From 9e6402c279850e67cec31a66b53c59516d8b62c7 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Wed, 24 Feb 2021 20:14:01 -0900 Subject: [PATCH 1/2] 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); From 07f36affb91a2f507e06b8dd2eb3202bf76c469e Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Thu, 25 Feb 2021 01:41:04 -0900 Subject: [PATCH 2/2] Add barrel as a valid single chest block --- .../translators/chest/SingleChestInventoryTranslator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/chest/SingleChestInventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/chest/SingleChestInventoryTranslator.java index 42b23d5b4..0f3b8ecb9 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/chest/SingleChestInventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/translators/chest/SingleChestInventoryTranslator.java @@ -37,10 +37,10 @@ public class SingleChestInventoryTranslator extends ChestInventoryTranslator { public SingleChestInventoryTranslator(int size) { super(size, 27); this.holder = new BlockInventoryHolder("minecraft:chest[facing=north,type=single,waterlogged=false]", ContainerType.CONTAINER, - "minecraft:ender_chest", "minecraft:trapped_chest") { + "minecraft:ender_chest", "minecraft:trapped_chest", "minecraft:barrel") { @Override protected boolean isValidBlock(String[] javaBlockString) { - if (javaBlockString[0].equals("minecraft:ender_chest")) { + if (javaBlockString[0].equals("minecraft:ender_chest") || javaBlockString[0].equals("minecraft:barrel")) { // Can't have double ender chests return true; }