diff --git a/common/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java b/common/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java index 345f994b..bf99806a 100644 --- a/common/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java +++ b/common/src/main/java/nl/matsv/viabackwards/api/BackwardsProtocol.java @@ -1,7 +1,9 @@ package nl.matsv.viabackwards.api; import nl.matsv.viabackwards.api.data.BackwardsMappings; +import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import org.jetbrains.annotations.Nullable; +import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; @@ -25,6 +27,15 @@ public abstract class BackwardsProtocol trackers = new ConcurrentHashMap<>(); + private final Map trackers = new HashMap<>(); private int currentWorldSectionHeight = 16; private int currentMinY; @@ -89,7 +90,7 @@ public class EntityTracker extends StoredObject { public static final class StoredEntity { private final int entityId; private final EntityType type; - private final Map, EntityStorage> storedObjects = new ConcurrentHashMap<>(); + private Map, EntityStorage> storedObjects; private StoredEntity(final int entityId, final EntityType type) { this.entityId = entityId; @@ -105,7 +106,7 @@ public class EntityTracker extends StoredObject { */ @Nullable public T get(Class objectClass) { - return (T) storedObjects.get(objectClass); + return storedObjects != null ? (T) storedObjects.get(objectClass) : null; } /** @@ -115,7 +116,7 @@ public class EntityTracker extends StoredObject { * @return True if the object is in the storage */ public boolean has(Class objectClass) { - return storedObjects.containsKey(objectClass); + return storedObjects != null && storedObjects.containsKey(objectClass); } /** @@ -124,6 +125,9 @@ public class EntityTracker extends StoredObject { * @param object The object to store. */ public void put(EntityStorage object) { + if (storedObjects == null) { + storedObjects = new ConcurrentHashMap<>(); + } storedObjects.put(object.getClass(), object); } diff --git a/common/src/main/java/nl/matsv/viabackwards/api/entities/storage/MetaStorage.java b/common/src/main/java/nl/matsv/viabackwards/api/entities/storage/MetaStorage.java index e6b5164a..1a8ad115 100644 --- a/common/src/main/java/nl/matsv/viabackwards/api/entities/storage/MetaStorage.java +++ b/common/src/main/java/nl/matsv/viabackwards/api/entities/storage/MetaStorage.java @@ -48,18 +48,6 @@ public class MetaStorage { return null; } - public Metadata getOrDefault(int index, Metadata data) { - return getOrDefault(index, false, data); - } - - public Metadata getOrDefault(int index, boolean removeIfExists, Metadata data) { - Metadata existingData = get(index); - if (removeIfExists && existingData != null) { - delete(existingData); - } - return existingData != null ? existingData : data; - } - public List getMetaDataList() { return metaDataList; } diff --git a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java index ae348a4f..43cc0657 100644 --- a/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java +++ b/common/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/Protocol1_10To1_11.java @@ -12,7 +12,6 @@ package nl.matsv.viabackwards.protocol.protocol1_10to1_11; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.data.BackwardsMappings; -import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.rewriters.SoundRewriter; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.BlockItemPackets1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets.EntityPackets1_11; @@ -51,17 +50,11 @@ public class Protocol1_10To1_11 extends BackwardsProtocol { @@ -21,12 +19,6 @@ public class Protocol1_14To1_14_1 extends BackwardsProtocol