Fix Player#didCloseInventory

This commit is contained in:
Felix Cravic 2020-07-01 17:25:25 +02:00
parent eb9aa8b6b6
commit ce06919da1
4 changed files with 6 additions and 5 deletions

View File

@ -227,7 +227,6 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
private WindowItemsPacket createWindowItemsPacket() { private WindowItemsPacket createWindowItemsPacket() {
WindowItemsPacket windowItemsPacket = new WindowItemsPacket(); WindowItemsPacket windowItemsPacket = new WindowItemsPacket();
windowItemsPacket.windowId = getWindowId(); windowItemsPacket.windowId = getWindowId();
windowItemsPacket.count = (short) itemStacks.length;
windowItemsPacket.items = itemStacks; windowItemsPacket.items = itemStacks;
return windowItemsPacket; return windowItemsPacket;
} }

View File

@ -334,7 +334,6 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
WindowItemsPacket windowItemsPacket = new WindowItemsPacket(); WindowItemsPacket windowItemsPacket = new WindowItemsPacket();
windowItemsPacket.windowId = 0; windowItemsPacket.windowId = 0;
windowItemsPacket.count = INVENTORY_SIZE;
windowItemsPacket.items = convertedSlots; windowItemsPacket.items = convertedSlots;
return windowItemsPacket; return windowItemsPacket;
} }

View File

@ -502,6 +502,10 @@ public class InventoryClickProcessor {
slot = slot - inventorySlot + PlayerInventoryUtils.OFFSET; slot = slot - inventorySlot + PlayerInventoryUtils.OFFSET;
} }
// Reset the didCloseInventory field
// Wait for inventory conditions + events to possibly close the inventory
player.UNSAFE_changeDidCloseInventory(false);
List<InventoryCondition> inventoryConditions = isPlayerInventory ? List<InventoryCondition> inventoryConditions = isPlayerInventory ?
player.getInventory().getInventoryConditions() : inventory.getInventoryConditions(); player.getInventory().getInventoryConditions() : inventory.getInventoryConditions();
if (!inventoryConditions.isEmpty()) { if (!inventoryConditions.isEmpty()) {

View File

@ -7,13 +7,12 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier;
public class WindowItemsPacket implements ServerPacket { public class WindowItemsPacket implements ServerPacket {
public int windowId; public byte windowId;
public short count;
public ItemStack[] items; public ItemStack[] items;
@Override @Override
public void write(PacketWriter writer) { public void write(PacketWriter writer) {
writer.writeVarInt(windowId); writer.writeByte(windowId);
if (items == null) { if (items == null) {
writer.writeShort((short) 0); writer.writeShort((short) 0);