From c14411a87a4b854a40ab0fb9b54de38db4fad665 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 17 May 2016 10:46:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pw/yumc/MenuProtect/MenuProtect.java | 2 +- .../MenuProtect/listen/ProtectListener.java | 13 +++--------- .../pw/yumc/MenuProtect/utils/MarkUtil.java | 20 +++++++++++++------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/pw/yumc/MenuProtect/MenuProtect.java b/src/main/java/pw/yumc/MenuProtect/MenuProtect.java index 02933ab..5224f8e 100644 --- a/src/main/java/pw/yumc/MenuProtect/MenuProtect.java +++ b/src/main/java/pw/yumc/MenuProtect/MenuProtect.java @@ -26,7 +26,7 @@ public class MenuProtect extends JavaPlugin { @Override public void onEnable() { - Bukkit.getPluginManager().registerEvents(new ProtectListener(this), this); + Bukkit.getPluginManager().registerEvents(new ProtectListener(), this); this.getLogger().info("菜单物品保护已开启!"); } diff --git a/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java b/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java index 6331830..a9a2e18 100644 --- a/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java +++ b/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java @@ -1,6 +1,5 @@ package pw.yumc.MenuProtect.listen; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -12,17 +11,11 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import pw.yumc.MenuProtect.MenuProtect; +import cn.citycraft.PluginHelper.kit.PluginKit; import pw.yumc.MenuProtect.utils.MarkUtil; public class ProtectListener implements Listener { - private final MenuProtect plugin; - - public ProtectListener(final MenuProtect plugin) { - this.plugin = plugin; - } - @EventHandler(priority = EventPriority.MONITOR) public void onInvClick(final InventoryClickEvent e) { if (e.getWhoClicked() instanceof Player) { @@ -56,7 +49,7 @@ public class ProtectListener implements Listener { } private void handlerPlayerClick(final Player p, final ItemStack is) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + PluginKit.runTaskAsync(new Runnable() { @Override public void run() { MarkUtil.handlerItemClick(p, is); @@ -65,7 +58,7 @@ public class ProtectListener implements Listener { } private void handlerPlayerInventory(final Player p) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + PluginKit.runTaskAsync(new Runnable() { @Override public void run() { final PlayerInventory inv = p.getInventory(); diff --git a/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java b/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java index 17c661f..6e06c41 100644 --- a/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java +++ b/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java @@ -10,6 +10,8 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import cn.citycraft.PluginHelper.kit.PluginKit; + public class MarkUtil { public static List marks = null; public static Map> cmds = new HashMap<>(); @@ -19,12 +21,17 @@ public class MarkUtil { for (final String lore : is.getItemMeta().getLore()) { if (cmds.containsKey(lore)) { for (final String cmd : cmds.get(lore)) { - CommandSender sender = Bukkit.getConsoleSender(); - if (cmd.startsWith("[p]")) { - sender = p; - } - final String rcmd = cmd.replaceAll("%player%", p.getName()); - Bukkit.dispatchCommand(sender, rcmd.startsWith("[") ? rcmd.substring(3) : rcmd); + PluginKit.runTask(new Runnable() { + @Override + public void run() { + CommandSender sender = Bukkit.getConsoleSender(); + if (cmd.startsWith("[p]")) { + sender = p; + } + final String rcmd = cmd.replaceAll("%player%", p.getName()); + Bukkit.dispatchCommand(sender, rcmd.startsWith("[") ? rcmd.substring(3) : rcmd); + } + }); } } } @@ -48,5 +55,6 @@ public class MarkUtil { for (final String lore : cfg.getKeys(false)) { cmds.put(lore, cfg.getStringList(lore)); } + PluginKit.getLogger().info("初始化LoreCommand完毕 总计: " + cmds.size() + "条..."); } }