Add minimum delay between closing and opening a new window (#735)

Should fix new windows not showing up with some plugins like Lottery.
This commit is contained in:
AJ Ferguson 2020-06-04 10:49:32 -08:00 committed by GitHub
parent 69a4cd3860
commit 1d8995efe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 11 deletions

View File

@ -53,8 +53,6 @@ public class BedrockContainerCloseTranslator extends PacketTranslator<ContainerC
ClientCloseWindowPacket closeWindowPacket = new ClientCloseWindowPacket(windowId);
session.getDownstream().getSession().send(closeWindowPacket);
InventoryUtils.closeInventory(session, windowId);
} else if (openInventory != null && openInventory.getId() != windowId) {
InventoryUtils.openInventory(session, openInventory);
}
}
}

View File

@ -50,10 +50,8 @@ public class JavaOpenWindowTranslator extends PacketTranslator<ServerOpenWindowP
Inventory openInventory = session.getInventoryCache().getOpenInventory();
if (newTranslator == null) {
if (openInventory != null) {
ContainerClosePacket closePacket = new ContainerClosePacket();
closePacket.setWindowId((byte)openInventory.getId());
session.sendUpstreamPacket(closePacket);
InventoryTranslator.INVENTORY_TRANSLATORS.get(openInventory.getWindowType()).closeInventory(session, openInventory);
InventoryUtils.closeWindow(session, openInventory.getId());
InventoryUtils.closeInventory(session, openInventory.getId());
}
ClientCloseWindowPacket closeWindowPacket = new ClientCloseWindowPacket(packet.getWindowId());
session.sendDownstreamPacket(closeWindowPacket);
@ -80,10 +78,6 @@ public class JavaOpenWindowTranslator extends PacketTranslator<ServerOpenWindowP
if (!openTranslator.getClass().equals(newTranslator.getClass())) {
InventoryUtils.closeWindow(session, openInventory.getId());
InventoryUtils.closeInventory(session, openInventory.getId());
session.getInventoryCache().setOpenInventory(newInventory);
//The new window will be opened when the bedrock client sends the
//window close confirmation in BedrockContainerCloseTranslator
return;
}
}

View File

@ -54,12 +54,18 @@ public class InventoryUtils {
if (translator != null) {
session.getInventoryCache().setOpenInventory(inventory);
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());
//TODO: find better way to handle double chest delay
if (translator instanceof DoubleChestInventoryTranslator) {
delay = Math.max(delay, 200);
}
if (delay > 0) {
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> {
translator.openInventory(session, inventory);
translator.updateInventory(session, inventory);
}, 200, TimeUnit.MILLISECONDS);
}, delay, TimeUnit.MILLISECONDS);
} else {
translator.openInventory(session, inventory);
translator.updateInventory(session, inventory);