From ba8da0647e4fe3eddcbe8f130c4bd7ab267eba75 Mon Sep 17 00:00:00 2001 From: TheMode Date: Thu, 16 Sep 2021 18:57:13 +0200 Subject: [PATCH] Properly call click events for shift & double clicks Signed-off-by: TheMode --- .../inventory/InventoryClickHandler.java | 6 ++--- .../click/InventoryClickProcessor.java | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/minestom/server/inventory/InventoryClickHandler.java b/src/main/java/net/minestom/server/inventory/InventoryClickHandler.java index d851a00f6..469e0413d 100644 --- a/src/main/java/net/minestom/server/inventory/InventoryClickHandler.java +++ b/src/main/java/net/minestom/server/inventory/InventoryClickHandler.java @@ -5,6 +5,7 @@ import net.minestom.server.event.EventDispatcher; import net.minestom.server.event.inventory.InventoryClickEvent; import net.minestom.server.inventory.click.ClickType; import net.minestom.server.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; /** @@ -13,6 +14,7 @@ import org.jetbrains.annotations.NotNull; *

* See https://wiki.vg/Protocol#Click_Window for more information. */ +@ApiStatus.NonExtendable public interface InventoryClickHandler { /** @@ -78,8 +80,6 @@ public interface InventoryClickHandler { default void callClickEvent(@NotNull Player player, Inventory inventory, int slot, @NotNull ClickType clickType, @NotNull ItemStack clicked, @NotNull ItemStack cursor) { - InventoryClickEvent inventoryClickEvent = new InventoryClickEvent(inventory, player, slot, clickType, clicked, cursor); - EventDispatcher.call(inventoryClickEvent); + EventDispatcher.call(new InventoryClickEvent(inventory, player, slot, clickType, clicked, cursor)); } - } 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 c5f67af93..de93c33ce 100644 --- a/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java +++ b/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java @@ -5,7 +5,10 @@ import net.minestom.server.entity.Player; import net.minestom.server.event.EventDispatcher; import net.minestom.server.event.inventory.InventoryClickEvent; import net.minestom.server.event.inventory.InventoryPreClickEvent; -import net.minestom.server.inventory.*; +import net.minestom.server.inventory.AbstractInventory; +import net.minestom.server.inventory.Inventory; +import net.minestom.server.inventory.PlayerInventory; +import net.minestom.server.inventory.TransactionType; import net.minestom.server.inventory.condition.InventoryCondition; import net.minestom.server.inventory.condition.InventoryConditionResult; import net.minestom.server.item.ItemStack; @@ -154,7 +157,12 @@ public final class InventoryClickProcessor { return true; }, start, end, step); - ItemStack itemResult = TransactionOption.ALL.fill(targetInventory, pair.left(), pair.right()); + final ItemStack itemResult = pair.left(); + final Map itemChangesMap = pair.right(); + itemChangesMap.forEach((Integer s, ItemStack itemStack) -> { + targetInventory.setItemStack(s, itemStack); + callClickEvent(player, targetInventory, s, ClickType.SHIFT_CLICK, itemStack, cursor); + }); clickResult.setClicked(itemResult); return clickResult; } @@ -306,9 +314,13 @@ public final class InventoryClickProcessor { final InventoryClickResult result = startCondition(player, inv, index, ClickType.DOUBLE_CLICK, itemStack, cursor); return !result.isCancel(); }); - var itemResult = pair.left(); - var map = pair.right(); - return TransactionOption.ALL.fill(inv, itemResult, map); + final ItemStack itemResult = pair.left(); + var itemChangesMap = pair.right(); + itemChangesMap.forEach((Integer s, ItemStack itemStack) -> { + inv.setItemStack(s, itemStack); + callClickEvent(player, inv, s, ClickType.DOUBLE_CLICK, itemStack, cursor); + }); + return itemResult; }; ItemStack remain = cursorRule.apply(cursor, remainingAmount);