From 5cf358ac3ca238625a22c9cfc1dde5bd8ff5013d Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 18 Aug 2021 21:08:04 +0200 Subject: [PATCH] Fix inventory events not giving the proper inventory/slot --- .../minestom/server/inventory/Inventory.java | 18 +++++++++++------- .../packet/client/ClientPlayPacket.java | 2 -- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minestom/server/inventory/Inventory.java b/src/main/java/net/minestom/server/inventory/Inventory.java index 97e2a16c1..60b7a4bfe 100644 --- a/src/main/java/net/minestom/server/inventory/Inventory.java +++ b/src/main/java/net/minestom/server/inventory/Inventory.java @@ -267,7 +267,8 @@ public class Inventory extends AbstractInventory implements Viewable { final boolean isInWindow = isClickInWindow(slot); final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset); final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot); - final InventoryClickResult clickResult = clickProcessor.leftClick(player, this, slot, clicked, cursor); + final InventoryClickResult clickResult = clickProcessor.leftClick(player, + isInWindow ? this : playerInventory, clickSlot, clicked, cursor); if (clickResult.isCancel()) { updateAll(player); return false; @@ -289,7 +290,8 @@ public class Inventory extends AbstractInventory implements Viewable { final boolean isInWindow = isClickInWindow(slot); final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset); final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot); - final InventoryClickResult clickResult = clickProcessor.rightClick(player, this, slot, clicked, cursor); + final InventoryClickResult clickResult = clickProcessor.rightClick(player, + isInWindow ? this : playerInventory, clickSlot, clicked, cursor); if (clickResult.isCancel()) { updateAll(player); return false; @@ -337,7 +339,8 @@ public class Inventory extends AbstractInventory implements Viewable { final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset); final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot); final ItemStack heldItem = playerInventory.getItemStack(key); - final InventoryClickResult clickResult = clickProcessor.changeHeld(player, this, slot, key, clicked, heldItem); + final InventoryClickResult clickResult = clickProcessor.changeHeld(player, + isInWindow ? this : playerInventory, clickSlot, key, clicked, heldItem); if (clickResult.isCancel()) { updateAll(player); return false; @@ -368,8 +371,8 @@ public class Inventory extends AbstractInventory implements Viewable { final ItemStack clicked = outsideDrop ? ItemStack.AIR : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot)); final ItemStack cursor = getCursorItem(player); - final InventoryClickResult clickResult = clickProcessor.drop(player, this, - all, slot, button, clicked, cursor); + final InventoryClickResult clickResult = clickProcessor.drop(player, + isInWindow ? this : playerInventory, all, clickSlot, button, clicked, cursor); if (clickResult.isCancel()) { updateAll(player); return false; @@ -395,8 +398,9 @@ public class Inventory extends AbstractInventory implements Viewable { (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot)) : ItemStack.AIR; final ItemStack cursor = getCursorItem(player); - final InventoryClickResult clickResult = clickProcessor.dragging(player, this, - slot, button, + final InventoryClickResult clickResult = clickProcessor.dragging(player, + isInWindow ? this : playerInventory, + clickSlot, button, clicked, cursor, s -> isClickInWindow(s) ? getItemStack(s) : diff --git a/src/main/java/net/minestom/server/network/packet/client/ClientPlayPacket.java b/src/main/java/net/minestom/server/network/packet/client/ClientPlayPacket.java index 75d045ac0..9dcdd20af 100644 --- a/src/main/java/net/minestom/server/network/packet/client/ClientPlayPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/ClientPlayPacket.java @@ -6,7 +6,6 @@ import net.minestom.server.listener.manager.PacketListenerManager; import org.jetbrains.annotations.NotNull; public abstract class ClientPlayPacket implements ClientPacket { - private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager(); /** @@ -19,5 +18,4 @@ public abstract class ClientPlayPacket implements ClientPacket { public void process(@NotNull Player player) { PACKET_LISTENER_MANAGER.processClientPacket(this, player); } - }