diff --git a/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java b/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java index 165451c..0b710c7 100644 --- a/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java +++ b/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java @@ -33,7 +33,7 @@ public class ProtectListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onInvMove(final InventoryMoveItemEvent e) { final ItemStack ci = e.getItem(); - if (MarkUtil.hasMark(ci)) { + if (MarkUtil.clearMark(ci) != null) { e.setCancelled(true); } } @@ -41,7 +41,7 @@ public class ProtectListener implements Listener { private ItemStack[] handlerItems(final ItemStack[] cis) { for (int i = 0; i < cis.length; i++) { final ItemStack itemStack = cis[i]; - if (MarkUtil.hasMark(itemStack)) { + if (MarkUtil.clearMark(itemStack) != null) { cis[i] = new ItemStack(Material.AIR); } } diff --git a/src/main/java/pw/yumc/MenuProtect/listen/WowSuchCleanerListener.java b/src/main/java/pw/yumc/MenuProtect/listen/WowSuchCleanerListener.java index 203b360..b44cab2 100644 --- a/src/main/java/pw/yumc/MenuProtect/listen/WowSuchCleanerListener.java +++ b/src/main/java/pw/yumc/MenuProtect/listen/WowSuchCleanerListener.java @@ -20,7 +20,7 @@ public class WowSuchCleanerListener implements Listener { final List list = e.getItemsToAuction(); final List needRemove = e.getItemsToAuction(); for (final ItemStack itemStack : list) { - if (MarkUtil.hasMark(itemStack)) { + if (MarkUtil.clearMark(itemStack) != null) { needRemove.add(itemStack); } } diff --git a/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java b/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java index c9be611..c5ceb9a 100644 --- a/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java +++ b/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java @@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import pw.yumc.YumCore.bukkit.Log; import pw.yumc.YumCore.kit.PKit; @@ -18,35 +19,45 @@ public class MarkUtil { public static Map> cmds = new HashMap<>(); public static void handlerItemClick(final Player p, final ItemStack is) { - if (hasMark(is) && is.getItemMeta().hasLore()) { - for (final String lore : is.getItemMeta().getLore()) { - if (cmds.containsKey(lore) || (is.getItemMeta().hasDisplayName() && cmds.containsKey(is.getItemMeta().getDisplayName()))) { - for (final String cmd : cmds.get(lore)) { - PKit.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); - } - }); + String leftName = clearMark(is); + if (leftName != null) { + String key = null; + ItemMeta im = is.getItemMeta(); + if (cmds.containsKey(leftName)) { + key = leftName; + } else if (im.hasLore()) { + for (final String lore : is.getItemMeta().getLore()) { + if (cmds.containsKey(lore)) { + key = lore; } } } + if (key != null) { + for (final String cmd : cmds.get(key)) { + PKit.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); + } + }); + } + } } } - public static boolean hasMark(final ItemStack ci) { + public static String clearMark(final ItemStack ci) { try { for (final String mark : marks) { - if (ci.getItemMeta().getDisplayName().startsWith(mark)) { return true; } + if (ci.getItemMeta().getDisplayName().startsWith(mark)) { return ci.getItemMeta().getDisplayName().split(mark)[1]; } } } catch (final Exception ignored) { } - return false; + return null; } public static void initCommand(final ConfigurationSection cfg) {