mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix handling for null ContainerTypes
EnumMap does not permit null values.
This commit is contained in:
parent
2e9ac9db7c
commit
1d713cb34c
2 changed files with 19 additions and 5 deletions
|
@ -41,6 +41,7 @@ import com.nukkitx.protocol.bedrock.data.inventory.stackrequestactions.*;
|
||||||
import com.nukkitx.protocol.bedrock.packet.ItemStackResponsePacket;
|
import com.nukkitx.protocol.bedrock.packet.ItemStackResponsePacket;
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.inventory.CartographyContainer;
|
import org.geysermc.geyser.inventory.CartographyContainer;
|
||||||
import org.geysermc.geyser.inventory.GeyserItemStack;
|
import org.geysermc.geyser.inventory.GeyserItemStack;
|
||||||
|
@ -65,11 +66,8 @@ import java.util.*;
|
||||||
public abstract class InventoryTranslator {
|
public abstract class InventoryTranslator {
|
||||||
|
|
||||||
public static final InventoryTranslator PLAYER_INVENTORY_TRANSLATOR = new PlayerInventoryTranslator();
|
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 */
|
/* Chest UIs */
|
||||||
put(ContainerType.GENERIC_9X1, new SingleChestInventoryTranslator(9));
|
put(ContainerType.GENERIC_9X1, new SingleChestInventoryTranslator(9));
|
||||||
put(ContainerType.GENERIC_9X2, new SingleChestInventoryTranslator(18));
|
put(ContainerType.GENERIC_9X2, new SingleChestInventoryTranslator(18));
|
||||||
|
@ -878,6 +876,22 @@ public abstract class InventoryTranslator {
|
||||||
return slotInfoData.getContainer() == ContainerSlotType.CURSOR;
|
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 {
|
protected enum CraftState {
|
||||||
START,
|
START,
|
||||||
RECIPE_ID,
|
RECIPE_ID,
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenSc
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryTranslator newTranslator = InventoryTranslator.INVENTORY_TRANSLATORS.get(packet.getType());
|
InventoryTranslator newTranslator = InventoryTranslator.inventoryTranslator(packet.getType());
|
||||||
Inventory openInventory = session.getOpenInventory();
|
Inventory openInventory = session.getOpenInventory();
|
||||||
// No translator exists for this window type. Close all windows and return.
|
// No translator exists for this window type. Close all windows and return.
|
||||||
if (newTranslator == null) {
|
if (newTranslator == null) {
|
||||||
|
|
Loading…
Reference in a new issue