From b299df2d21ace1c7e88b1ee8fafb297e2a9347e8 Mon Sep 17 00:00:00 2001 From: kernitus <2789734+kernitus@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:21:57 +0000 Subject: [PATCH] fix: don't prevent moving shield to chests in disable offhand module --- .../module/ModuleDisableOffHand.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleDisableOffHand.java b/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleDisableOffHand.java index e096fccf..6261eed6 100644 --- a/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleDisableOffHand.java +++ b/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleDisableOffHand.java @@ -22,6 +22,7 @@ import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -52,7 +53,7 @@ public void reload() { } private void sendDeniedMessage(CommandSender sender) { - if (deniedMessage.trim().length() > 0) + if (!deniedMessage.trim().isEmpty()) Messenger.send(sender, deniedMessage); } @@ -83,8 +84,14 @@ public void onInventoryClick(InventoryClickEvent e) { final Inventory clickedInventory = e.getClickedInventory(); if (clickedInventory == null) return; final InventoryType inventoryType = clickedInventory.getType(); - // If they're in their own inventory, and not chests etc. - if (inventoryType != InventoryType.PLAYER) return; + // Source inventory must be PLAYER + if(inventoryType != InventoryType.PLAYER) return; + + final InventoryView view = e.getView(); + // If neither of the inventories is CRAFTING, player cannot be moving stuff to the offhand + if (view.getBottomInventory().getType() != InventoryType.CRAFTING && + view.getTopInventory().getType() != InventoryType.CRAFTING) + return; // Prevent shift-clicking a shield into the offhand item slot final ItemStack currentItem = e.getCurrentItem();