From b662e331f006649e729d63a20dcf38a280ab75a8 Mon Sep 17 00:00:00 2001 From: TheMode Date: Sat, 24 Apr 2021 19:08:02 +0200 Subject: [PATCH] Fix shift clicks not being cancelled --- .../inventory/click/InventoryClickProcessor.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java b/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java index 80ce319e2..f5c835010 100644 --- a/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java +++ b/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java @@ -186,7 +186,7 @@ public class InventoryClickProcessor { return null; var pair = TransactionType.ADD.process(targetInventory, clicked, (index, itemStack) -> { - InventoryClickResult result = startCondition(inventory, player, index, ClickType.SHIFT_CLICK, itemStack, cursor); + InventoryClickResult result = startCondition(targetInventory, player, index, ClickType.SHIFT_CLICK, itemStack, cursor); return !result.isCancel(); }); @@ -209,7 +209,7 @@ public class InventoryClickProcessor { var pair = TransactionType.ADD.process(targetInventory, clicked, (index, itemStack) -> { if (index == slot) // Prevent item lose/duplication return false; - InventoryClickResult result = startCondition(null, player, index, ClickType.SHIFT_CLICK, itemStack, cursor); + InventoryClickResult result = startCondition(targetInventory, player, index, ClickType.SHIFT_CLICK, itemStack, cursor); return !result.isCancel(); }, start, end, step); @@ -547,6 +547,13 @@ public class InventoryClickProcessor { return startCondition(clickResult, inventory, player, slot, clickType); } + @NotNull + private InventoryClickResult startCondition(@Nullable AbstractInventory inventory, @NotNull Player player, int slot, + @NotNull ClickType clickType, @NotNull ItemStack clicked, @NotNull ItemStack cursor) { + return startCondition(inventory instanceof Inventory ? (Inventory) inventory : null, + player, slot, clickType, clicked, cursor); + } + private void callClickEvent(@NotNull Player player, @Nullable Inventory inventory, int slot, @NotNull ClickType clickType, @NotNull ItemStack clicked, @NotNull ItemStack cursor) { InventoryClickEvent inventoryClickEvent = new InventoryClickEvent(inventory, player, slot, clickType, clicked, cursor);