1
0
mirror of https://e.coding.net/circlecloud/MenuProtect.git synced 2024-11-24 11:18:46 +00:00

fix: 修复异步命令错误

This commit is contained in:
502647092 2016-05-17 10:46:03 +08:00
parent 3129f63f90
commit c14411a87a
3 changed files with 18 additions and 17 deletions

View File

@ -26,7 +26,7 @@ public class MenuProtect extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
Bukkit.getPluginManager().registerEvents(new ProtectListener(this), this); Bukkit.getPluginManager().registerEvents(new ProtectListener(), this);
this.getLogger().info("菜单物品保护已开启!"); this.getLogger().info("菜单物品保护已开启!");
} }

View File

@ -1,6 +1,5 @@
package pw.yumc.MenuProtect.listen; package pw.yumc.MenuProtect.listen;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -12,17 +11,11 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import pw.yumc.MenuProtect.MenuProtect; import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.MenuProtect.utils.MarkUtil; import pw.yumc.MenuProtect.utils.MarkUtil;
public class ProtectListener implements Listener { public class ProtectListener implements Listener {
private final MenuProtect plugin;
public ProtectListener(final MenuProtect plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onInvClick(final InventoryClickEvent e) { public void onInvClick(final InventoryClickEvent e) {
if (e.getWhoClicked() instanceof Player) { if (e.getWhoClicked() instanceof Player) {
@ -56,7 +49,7 @@ public class ProtectListener implements Listener {
} }
private void handlerPlayerClick(final Player p, final ItemStack is) { private void handlerPlayerClick(final Player p, final ItemStack is) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { PluginKit.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
MarkUtil.handlerItemClick(p, is); MarkUtil.handlerItemClick(p, is);
@ -65,7 +58,7 @@ public class ProtectListener implements Listener {
} }
private void handlerPlayerInventory(final Player p) { private void handlerPlayerInventory(final Player p) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { PluginKit.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
final PlayerInventory inv = p.getInventory(); final PlayerInventory inv = p.getInventory();

View File

@ -10,6 +10,8 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import cn.citycraft.PluginHelper.kit.PluginKit;
public class MarkUtil { public class MarkUtil {
public static List<String> marks = null; public static List<String> marks = null;
public static Map<String, List<String>> cmds = new HashMap<>(); public static Map<String, List<String>> cmds = new HashMap<>();
@ -19,6 +21,9 @@ public class MarkUtil {
for (final String lore : is.getItemMeta().getLore()) { for (final String lore : is.getItemMeta().getLore()) {
if (cmds.containsKey(lore)) { if (cmds.containsKey(lore)) {
for (final String cmd : cmds.get(lore)) { for (final String cmd : cmds.get(lore)) {
PluginKit.runTask(new Runnable() {
@Override
public void run() {
CommandSender sender = Bukkit.getConsoleSender(); CommandSender sender = Bukkit.getConsoleSender();
if (cmd.startsWith("[p]")) { if (cmd.startsWith("[p]")) {
sender = p; sender = p;
@ -26,6 +31,8 @@ public class MarkUtil {
final String rcmd = cmd.replaceAll("%player%", p.getName()); final String rcmd = cmd.replaceAll("%player%", p.getName());
Bukkit.dispatchCommand(sender, rcmd.startsWith("[") ? rcmd.substring(3) : rcmd); Bukkit.dispatchCommand(sender, rcmd.startsWith("[") ? rcmd.substring(3) : rcmd);
} }
});
}
} }
} }
} }
@ -48,5 +55,6 @@ public class MarkUtil {
for (final String lore : cfg.getKeys(false)) { for (final String lore : cfg.getKeys(false)) {
cmds.put(lore, cfg.getStringList(lore)); cmds.put(lore, cfg.getStringList(lore));
} }
PluginKit.getLogger().info("初始化LoreCommand完毕 总计: " + cmds.size() + "条...");
} }
} }