diff --git a/src/main/java/cn/citycraft/MenuProtect/listen/ProtectListener.java b/src/main/java/cn/citycraft/MenuProtect/listen/ProtectListener.java index acf5fc6..e3b8a2a 100644 --- a/src/main/java/cn/citycraft/MenuProtect/listen/ProtectListener.java +++ b/src/main/java/cn/citycraft/MenuProtect/listen/ProtectListener.java @@ -4,10 +4,16 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.AnvilInventory; +import org.bukkit.inventory.CraftingInventory; +import org.bukkit.inventory.DoubleChestInventory; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -30,22 +36,23 @@ public class ProtectListener implements Listener { } } - /* - * @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - * public void onItemClick(final InventoryClickEvent e) { - * final Player p = (Player) e.getWhoClicked(); - * final ItemStack ci = e.getCurrentItem(); - * final Inventory inv = e.getInventory(); - * final int solt = e.getSlot(); - * try { - * if (MarkUtil.hasMark(ci)) { - * inv.setItem(solt, new ItemStack(Material.AIR)); - * p.closeInventory(); - * } - * } catch (final Exception ex) { - * } - * } - */ + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onItemClick(final InventoryClickEvent e) { + final Player p = (Player) e.getWhoClicked(); + final ItemStack ci = e.getCurrentItem(); + final Inventory inv = e.getInventory(); + if (inv.getHolder() == null || !(inv instanceof PlayerInventory || inv instanceof CraftingInventory || inv instanceof AnvilInventory || inv instanceof DoubleChestInventory)) { + return; + } + final int solt = e.getSlot(); + try { + if (MarkUtil.hasMark(ci)) { + inv.setItem(solt, new ItemStack(Material.AIR)); + p.closeInventory(); + } + } catch (final Exception ex) { + } + } @EventHandler public void onPlayerHandlerItem(final PlayerItemHeldEvent e) {