From b2680d76a61d6ba3abbbd344c6be7d90cc1debd6 Mon Sep 17 00:00:00 2001 From: Matsv Date: Mon, 11 Jul 2016 15:52:06 +0200 Subject: [PATCH] WIP cleanup --- .../api/type/types/minecraft/Types1_8.java | 20 +++++++++++++++++++ .../api/type/types/minecraft/Types1_9.java | 20 +++++++++++++++++++ .../Protocol1_10To1_9_3_4.java | 12 +++++++---- .../types/MetaList1_9_1_10Type.java | 8 ++++---- .../protocol1_9to1_8/Protocol1_9TO1_8.java | 3 +++ .../packets/EntityPackets.java | 11 +++++----- .../packets/SpawnPackets.java | 17 ++++++++-------- .../storage/EntityTracker.java | 4 ++-- .../types/MetadataList1_8Type.java | 4 ++-- 9 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Types1_8.java create mode 100644 src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Types1_9.java diff --git a/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Types1_8.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Types1_8.java new file mode 100644 index 000000000..40c39d3b8 --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Types1_8.java @@ -0,0 +1,20 @@ +package us.myles.ViaVersion.api.type.types.minecraft; + +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.Metadata1_8Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.MetadataList1_8Type; + +import java.util.List; + +public class Types1_8 { + /** + * Metadata list type for 1.8 + */ + public static Type> METADATA_LIST = new MetadataList1_8Type(); + + /** + * Metadata type for 1.8 + */ + public static Type METADATA = new Metadata1_8Type(); +} diff --git a/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Types1_9.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Types1_9.java new file mode 100644 index 000000000..cafd63b5e --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Types1_9.java @@ -0,0 +1,20 @@ +package us.myles.ViaVersion.api.type.types.minecraft; + +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.Meta1_9_1_10Type; +import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetaList1_9_1_10Type; + +import java.util.List; + +public class Types1_9 { + /** + * Metadata list type for 1.9 + */ + public static final Type> METADATA_LIST = new MetaList1_9_1_10Type(); + + /** + * Metadata type for 1.9 + */ + public static final Type METADATA = new Meta1_9_1_10Type(); +} diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java index 23abc46ad..7e67209c8 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java @@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.types.minecraft.Types1_9; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker; import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.Meta1_9_1_10Type; @@ -17,15 +18,18 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; public class Protocol1_10To1_9_3_4 extends Protocol { + @Deprecated public static final Type> METADATA_LIST = new MetaList1_9_1_10Type(); + @Deprecated public static final Type METADATA = new Meta1_9_1_10Type(); + public static ValueTransformer toNewPitch = new ValueTransformer(Type.FLOAT) { @Override public Float transform(PacketWrapper wrapper, Short inputValue) throws Exception { return inputValue / 63.5F; } }; - public static ValueTransformer, List> transformMetadata = new ValueTransformer, List>(METADATA_LIST) { + public static ValueTransformer, List> transformMetadata = new ValueTransformer, List>(Types1_9.METADATA_LIST) { @Override public List transform(PacketWrapper wrapper, List inputValue) throws Exception { List metaList = new CopyOnWriteArrayList<>(inputValue); @@ -80,7 +84,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID - map(METADATA_LIST, transformMetadata); // 1 - Metadata list + map(Types1_9.METADATA_LIST, transformMetadata); // 1 - Metadata list } }); @@ -100,7 +104,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { map(Type.SHORT); // 9 - Velocity X map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 11 - Velocity Z - map(METADATA_LIST, transformMetadata); // 12 - Metadata + map(Types1_9.METADATA_LIST, transformMetadata); // 12 - Metadata } }); @@ -115,7 +119,7 @@ public class Protocol1_10To1_9_3_4 extends Protocol { map(Type.DOUBLE); // 4 - Z map(Type.BYTE); // 5 - Yaw map(Type.BYTE); // 6 - Pitch - map(METADATA_LIST, transformMetadata); // 7 - Metadata list + map(Types1_9.METADATA_LIST, transformMetadata); // 7 - Metadata list } }); diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_9_1_10Type.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_9_1_10Type.java index 9f52af337..b8f590c78 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_9_1_10Type.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/types/MetaList1_9_1_10Type.java @@ -3,7 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.type.types.minecraft.MetaListTypeTemplate; -import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; +import us.myles.ViaVersion.api.type.types.minecraft.Types1_9; import java.util.ArrayList; import java.util.List; @@ -15,7 +15,7 @@ public class MetaList1_9_1_10Type extends MetaListTypeTemplate { List list = new ArrayList<>(); Metadata meta; do { - meta = Protocol1_10To1_9_3_4.METADATA.read(buffer); + meta = Types1_9.METADATA.read(buffer); if (meta != null) list.add(meta); } while (meta != null); @@ -26,9 +26,9 @@ public class MetaList1_9_1_10Type extends MetaListTypeTemplate { @Override public void write(ByteBuf buffer, List object) throws Exception { for (Metadata m : object) - Protocol1_10To1_9_3_4.METADATA.write(buffer, m); + Types1_9.METADATA.write(buffer, m); // Write end of list - Protocol1_10To1_9_3_4.METADATA.write(buffer, null); + Types1_9.METADATA.write(buffer, null); } } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java index 267fd85a7..0acd25ed4 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java @@ -26,8 +26,11 @@ import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; public class Protocol1_9TO1_8 extends Protocol { + @Deprecated public static Type> METADATA_LIST = new MetadataList1_8Type(); + @Deprecated public static Type METADATA = new Metadata1_8Type(); + private static Gson gson = new GsonBuilder().create(); public static ValueTransformer FIX_JSON = new ValueTransformer(Type.STRING) { @Override diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java index 43faa4c5d..ae5335719 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -10,8 +10,9 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.types.minecraft.Types1_8; +import us.myles.ViaVersion.api.type.types.minecraft.Types1_9; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter; @@ -176,11 +177,11 @@ public class EntityPackets { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID - map(Protocol1_9TO1_8.METADATA_LIST, Protocol1_10To1_9_3_4.METADATA_LIST); // 1 - Metadata List + map(Types1_8.METADATA_LIST, Types1_9.METADATA_LIST); // 1 - Metadata List handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); + List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); if (tracker.getClientEntityTypes().containsKey(entityID)) { @@ -197,7 +198,7 @@ public class EntityPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); + List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); tracker.handleMetadata(entityID, metadataList); @@ -208,7 +209,7 @@ public class EntityPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); + List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); if (metadataList.size() == 0) { wrapper.cancel(); } diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java index 3763d8349..475fe06f8 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java @@ -11,8 +11,9 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueCreator; import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.types.minecraft.Types1_8; +import us.myles.ViaVersion.api.type.types.minecraft.Types1_9; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter; @@ -108,7 +109,7 @@ public class SpawnPackets { // TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS Metadata potion = new Metadata(5, NewType.Slot.getTypeID(), Type.ITEM, item); meta.add(potion); - wrapper.write(Protocol1_10To1_9_3_4.METADATA_LIST, meta); + wrapper.write(Types1_9.METADATA_LIST, meta); } }); metaPacket.send(Protocol1_9TO1_8.class); @@ -207,11 +208,11 @@ public class SpawnPackets { map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 11 - Velocity Z - map(Protocol1_9TO1_8.METADATA_LIST, Protocol1_10To1_9_3_4.METADATA_LIST); + map(Types1_8.METADATA_LIST, Types1_9.METADATA_LIST); handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); + List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); if (tracker.getClientEntityTypes().containsKey(entityID)) { @@ -226,7 +227,7 @@ public class SpawnPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); + List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); tracker.handleMetadata(entityID, metadataList); @@ -312,12 +313,12 @@ public class SpawnPackets { } }); - map(Protocol1_9TO1_8.METADATA_LIST, Protocol1_10To1_9_3_4.METADATA_LIST); + map(Types1_8.METADATA_LIST, Types1_9.METADATA_LIST); handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); + List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); if (tracker.getClientEntityTypes().containsKey(entityID)) { @@ -333,7 +334,7 @@ public class SpawnPackets { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - List metadataList = wrapper.get(Protocol1_10To1_9_3_4.METADATA_LIST, 0); + List metadataList = wrapper.get(Types1_9.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); tracker.handleMetadata(entityID, metadataList); diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java index f5be00076..3e32fb868 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java @@ -19,8 +19,8 @@ import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.types.minecraft.Types1_9; import us.myles.ViaVersion.protocols.base.ProtocolInfo; -import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter; @@ -275,7 +275,7 @@ public class EntityTracker extends StoredObject { if (metadataBuffer.containsKey(entityID)) { PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser()); wrapper.write(Type.VAR_INT, entityID); - wrapper.write(Protocol1_10To1_9_3_4.METADATA_LIST, metadataBuffer.get(entityID)); + wrapper.write(Types1_9.METADATA_LIST, metadataBuffer.get(entityID)); MetadataRewriter.transform(getClientEntityTypes().get(entityID), metadataBuffer.get(entityID)); handleMetadata(entityID, metadataBuffer.get(entityID)); if (metadataBuffer.get(entityID).size() > 0) { diff --git a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataList1_8Type.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataList1_8Type.java index 8c6622ef9..beadec9a4 100644 --- a/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataList1_8Type.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataList1_8Type.java @@ -3,7 +3,7 @@ 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.types.minecraft.MetaListTypeTemplate; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.api.type.types.minecraft.Types1_8; import java.util.ArrayList; import java.util.List; @@ -15,7 +15,7 @@ public class MetadataList1_8Type extends MetaListTypeTemplate { List list = new ArrayList<>(); Metadata m; do { - m = Protocol1_9TO1_8.METADATA.read(buffer); + m = Types1_8.METADATA.read(buffer); if (m != null) { list.add(m); }