3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-04 23:30:17 +01:00

Fix handling for null ContainerTypes

EnumMap does not permit null values.
Dieser Commit ist enthalten in:
RednedEpic 2021-12-04 14:35:01 -06:00
Ursprung 2e9ac9db7c
Commit 1d713cb34c
2 geänderte Dateien mit 19 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -41,6 +41,7 @@ import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.*;
import com.nukkitx.protocol.bedrock.packet.ItemStackResponsePacket;
import it.unimi.dsi.fastutil.ints.*;
import lombok.AllArgsConstructor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.inventory.CartographyContainer;
import org.geysermc.geyser.inventory.GeyserItemStack;
@ -65,11 +66,8 @@ import java.util.*;
public abstract class InventoryTranslator {
public static final InventoryTranslator PLAYER_INVENTORY_TRANSLATOR = new PlayerInventoryTranslator();
public static final Map<ContainerType, InventoryTranslator> INVENTORY_TRANSLATORS = new EnumMap<>(ContainerType.class) {
private static final Map<ContainerType, InventoryTranslator> INVENTORY_TRANSLATORS = new EnumMap<>(ContainerType.class) {
{
/* Player Inventory */
put(null, PLAYER_INVENTORY_TRANSLATOR);
/* Chest UIs */
put(ContainerType.GENERIC_9X1, new SingleChestInventoryTranslator(9));
put(ContainerType.GENERIC_9X2, new SingleChestInventoryTranslator(18));
@ -878,6 +876,22 @@ public abstract class InventoryTranslator {
return slotInfoData.getContainer() == ContainerSlotType.CURSOR;
}
/**
* Gets the {@link InventoryTranslator} for the given {@link ContainerType}.
* Returns {@link #PLAYER_INVENTORY_TRANSLATOR} if type is null.
*
* @param type the type
* @return the InventoryType for the given ContainerType.
*/
@Nullable
public static InventoryTranslator inventoryTranslator(@Nullable ContainerType type) {
if (type == null) {
return PLAYER_INVENTORY_TRANSLATOR;
}
return INVENTORY_TRANSLATORS.get(type);
}
protected enum CraftState {
START,
RECIPE_ID,

Datei anzeigen

@ -45,7 +45,7 @@ public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenSc
return;
}
InventoryTranslator newTranslator = InventoryTranslator.INVENTORY_TRANSLATORS.get(packet.getType());
InventoryTranslator newTranslator = InventoryTranslator.inventoryTranslator(packet.getType());
Inventory openInventory = session.getOpenInventory();
// No translator exists for this window type. Close all windows and return.
if (newTranslator == null) {