3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Implement Myles idea to just use templates instead of defining compatibility

Dieser Commit ist enthalten in:
Matsv 2016-05-21 21:19:20 +02:00
Ursprung 50a3e03649
Commit cdb757eae5
8 geänderte Dateien mit 43 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -117,7 +117,7 @@ public class PacketWrapper {
}
} else {
Pair<Type, Object> 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) {

Datei anzeigen

@ -83,16 +83,8 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
this.compatibilities = new HashSet<>();
}
public void addCompatibility(Class<? extends Type> claz) {
compatibilities.add(claz);
}
public void addCompatibility(Type claz) {
addCompatibility(claz.getClass());
}
public boolean isCompatibleWith(Type claz) {
return compatibilities.contains(claz.getClass());
public Class<? extends Type> getBaseClass() {
return this.getClass();
}
@Override

Datei anzeigen

@ -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<List<Metadata>> {
public MetaListTypeTemplate() {
super("MetaData List", List.class);
}
@Override
public Class<? extends Type> getBaseClass() {
return MetaListTypeTemplate.class;
}
}

Datei anzeigen

@ -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<Metadata> {
public MetaTypeTemplate() {
super("Metadata type", Metadata.class);
}
@Override
public Class<? extends Type> getBaseClass() {
return MetaTypeTemplate.class;
}
}

Datei anzeigen

@ -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<List<Metadata>> {
public MetadataListType() {
super("Metadata List", List.class);
}
public class MetadataListType extends MetaListTypeTemplate {
@Override
public List<Metadata> read(ByteBuf buffer) throws Exception {

Datei anzeigen

@ -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<Metadata> {
public MetadataType() {
super(Metadata.class);
}
public class MetadataType extends MetaTypeTemplate {
@Override
public Metadata read(ByteBuf buffer) throws Exception {

Datei anzeigen

@ -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<List<Metadata>> {
public MetaListSnapshotType() {
super(List.class);
addCompatibility(Protocol1_9TO1_8.METADATA_LIST);
}
public class MetaListSnapshotType extends MetaListTypeTemplate {
@Override
public List<Metadata> read(ByteBuf buffer) throws Exception {

Datei anzeigen

@ -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<Metadata> {
public MetaSnapshotType() {
super(Metadata.class);
addCompatibility(Protocol1_9TO1_8.METADATA);
}
public class MetaSnapshotType extends MetaTypeTemplate {
@Override
public Metadata read(ByteBuf buffer) throws Exception {