diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/MetadataRewriter.java deleted file mode 100644 index f8724e2d5..000000000 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/MetadataRewriter.java +++ /dev/null @@ -1,33 +0,0 @@ -package us.myles.ViaVersion.protocols.protocol1_14_1to1_14; - -import us.myles.ViaVersion.api.Via; -import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.entities.Entity1_14Types; -import us.myles.ViaVersion.api.minecraft.metadata.Metadata; - -import java.util.ArrayList; -import java.util.List; - -public class MetadataRewriter { - - public static void handleMetadata(int entityId, Entity1_14Types.EntityType type, List metadatas, UserConnection connection) { - if (type == null) return; - - for (Metadata metadata : new ArrayList<>(metadatas)) { - try { - if (type.is(Entity1_14Types.EntityType.VILLAGER) || type.is(Entity1_14Types.EntityType.WANDERING_TRADER)) { - if (metadata.getId() >= 15) { - metadata.setId(metadata.getId() + 1); - } - } - } catch (Exception e) { - metadatas.remove(metadata); - if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { - Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler"); - Via.getPlatform().getLogger().warning("Metadata: " + metadata); - e.printStackTrace(); - } - } - } - } -} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java index 77b4182ef..0758c64e1 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/Protocol1_14_1To1_14.java @@ -2,18 +2,21 @@ package us.myles.ViaVersion.protocols.protocol1_14_1to1_14; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14; import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets.EntityPackets; -import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker; +import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1; public class Protocol1_14_1To1_14 extends Protocol { @Override protected void registerPackets() { + put(new MetadataRewriter1_14_1To1_14()); + EntityPackets.register(this); } @Override public void init(UserConnection userConnection) { - userConnection.put(new EntityTracker(userConnection)); + userConnection.put(new EntityTracker1_14_1(userConnection)); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/metadata/MetadataRewriter1_14_1To1_14.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/metadata/MetadataRewriter1_14_1To1_14.java new file mode 100644 index 000000000..3fb76c9f2 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/metadata/MetadataRewriter1_14_1To1_14.java @@ -0,0 +1,22 @@ +package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata; + +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_14Types; +import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.rewriters.MetadataRewriter; + +import java.util.List; + +public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter { + + public void handleMetadata(int entityId, EntityType type, Metadata metadata, List metadatas, UserConnection connection) { + if (type == null) return; + + if (type.is(EntityType.VILLAGER) || type.is(EntityType.WANDERING_TRADER)) { + if (metadata.getId() >= 15) { + metadata.setId(metadata.getId() + 1); + } + } + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java index 7d7373909..b19b2dcdc 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/packets/EntityPackets.java @@ -9,8 +9,8 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.MetadataRewriter; -import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker; +import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14; +import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1; public class EntityPackets { @@ -43,9 +43,9 @@ public class EntityPackets { Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType); - MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); } }); } @@ -72,8 +72,8 @@ public class EntityPackets { Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER; // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); - MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType); + protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); } }); } @@ -91,8 +91,8 @@ public class EntityPackets { public void handle(PacketWrapper wrapper) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); - Optional type = wrapper.user().get(EntityTracker.class).get(entityId); - MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); + Optional type = wrapper.user().get(EntityTracker1_14_1.class).getEntity(entityId); + protocol.get(MetadataRewriter1_14_1To1_14.class).handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/storage/EntityTracker.java deleted file mode 100644 index c28f14b49..000000000 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/storage/EntityTracker.java +++ /dev/null @@ -1,45 +0,0 @@ -package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage; - -import com.google.common.base.Optional; -import lombok.Getter; -import lombok.Setter; -import us.myles.ViaVersion.api.data.ExternalJoinGameListener; -import us.myles.ViaVersion.api.data.StoredObject; -import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.entities.Entity1_14Types; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -public class EntityTracker extends StoredObject implements ExternalJoinGameListener { - private final Map clientEntityTypes = new ConcurrentHashMap<>(); - @Getter - @Setter - private int clientEntityId; - - public EntityTracker(UserConnection user) { - super(user); - } - - public void removeEntity(int entityId) { - clientEntityTypes.remove(entityId); - } - - public void addEntity(int entityId, Entity1_14Types.EntityType type) { - clientEntityTypes.put(entityId, type); - } - - public boolean has(int entityId) { - return clientEntityTypes.containsKey(entityId); - } - - public Optional get(int id) { - return Optional.fromNullable(clientEntityTypes.get(id)); - } - - @Override - public void onExternalJoinGame(int playerEntityId) { - clientEntityId = playerEntityId; - clientEntityTypes.put(playerEntityId, Entity1_14Types.EntityType.PLAYER); - } -} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/storage/EntityTracker1_14_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/storage/EntityTracker1_14_1.java new file mode 100644 index 000000000..bff461a03 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14_1to1_14/storage/EntityTracker1_14_1.java @@ -0,0 +1,13 @@ +package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage; + +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.entities.Entity1_14Types; +import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType; +import us.myles.ViaVersion.api.storage.EntityTracker; + +public class EntityTracker1_14_1 extends EntityTracker { + + public EntityTracker1_14_1(UserConnection user) { + super(user, EntityType.PLAYER); + } +}