diff --git a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 943a8f4fa..6ba2dadb5 100644 --- a/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java +++ b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -117,7 +117,7 @@ public class PacketWrapper { } } else { Pair read = readableObjects.poll(); - if (read.getKey().equals(type) || (type.isCompatibleWith(read.getKey()) && type.getOutputClass().equals(read.getKey().getOutputClass()))) { + if (read.getKey().equals(type) || (type.getBaseClass().equals(read.getKey().getBaseClass()) && type.getOutputClass().equals(read.getKey().getOutputClass()))) { return (T) read.getValue(); } else { if (type == Type.NOTHING) { diff --git a/src/main/java/us/myles/ViaVersion/api/type/Type.java b/src/main/java/us/myles/ViaVersion/api/type/Type.java index ef7833d08..33f89bb63 100644 --- a/src/main/java/us/myles/ViaVersion/api/type/Type.java +++ b/src/main/java/us/myles/ViaVersion/api/type/Type.java @@ -83,16 +83,8 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { this.compatibilities = new HashSet<>(); } - public void addCompatibility(Class claz) { - compatibilities.add(claz); - } - - public void addCompatibility(Type claz) { - addCompatibility(claz.getClass()); - } - - public boolean isCompatibleWith(Type claz) { - return compatibilities.contains(claz.getClass()); + public Class getBaseClass() { + return this.getClass(); } @Override diff --git a/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/MetaListTypeTemplate.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/MetaListTypeTemplate.java new file mode 100644 index 000000000..187d0c436 --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/MetaListTypeTemplate.java @@ -0,0 +1,17 @@ +package us.myles.ViaVersion.api.type.types.minecraft; + +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.type.Type; + +import java.util.List; + +public abstract class MetaListTypeTemplate extends Type> { + public MetaListTypeTemplate() { + super("MetaData List", List.class); + } + + @Override + public Class getBaseClass() { + return MetaListTypeTemplate.class; + } +} diff --git a/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/MetaTypeTemplate.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/MetaTypeTemplate.java new file mode 100644 index 000000000..68bb859c8 --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/MetaTypeTemplate.java @@ -0,0 +1,15 @@ +package us.myles.ViaVersion.api.type.types.minecraft; + +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.type.Type; + +public abstract class MetaTypeTemplate extends Type { + public MetaTypeTemplate() { + super("Metadata type", Metadata.class); + } + + @Override + public Class getBaseClass() { + return MetaTypeTemplate.class; + } +} diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java index 9e6d761f8..4e3918f50 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java @@ -2,16 +2,13 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.types; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; -import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.types.minecraft.MetaListTypeTemplate; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import java.util.ArrayList; import java.util.List; -public class MetadataListType extends Type> { - public MetadataListType() { - super("Metadata List", List.class); - } +public class MetadataListType extends MetaListTypeTemplate { @Override public List read(ByteBuf buffer) throws Exception { diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java index 46c5e13ef..8e6760aeb 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java @@ -3,14 +3,10 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.types; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; -import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataTypes; -public class MetadataType extends Type { - - public MetadataType() { - super(Metadata.class); - } +public class MetadataType extends MetaTypeTemplate { @Override public Metadata read(ByteBuf buffer) throws Exception { diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaListSnapshotType.java b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaListSnapshotType.java index 9fcdb1024..3d877106b 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaListSnapshotType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaListSnapshotType.java @@ -3,17 +3,13 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_9_3; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.api.type.types.minecraft.MetaListTypeTemplate; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType; import java.util.ArrayList; import java.util.List; -public class MetaListSnapshotType extends Type> { - public MetaListSnapshotType() { - super(List.class); - addCompatibility(Protocol1_9TO1_8.METADATA_LIST); - } +public class MetaListSnapshotType extends MetaListTypeTemplate { @Override public List read(ByteBuf buffer) throws Exception { diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaSnapshotType.java b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaSnapshotType.java index 47e8f4d03..0fcaa72cc 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaSnapshotType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_9_3/MetaSnapshotType.java @@ -2,15 +2,10 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_9_3; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; -import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType; -public class MetaSnapshotType extends Type { - public MetaSnapshotType() { - super(Metadata.class); - addCompatibility(Protocol1_9TO1_8.METADATA); - } +public class MetaSnapshotType extends MetaTypeTemplate { @Override public Metadata read(ByteBuf buffer) throws Exception {