3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 00:00:41 +01:00

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

Should fix new windows not showing up with some plugins like Lottery.
Dieser Commit ist enthalten in:
AJ Ferguson 2020-06-04 10:49:32 -08:00 committet von GitHub
Ursprung 69a4cd3860
Commit 1d8995efe6
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 9 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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);