From fe53481afd0895c632897f522a2eba738dccf6e3 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Sun, 25 Apr 2021 00:12:17 +0200 Subject: [PATCH] Fix duplicate sorting trigger --- src/dev/w1zzrd/invtweaks/listener/SortListener.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dev/w1zzrd/invtweaks/listener/SortListener.java b/src/dev/w1zzrd/invtweaks/listener/SortListener.java index 6e1a21f..3a8c81a 100644 --- a/src/dev/w1zzrd/invtweaks/listener/SortListener.java +++ b/src/dev/w1zzrd/invtweaks/listener/SortListener.java @@ -6,6 +6,7 @@ import org.bukkit.block.ShulkerBox; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.PlayerInventory; import java.util.Objects; @@ -27,12 +28,14 @@ public class SortListener implements Listener { * 2. Player must be attempting to interact with a Chest or Shulker Box * 3. Player must be sneaking * 4. Player must be holding a sword in their main hand + * 5. Event is not triggered for players off-hand */ if (event.hasBlock() && (Objects.requireNonNull(event.getClickedBlock()).getState() instanceof Chest || event.getClickedBlock().getState() instanceof ShulkerBox) && event.getPlayer().isSneaking() && - playerInventory.getItemInMainHand().getType().name().endsWith("_SWORD") + playerInventory.getItemInMainHand().getType().name().endsWith("_SWORD") && + event.getHand() != EquipmentSlot.OFF_HAND ) { logger.fine(LOG_PLUGIN_NAME + " Triggering /sort for player " + event.getPlayer().getName()); event.getPlayer().performCommand("sort");