3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-16 04:50:07 +01:00

Fix: Send a container close packet to Java for containers that could not be opened (#4861)

* Close containers if we did not manage to open it

* Mark session inventory translator as nonnull
Dieser Commit ist enthalten in:
chris 2024-07-14 20:17:22 +02:00 committet von GitHub
Ursprung 49f66c2a02
Commit 9cdda707a3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
3 geänderte Dateien mit 8 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -222,7 +222,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
private boolean closingInventory; private boolean closingInventory;
@Setter @Setter
private InventoryTranslator inventoryTranslator = InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR; private @NonNull InventoryTranslator inventoryTranslator = InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR;
/** /**
* Use {@link #getNextItemNetId()} instead for consistency * Use {@link #getNextItemNetId()} instead for consistency

Datei anzeigen

@ -70,6 +70,7 @@ public class JavaOpenBookTranslator extends PacketTranslator<ClientboundOpenBook
} }
InventoryTranslator translator = InventoryTranslator.inventoryTranslator(ContainerType.LECTERN); InventoryTranslator translator = InventoryTranslator.inventoryTranslator(ContainerType.LECTERN);
Objects.requireNonNull(translator, "could not find lectern inventory translator!");
session.setInventoryTranslator(translator); session.setInventoryTranslator(translator);
// Should never be null // Should never be null

Datei anzeigen

@ -57,6 +57,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient; import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundPickItemPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundPickItemPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
@ -91,7 +92,7 @@ public class InventoryUtils {
public static void displayInventory(GeyserSession session, Inventory inventory) { public static void displayInventory(GeyserSession session, Inventory inventory) {
InventoryTranslator translator = session.getInventoryTranslator(); InventoryTranslator translator = session.getInventoryTranslator();
if (translator != null && translator.prepareInventory(session, inventory)) { if (translator.prepareInventory(session, inventory)) {
if (translator instanceof DoubleChestInventoryTranslator && !((Container) inventory).isUsingRealBlock()) { if (translator instanceof DoubleChestInventoryTranslator && !((Container) inventory).isUsingRealBlock()) {
session.scheduleInEventLoop(() -> { session.scheduleInEventLoop(() -> {
Inventory openInv = session.getOpenInventory(); Inventory openInv = session.getOpenInventory();
@ -110,7 +111,11 @@ public class InventoryUtils {
inventory.setDisplayed(true); inventory.setDisplayed(true);
} }
} else { } else {
// Can occur if we e.g. did not find a spot to put a fake container in
ServerboundContainerClosePacket closePacket = new ServerboundContainerClosePacket(inventory.getJavaId());
session.sendDownstreamGamePacket(closePacket);
session.setOpenInventory(null); session.setOpenInventory(null);
session.setInventoryTranslator(InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR);
} }
} }