From 9e6402c279850e67cec31a66b53c59516d8b62c7 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Wed, 24 Feb 2021 20:14:01 -0900 Subject: [PATCH] Fixes --- .../connector/inventory/Inventory.java | 4 ++ .../network/session/GeyserSession.java | 2 + .../BedrockContainerCloseTranslator.java | 25 ++++++----- .../BedrockLecternUpdateTranslator.java | 2 +- .../LecternInventoryTranslator.java | 4 +- .../chest/DoubleChestInventoryTranslator.java | 6 +++ .../java/JavaRespawnTranslator.java | 1 + .../window/JavaCloseWindowTranslator.java | 2 +- .../java/window/JavaOpenWindowTranslator.java | 4 +- .../connector/utils/InventoryUtils.java | 42 ++++++++++++------- 10 files changed, 59 insertions(+), 33 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java index 535a9077a..179801825 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java @@ -61,6 +61,10 @@ public class Inventory { @Getter protected short transactionId = 0; + @Getter + @Setter + private boolean pending = false; + protected Inventory(int id, int size) { this("Inventory", id, size); } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 41269ebf1..f2fa98ba4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -136,6 +136,8 @@ public class GeyserSession implements CommandSender { private final PlayerInventory playerInventory; @Setter private Inventory openInventory; + @Setter + private boolean closingInventory; @Setter private InventoryTranslator inventoryTranslator = InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockContainerCloseTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockContainerCloseTranslator.java index 6f0f877c8..d46a51ef1 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockContainerCloseTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockContainerCloseTranslator.java @@ -31,6 +31,7 @@ import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.Translator; +import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import org.geysermc.connector.utils.InventoryUtils; @Translator(packet = ContainerClosePacket.class) @@ -42,19 +43,21 @@ public class BedrockContainerCloseTranslator extends PacketTranslator session.addInventoryTask(() -> { session.setInventoryTranslator(InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR); session.setOpenInventory(null); + session.setClosingInventory(false); }); SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaCloseWindowTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaCloseWindowTranslator.java index b78dc32f2..639996203 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaCloseWindowTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaCloseWindowTranslator.java @@ -36,6 +36,6 @@ public class JavaCloseWindowTranslator extends PacketTranslator InventoryUtils.closeInventory(session, packet.getWindowId())); + session.addInventoryTask(() -> InventoryUtils.closeInventory(session, packet.getWindowId(), true)); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java index 2d1f77317..db20dfcd2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaOpenWindowTranslator.java @@ -51,7 +51,7 @@ public class JavaOpenWindowTranslator extends PacketTranslator 0) { + if (translator instanceof DoubleChestInventoryTranslator && !((Container) inventory).isUsingRealBlock()) { GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> { - translator.openInventory(session, inventory); - translator.updateInventory(session, inventory); - }, delay, TimeUnit.MILLISECONDS); + session.addInventoryTask(() -> { + Inventory openInv = session.getOpenInventory(); + if (openInv != null && openInv.getId() == inventory.getId()) { + translator.openInventory(session, inventory); + translator.updateInventory(session, inventory); + } + }); + }, 200, TimeUnit.MILLISECONDS); } else { translator.openInventory(session, inventory); translator.updateInventory(session, inventory); @@ -78,7 +86,7 @@ public class InventoryUtils { } } - public static void closeInventory(GeyserSession session, int windowId) { + public static void closeInventory(GeyserSession session, int windowId, boolean confirm) { session.getPlayerInventory().setCursor(GeyserItemStack.EMPTY, session); updateCursor(session); @@ -86,7 +94,9 @@ public class InventoryUtils { if (inventory != null) { InventoryTranslator translator = session.getInventoryTranslator(); translator.closeInventory(session, inventory); - session.setLastWindowCloseTime(System.currentTimeMillis()); + if (confirm && !inventory.isPending() && !(translator instanceof LecternInventoryTranslator)) { + session.setClosingInventory(true); + } } session.setInventoryTranslator(InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR); session.setOpenInventory(null);