diff --git a/src/main/java/net/minestom/server/data/Data.java b/src/main/java/net/minestom/server/data/Data.java index 330647a6c..815c88eaf 100644 --- a/src/main/java/net/minestom/server/data/Data.java +++ b/src/main/java/net/minestom/server/data/Data.java @@ -1,23 +1,12 @@ package net.minestom.server.data; -import net.minestom.server.MinecraftServer; - import java.util.concurrent.ConcurrentHashMap; public class Data { - protected static final DataManager DATA_MANAGER = MinecraftServer.getDataManager(); - protected ConcurrentHashMap data = new ConcurrentHashMap(); public void set(String key, T value, Class type) { - // Type registering is only relevant if data should be serialized - if (this instanceof SerializableData) { - if (DATA_MANAGER.getDataType(type) == null) { - throw new UnsupportedOperationException("Type " + type.getName() + " hasn't been registered in DataManager#registerType"); - } - } - this.data.put(key, value); } diff --git a/src/main/java/net/minestom/server/data/SerializableData.java b/src/main/java/net/minestom/server/data/SerializableData.java index 66c84db24..c3188e868 100644 --- a/src/main/java/net/minestom/server/data/SerializableData.java +++ b/src/main/java/net/minestom/server/data/SerializableData.java @@ -1,5 +1,6 @@ package net.minestom.server.data; +import net.minestom.server.MinecraftServer; import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.utils.PrimitiveConversion; @@ -11,10 +12,16 @@ import java.util.concurrent.ConcurrentHashMap; public class SerializableData extends Data { + private static final DataManager DATA_MANAGER = MinecraftServer.getDataManager(); + private ConcurrentHashMap dataType = new ConcurrentHashMap<>(); @Override public void set(String key, T value, Class type) { + if (DATA_MANAGER.getDataType(type) == null) { + throw new UnsupportedOperationException("Type " + type.getName() + " hasn't been registered in DataManager#registerType"); + } + super.set(key, value, type); this.dataType.put(key, type); } diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 06f7b6ab0..f35a8b9b4 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -799,7 +799,7 @@ public class Player extends LivingEntity { if (openInventory == null) { closeWindowPacket.windowId = 0; } else { - closeWindowPacket.windowId = (byte) openInventory.getInventoryType().getWindowType(); + closeWindowPacket.windowId = openInventory.getWindowId(); openInventory.removeViewer(this); refreshOpenInventory(null); } diff --git a/src/main/java/net/minestom/server/inventory/Inventory.java b/src/main/java/net/minestom/server/inventory/Inventory.java index 213b6d8c4..15e168235 100644 --- a/src/main/java/net/minestom/server/inventory/Inventory.java +++ b/src/main/java/net/minestom/server/inventory/Inventory.java @@ -20,7 +20,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View private static volatile byte lastInventoryId; - private int id; + private byte id; private InventoryType inventoryType; private String title; @@ -66,7 +66,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View return title; } - public int getWindowId() { + public byte getWindowId() { return id; } @@ -134,7 +134,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View itemStack = itemStack == null ? ItemStack.getAirItem() : itemStack; this.itemStacks[slot] = itemStack; SetSlotPacket setSlotPacket = new SetSlotPacket(); - setSlotPacket.windowId = 1; + setSlotPacket.windowId = getWindowId(); setSlotPacket.slot = (short) slot; setSlotPacket.itemStack = itemStack; sendPacketToViewers(setSlotPacket);