From 8ae803b9a5ea4d5b6a4dc2141db6b34af7989442 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Sun, 20 Oct 2019 13:52:21 -0800 Subject: [PATCH] Add delay when reopening inventory --- .../java/window/JavaSetSlotTranslator.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java index d67ad0279..0392a52c7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java @@ -30,6 +30,7 @@ import com.nukkitx.protocol.bedrock.data.ContainerId; import com.nukkitx.protocol.bedrock.data.ItemData; import com.nukkitx.protocol.bedrock.packet.ContainerClosePacket; import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; +import org.geysermc.api.Geyser; import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -37,6 +38,7 @@ import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import java.util.Objects; +import java.util.concurrent.TimeUnit; public class JavaSetSlotTranslator extends PacketTranslator { @@ -53,15 +55,17 @@ public class JavaSetSlotTranslator extends PacketTranslator cursorPacket.setSlot(ItemData.AIR); session.getUpstream().sendPacket(cursorPacket); - Inventory inventory = session.getInventoryCache().getOpenInventory(); - if (inventory != null) { - session.setReopeningWindow(inventory.getId()); - } else { - inventory = session.getInventory(); - } - ContainerClosePacket closePacket = new ContainerClosePacket(); - closePacket.setWindowId((byte)inventory.getId()); - session.getUpstream().sendPacket(closePacket); + Geyser.getGeneralThreadPool().schedule(() -> { + Inventory inventory = session.getInventoryCache().getOpenInventory(); + if (inventory != null) { + session.setReopeningWindow(inventory.getId()); + } else { + inventory = session.getInventory(); + } + ContainerClosePacket closePacket = new ContainerClosePacket(); + closePacket.setWindowId((byte) inventory.getId()); + session.getUpstream().sendPacket(closePacket); + }, 150, TimeUnit.MILLISECONDS); } session.getInventory().setCursor(packet.getItem());