From b9846fe797098ff871c631498b48ca520bf0cd4d Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Mon, 27 Jul 2020 07:17:55 -0800 Subject: [PATCH] Small inventory fixes (#1029) * Increase minimum delay between closing and opening a new window * Fix potential crash when opening player inventory --- .../bedrock/BedrockInteractTranslator.java | 15 +++++++++------ .../geysermc/connector/utils/InventoryUtils.java | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java index 7d03f9832..856b01eec 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInteractTranslator.java @@ -135,12 +135,15 @@ public class BedrockInteractTranslator extends PacketTranslator } break; case OPEN_INVENTORY: - ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket(); - containerOpenPacket.setId((byte) 0); - containerOpenPacket.setType(ContainerType.INVENTORY); - containerOpenPacket.setUniqueEntityId(-1); - containerOpenPacket.setBlockPosition(entity.getPosition().toInt()); - session.sendUpstreamPacket(containerOpenPacket); + if (!session.getInventory().isOpen()) { + ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket(); + containerOpenPacket.setId((byte) 0); + containerOpenPacket.setType(ContainerType.INVENTORY); + containerOpenPacket.setUniqueEntityId(-1); + containerOpenPacket.setBlockPosition(entity.getPosition().toInt()); + session.sendUpstreamPacket(containerOpenPacket); + session.getInventory().setOpen(true); + } break; } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java index c30f4518a..6d83da0ad 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/InventoryUtils.java @@ -56,7 +56,7 @@ public class InventoryUtils { translator.prepareInventory(session, inventory); //Ensure at least half a second passes between closing and opening a new window //The client will not open the new window if it is still closing the old one - long delay = 500 - (System.currentTimeMillis() - session.getLastWindowCloseTime()); + long delay = 700 - (System.currentTimeMillis() - session.getLastWindowCloseTime()); //TODO: find better way to handle double chest delay if (translator instanceof DoubleChestInventoryTranslator) { delay = Math.max(delay, 200); @@ -87,6 +87,7 @@ public class InventoryUtils { } } else { Inventory inventory = session.getInventory(); + inventory.setOpen(false); InventoryTranslator translator = InventoryTranslator.INVENTORY_TRANSLATORS.get(inventory.getWindowType()); translator.updateInventory(session, inventory); }