diff --git a/core/src/main/java/com/nisovin/magicspells/spells/MenuSpell.java b/core/src/main/java/com/nisovin/magicspells/spells/MenuSpell.java index 8797a36a9..289aa7c1c 100644 --- a/core/src/main/java/com/nisovin/magicspells/spells/MenuSpell.java +++ b/core/src/main/java/com/nisovin/magicspells/spells/MenuSpell.java @@ -310,9 +310,13 @@ private ItemStack translateItem(Player opener, ItemStack item, SpellData data) { @EventHandler public void onInvClick(InventoryClickEvent event) { - Inventory inventory = event.getClickedInventory(); - if (inventory == null || !(inventory.getHolder() instanceof MenuInventory menu) || menu.getSpell() != this) return; + InventoryView view = event.getView(); + + Inventory inventory = view.getTopInventory(); + if (!(inventory.getHolder() instanceof MenuInventory menu) || menu.getSpell() != this) return; + event.setCancelled(true); + if (event.getClickedInventory() != inventory) return; Player player = (Player) event.getWhoClicked(); PostClickState state = castSpells(menu, event.getCurrentItem(), event.getClick()); @@ -336,13 +340,7 @@ public void onInvDrag(InventoryDragEvent event) { Inventory inventory = view.getTopInventory(); if (!(inventory.getHolder() instanceof MenuInventory menu) || menu.getSpell() != this) return; - int size = inventory.getSize(); - for (int slot : event.getRawSlots()) { - if (slot < size) { - event.setCancelled(true); - return; - } - } + event.setCancelled(true); } private PostClickState castSpells(MenuInventory menu, ItemStack item, ClickType click) { diff --git a/core/src/main/java/com/nisovin/magicspells/spells/PlayerMenuSpell.java b/core/src/main/java/com/nisovin/magicspells/spells/PlayerMenuSpell.java index 77fb2d0d8..6b6b512c4 100644 --- a/core/src/main/java/com/nisovin/magicspells/spells/PlayerMenuSpell.java +++ b/core/src/main/java/com/nisovin/magicspells/spells/PlayerMenuSpell.java @@ -246,11 +246,13 @@ private void open(Player opener, PlayerMenuInventory menu) { @EventHandler public void onItemClick(InventoryClickEvent event) { - Inventory inventory = event.getClickedInventory(); - if (inventory == null || !(inventory.getHolder() instanceof PlayerMenuInventory menu) || menu.getSpell() != this) return; + InventoryView view = event.getView(); + + Inventory inventory = view.getTopInventory(); + if (!(inventory.getHolder() instanceof PlayerMenuInventory menu) || menu.getSpell() != this) return; event.setCancelled(true); - if (!(event.getWhoClicked() instanceof Player opener)) return; + if (event.getClickedInventory() != inventory || !(event.getWhoClicked() instanceof Player opener)) return; ItemStack item = event.getCurrentItem(); if (item == null) return; @@ -334,13 +336,7 @@ public void onInvDrag(InventoryDragEvent event) { Inventory inventory = view.getTopInventory(); if (!(inventory.getHolder() instanceof PlayerMenuInventory menu) || menu.getSpell() != this) return; - int size = inventory.getSize(); - for (int slot : event.getRawSlots()) { - if (slot < size) { - event.setCancelled(true); - return; - } - } + event.setCancelled(true); } private class PlayerMenuInventory implements InventoryHolder {