mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 11:07:53 +01:00
Small tweaks
This commit is contained in:
parent
e022881554
commit
98875df389
@ -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<String, Object> data = new ConcurrentHashMap();
|
||||
|
||||
public <T> void set(String key, T value, Class<T> 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);
|
||||
}
|
||||
|
||||
|
@ -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<String, Class> dataType = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public <T> void set(String key, T value, Class<T> 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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user