From ce06919da1272675393a4e399fb838b9069d1930 Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Wed, 1 Jul 2020 17:25:25 +0200 Subject: [PATCH] Fix Player#didCloseInventory --- src/main/java/net/minestom/server/inventory/Inventory.java | 1 - .../java/net/minestom/server/inventory/PlayerInventory.java | 1 - .../server/inventory/click/InventoryClickProcessor.java | 4 ++++ .../server/network/packet/server/play/WindowItemsPacket.java | 5 ++--- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minestom/server/inventory/Inventory.java b/src/main/java/net/minestom/server/inventory/Inventory.java index 2c7df4a8b..706c1f7ff 100644 --- a/src/main/java/net/minestom/server/inventory/Inventory.java +++ b/src/main/java/net/minestom/server/inventory/Inventory.java @@ -227,7 +227,6 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View private WindowItemsPacket createWindowItemsPacket() { WindowItemsPacket windowItemsPacket = new WindowItemsPacket(); windowItemsPacket.windowId = getWindowId(); - windowItemsPacket.count = (short) itemStacks.length; windowItemsPacket.items = itemStacks; return windowItemsPacket; } diff --git a/src/main/java/net/minestom/server/inventory/PlayerInventory.java b/src/main/java/net/minestom/server/inventory/PlayerInventory.java index 66c7f246f..6e9f5f260 100644 --- a/src/main/java/net/minestom/server/inventory/PlayerInventory.java +++ b/src/main/java/net/minestom/server/inventory/PlayerInventory.java @@ -334,7 +334,6 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler WindowItemsPacket windowItemsPacket = new WindowItemsPacket(); windowItemsPacket.windowId = 0; - windowItemsPacket.count = INVENTORY_SIZE; windowItemsPacket.items = convertedSlots; return windowItemsPacket; } 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 004a79b3c..4e71572c1 100644 --- a/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java +++ b/src/main/java/net/minestom/server/inventory/click/InventoryClickProcessor.java @@ -502,6 +502,10 @@ public class InventoryClickProcessor { slot = slot - inventorySlot + PlayerInventoryUtils.OFFSET; } + // Reset the didCloseInventory field + // Wait for inventory conditions + events to possibly close the inventory + player.UNSAFE_changeDidCloseInventory(false); + List inventoryConditions = isPlayerInventory ? player.getInventory().getInventoryConditions() : inventory.getInventoryConditions(); if (!inventoryConditions.isEmpty()) { diff --git a/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java index ccef22999..8b64632fe 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java @@ -7,13 +7,12 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier; public class WindowItemsPacket implements ServerPacket { - public int windowId; - public short count; + public byte windowId; public ItemStack[] items; @Override public void write(PacketWriter writer) { - writer.writeVarInt(windowId); + writer.writeByte(windowId); if (items == null) { writer.writeShort((short) 0);