mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
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:
parent
69a4cd3860
commit
1d8995efe6
3 changed files with 9 additions and 11 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue