Don't send inventories to the client before initialization

Fixes #2677
This commit is contained in:
Camotoy 2021-12-07 14:51:58 -05:00
parent 2953ea9513
commit b0baf1670d
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 11 additions and 4 deletions

View file

@ -30,6 +30,7 @@ import org.geysermc.geyser.session.auth.AuthType;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.util.InventoryUtils;
import org.geysermc.geyser.util.LoginEncryptionUtils; import org.geysermc.geyser.util.LoginEncryptionUtils;
@Translator(packet = SetLocalPlayerAsInitializedPacket.class) @Translator(packet = SetLocalPlayerAsInitializedPacket.class)
@ -47,8 +48,13 @@ public class BedrockSetLocalPlayerAsInitializedTranslator extends PacketTranslat
// else we were able to log the user in // else we were able to log the user in
} }
if (session.isLoggedIn()) { if (session.isLoggedIn()) {
// Sigh // Sigh - as of Bedrock 1.18
session.getEntityCache().updateBossBars(); session.getEntityCache().updateBossBars();
// Double sigh - https://github.com/GeyserMC/Geyser/issues/2677 - as of Bedrock 1.18
if (session.getOpenInventory() != null && session.getOpenInventory().isPending()) {
InventoryUtils.openInventory(session, session.getOpenInventory());
}
} }
} }
} }

View file

@ -66,9 +66,10 @@ public class InventoryUtils {
public static void openInventory(GeyserSession session, Inventory inventory) { public static void openInventory(GeyserSession session, Inventory inventory) {
session.setOpenInventory(inventory); session.setOpenInventory(inventory);
if (session.isClosingInventory()) { if (session.isClosingInventory() || !session.getUpstream().isInitialized()) {
// Wait for close confirmation from client before opening the new inventory. // Wait for close confirmation from client before opening the new inventory.
// Handled in BedrockContainerCloseTranslator // Handled in BedrockContainerCloseTranslator
// or - client hasn't yet loaded in; wait until inventory is shown
inventory.setPending(true); inventory.setPending(true);
return; return;
} }