From 8a35c0235ee7a80a2b2249962cc471b60e16d24e Mon Sep 17 00:00:00 2001 From: Myles Date: Fri, 18 Mar 2016 21:18:48 +0000 Subject: [PATCH] Move everything into the right package. Clean up a lot of code. Remove PacketUtil (evil laugh) Add Pipeline Util Organise listeners, and add protocol pipe checks --- .../us/myles/ViaVersion/ViaIdleThread.java | 14 +- .../us/myles/ViaVersion/ViaVersionPlugin.java | 27 +- .../api/PacketWrapper.java | 13 +- .../api/util => ViaVersion/api}/Pair.java | 4 +- .../myles/ViaVersion/api/ViaVersionAPI.java | 1 + .../us/myles/ViaVersion/api/boss/BossBar.java | 32 +- .../api/data/StoredObject.java | 3 +- .../api/data/UserConnection.java | 6 +- .../api/minecraft}/Position.java | 2 +- .../{ => api/minecraft}/chunks/Chunk.java | 2 +- .../minecraft}/chunks/ChunkSection.java | 40 +- .../minecraft}/chunks/NibbleArray.java | 20 +- .../api/minecraft}/item/Item.java | 4 +- .../api/minecraft}/metadata/Metadata.java | 4 +- .../api/protocol/Protocol.java | 10 +- .../api/protocol/ProtocolPipeline.java | 10 +- .../api/protocol/ProtocolRegistry.java | 15 +- .../api/protocol/ProtocolVersion.java | 2 +- .../api/remapper/PacketHandler.java | 4 +- .../api/remapper/PacketRemapper.java | 10 +- .../api/remapper/TypeRemapper.java | 6 +- .../api/remapper/ValueCreator.java | 4 +- .../ViaVersion/api/remapper/ValueReader.java | 7 + .../api/remapper/ValueTransformer.java | 6 +- .../ViaVersion/api/remapper/ValueWriter.java | 7 + .../ViaVersion/api/type/ByteBufReader.java | 7 + .../ViaVersion/api/type/ByteBufWriter.java | 7 + .../api/type/PartialType.java | 10 +- .../api/type/Type.java | 10 +- .../ViaVersion/api/type/TypeConverter.java | 5 + .../api/type/types/ArrayType.java | 42 +- .../api/type/types/BooleanType.java | 8 +- .../api/type/types/ByteType.java | 10 +- .../api/type/types/DoubleType.java | 12 +- .../api/type/types/FloatType.java | 12 +- .../api/type/types/IntType.java | 12 +- .../api/type/types/LongType.java | 10 +- .../api/type/types/RemainingBytesType.java | 4 +- .../api/type/types/ShortType.java | 10 +- .../api/type/types/StringType.java | 4 +- .../api/type/types/UUIDType.java | 4 +- .../api/type/types/UnsignedByteType.java | 10 +- .../api/type/types/UnsignedShortType.java | 10 +- .../api/type/types/VarIntType.java | 8 +- .../api/type/types/VoidType.java | 8 +- .../type/types/minecraft/EulerAngleType.java | 5 +- .../type/types/minecraft/ItemArrayType.java | 6 +- .../api/type/types/minecraft/ItemType.java | 6 +- .../api/type/types/minecraft/NBTType.java | 9 +- .../api/type/types/minecraft/OptUUIDType.java | 11 +- .../type/types/minecraft/PositionType.java | 6 +- .../api/type/types/minecraft/VectorType.java | 4 +- .../us/myles/ViaVersion/boss/ViaBossBar.java | 67 ++- .../commands/ViaVersionCommand.java | 5 +- .../ViaVersion/handlers/ViaChunkHandler.java | 6 +- .../ViaVersion/handlers/ViaDecodeHandler.java | 15 +- .../ViaVersion/handlers/ViaEncodeHandler.java | 15 +- .../handlers/ViaVersionInitializer.java | 4 +- .../myles/ViaVersion/packets/PacketType.java | 69 ++- .../protocols}/base/BaseProtocol.java | 20 +- .../protocols}/base/ProtocolInfo.java | 10 +- .../Protocol1_9_1TO1_9.java | 12 +- .../protocol1_9to1_8}/ArmorType.java | 16 +- .../protocol1_9to1_8/ItemRewriter.java | 4 +- .../PlayerMovementMapper.java | 10 +- .../protocol1_9to1_8/Protocol1_9TO1_8.java | 78 ++- .../listeners}/ArmorListener.java | 42 +- .../listeners/CommandBlockListener.java | 42 +- .../protocol1_9to1_8}/metadata/MetaIndex.java | 384 ++++++------ .../metadata/MetadataRewriter.java | 37 +- .../metadata/MetadataTypes.java | 4 +- .../protocol1_9to1_8}/metadata/NewType.java | 2 +- .../protocol1_9to1_8}/metadata/Type.java | 2 +- .../packets/EntityPackets.java | 34 +- .../packets/InventoryPackets.java | 24 +- .../packets/PlayerPackets.java | 76 ++- .../packets/SpawnPackets.java | 32 +- .../packets/WorldPackets.java | 30 +- .../sounds/SoundCategory.java | 2 +- .../protocol1_9to1_8}/sounds/SoundEffect.java | 566 +++++++++--------- .../storage/ClientChunks.java | 20 +- .../storage/EntityTracker.java | 38 +- .../storage/InventoryTracker.java | 6 +- .../storage/MovementTracker.java | 8 +- .../protocol1_9to1_8/types/ChunkType.java | 44 +- .../types/MetadataListType.java | 8 +- .../protocol1_9to1_8/types/MetadataType.java | 8 +- .../ViaVersion/update/UpdateListener.java | 18 +- .../myles/ViaVersion/update/UpdateUtil.java | 3 +- .../myles/ViaVersion/util/Configuration.java | 44 +- .../us/myles/ViaVersion/util/PacketUtil.java | 294 --------- .../myles/ViaVersion/util/PipelineUtil.java | 60 ++ .../myles/ViaVersion/util/ReflectionUtil.java | 9 +- .../ViaVersion2/api/remapper/ValueReader.java | 8 - .../ViaVersion2/api/remapper/ValueWriter.java | 7 - .../ViaVersion2/api/type/ByteBufReader.java | 7 - .../ViaVersion2/api/type/ByteBufWriter.java | 7 - .../ViaVersion2/api/type/TypeConverter.java | 5 - 98 files changed, 1268 insertions(+), 1437 deletions(-) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/PacketWrapper.java (94%) rename src/main/java/us/myles/{ViaVersion2/api/util => ViaVersion/api}/Pair.java (79%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/data/StoredObject.java (83%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/data/UserConnection.java (97%) rename src/main/java/us/myles/{ViaVersion2/api/util => ViaVersion/api/minecraft}/Position.java (80%) rename src/main/java/us/myles/ViaVersion/{ => api/minecraft}/chunks/Chunk.java (93%) rename src/main/java/us/myles/ViaVersion/{ => api/minecraft}/chunks/ChunkSection.java (79%) rename src/main/java/us/myles/ViaVersion/{ => api/minecraft}/chunks/NibbleArray.java (86%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/api/minecraft}/item/Item.java (86%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/api/minecraft}/metadata/Metadata.java (71%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/protocol/Protocol.java (91%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/protocol/ProtocolPipeline.java (91%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/protocol/ProtocolRegistry.java (85%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/protocol/ProtocolVersion.java (85%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/remapper/PacketHandler.java (74%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/remapper/PacketRemapper.java (89%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/remapper/TypeRemapper.java (75%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/remapper/ValueCreator.java (74%) create mode 100644 src/main/java/us/myles/ViaVersion/api/remapper/ValueReader.java rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/remapper/ValueTransformer.java (77%) create mode 100644 src/main/java/us/myles/ViaVersion/api/remapper/ValueWriter.java create mode 100644 src/main/java/us/myles/ViaVersion/api/type/ByteBufReader.java create mode 100644 src/main/java/us/myles/ViaVersion/api/type/ByteBufWriter.java rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/PartialType.java (62%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/Type.java (93%) create mode 100644 src/main/java/us/myles/ViaVersion/api/type/TypeConverter.java rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/ArrayType.java (93%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/BooleanType.java (77%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/ByteType.java (70%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/DoubleType.java (69%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/FloatType.java (69%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/IntType.java (69%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/LongType.java (71%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/RemainingBytesType.java (83%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/ShortType.java (70%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/StringType.java (91%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/UUIDType.java (84%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/UnsignedByteType.java (71%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/UnsignedShortType.java (72%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/VarIntType.java (86%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/VoidType.java (72%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/minecraft/EulerAngleType.java (84%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/minecraft/ItemArrayType.java (82%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/minecraft/ItemType.java (86%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/minecraft/NBTType.java (84%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/minecraft/OptUUIDType.java (76%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/minecraft/PositionType.java (82%) rename src/main/java/us/myles/{ViaVersion2 => ViaVersion}/api/type/types/minecraft/VectorType.java (87%) rename src/main/java/us/myles/{ViaVersion2/api/protocol => ViaVersion/protocols}/base/BaseProtocol.java (92%) rename src/main/java/us/myles/{ViaVersion2/api/protocol => ViaVersion/protocols}/base/ProtocolInfo.java (59%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9_1to1_9/Protocol1_9_1TO1_9.java (73%) rename src/main/java/us/myles/ViaVersion/{armor => protocols/protocol1_9to1_8}/ArmorType.java (86%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/ItemRewriter.java (98%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/PlayerMovementMapper.java (54%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/Protocol1_9TO1_8.java (77%) rename src/main/java/us/myles/ViaVersion/{armor => protocols/protocol1_9to1_8/listeners}/ArmorListener.java (72%) rename src/main/java/us/myles/ViaVersion/{ => protocols/protocol1_9to1_8}/listeners/CommandBlockListener.java (71%) rename src/main/java/us/myles/ViaVersion/{ => protocols/protocol1_9to1_8}/metadata/MetaIndex.java (97%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/metadata/MetadataRewriter.java (82%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/metadata/MetadataTypes.java (82%) rename src/main/java/us/myles/ViaVersion/{ => protocols/protocol1_9to1_8}/metadata/NewType.java (85%) rename src/main/java/us/myles/ViaVersion/{ => protocols/protocol1_9to1_8}/metadata/Type.java (84%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/packets/EntityPackets.java (92%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/packets/InventoryPackets.java (95%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/packets/PlayerPackets.java (88%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/packets/SpawnPackets.java (92%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/packets/WorldPackets.java (92%) rename src/main/java/us/myles/ViaVersion/{ => protocols/protocol1_9to1_8}/sounds/SoundCategory.java (87%) rename src/main/java/us/myles/ViaVersion/{ => protocols/protocol1_9to1_8}/sounds/SoundEffect.java (98%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/storage/ClientChunks.java (93%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/storage/EntityTracker.java (86%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/storage/InventoryTracker.java (57%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/storage/MovementTracker.java (73%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/types/ChunkType.java (82%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/types/MetadataListType.java (78%) rename src/main/java/us/myles/{ViaVersion2/api => ViaVersion/protocols}/protocol1_9to1_8/types/MetadataType.java (78%) delete mode 100644 src/main/java/us/myles/ViaVersion/util/PacketUtil.java create mode 100644 src/main/java/us/myles/ViaVersion/util/PipelineUtil.java delete mode 100644 src/main/java/us/myles/ViaVersion2/api/remapper/ValueReader.java delete mode 100644 src/main/java/us/myles/ViaVersion2/api/remapper/ValueWriter.java delete mode 100644 src/main/java/us/myles/ViaVersion2/api/type/ByteBufReader.java delete mode 100644 src/main/java/us/myles/ViaVersion2/api/type/ByteBufWriter.java delete mode 100644 src/main/java/us/myles/ViaVersion2/api/type/TypeConverter.java diff --git a/src/main/java/us/myles/ViaVersion/ViaIdleThread.java b/src/main/java/us/myles/ViaVersion/ViaIdleThread.java index 6cf782ada..7bcd59d6a 100644 --- a/src/main/java/us/myles/ViaVersion/ViaIdleThread.java +++ b/src/main/java/us/myles/ViaVersion/ViaIdleThread.java @@ -2,11 +2,11 @@ package us.myles.ViaVersion; import org.bukkit.scheduler.BukkitRunnable; import us.myles.ViaVersion.api.ViaVersion; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; import us.myles.ViaVersion.util.ReflectionUtil; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.MovementTracker; import java.util.Map; import java.util.UUID; @@ -19,15 +19,15 @@ public class ViaIdleThread extends BukkitRunnable { this.portedPlayers = portedPlayers; try { this.idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying"); - } catch(ClassNotFoundException e) { + } catch (ClassNotFoundException e) { throw new RuntimeException("Couldn't find player idle packet, help!", e); } } @Override public void run() { - for(UserConnection info : portedPlayers.values()) { - if(info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { + for (UserConnection info : portedPlayers.values()) { + if (info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket(); if (nextIdleUpdate <= System.currentTimeMillis()) { try { diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index e297a3222..efa05b282 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -17,19 +17,19 @@ import us.myles.ViaVersion.api.ViaVersionAPI; import us.myles.ViaVersion.api.boss.BossBar; import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossStyle; -import us.myles.ViaVersion.armor.ArmorListener; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.protocol.ProtocolRegistry; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.boss.ViaBossBar; import us.myles.ViaVersion.commands.ViaVersionCommand; import us.myles.ViaVersion.handlers.ViaVersionInitializer; -import us.myles.ViaVersion.listeners.CommandBlockListener; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.ArmorListener; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.CommandBlockListener; import us.myles.ViaVersion.update.UpdateListener; import us.myles.ViaVersion.update.UpdateUtil; import us.myles.ViaVersion.util.Configuration; import us.myles.ViaVersion.util.ListWrapper; import us.myles.ViaVersion.util.ReflectionUtil; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol.ProtocolRegistry; -import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo; import java.io.File; import java.lang.reflect.Field; @@ -244,7 +244,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { @Override public int getPlayerVersion(@NonNull Player player) { if (!isPorted(player)) - return 47; + return ProtocolRegistry.SERVER_PROTOCOL; return portedPlayers.get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion(); } @@ -258,6 +258,14 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { return getDescription().getVersion(); } + public UserConnection getConnection(UUID playerUUID){ + return portedPlayers.get(playerUUID); + } + + public UserConnection getConnection(Player player){ + return portedPlayers.get(player.getUniqueId()); + } + public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException { sendRawPacket(player.getUniqueId(), packet); } @@ -292,8 +300,8 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { return getConfig().getBoolean("prevent-collision", true); } - public boolean isNewEffectIndicator(){ - return getConfig().getBoolean("use-new-effect-indicator",true); + public boolean isNewEffectIndicator() { + return getConfig().getBoolean("use-new-effect-indicator", true); } public boolean isSuppressMetadataErrors() { @@ -322,8 +330,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { public boolean isAutoTeam() { // Collision has to be enabled first - if (!isPreventCollision()) return false; - return getConfig().getBoolean("auto-team", true); + return isPreventCollision() && getConfig().getBoolean("auto-team", true); } public void addPortedClient(UserConnection info) { diff --git a/src/main/java/us/myles/ViaVersion2/api/PacketWrapper.java b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java similarity index 94% rename from src/main/java/us/myles/ViaVersion2/api/PacketWrapper.java rename to src/main/java/us/myles/ViaVersion/api/PacketWrapper.java index 8573dd5d9..a60e6b91b 100644 --- a/src/main/java/us/myles/ViaVersion2/api/PacketWrapper.java +++ b/src/main/java/us/myles/ViaVersion/api/PacketWrapper.java @@ -1,15 +1,14 @@ -package us.myles.ViaVersion2.api; +package us.myles.ViaVersion.api; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import lombok.Getter; import lombok.Setter; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.remapper.ValueCreator; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; -import us.myles.ViaVersion2.api.util.Pair; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.remapper.ValueCreator; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; import java.io.IOException; import java.util.ArrayList; @@ -60,7 +59,7 @@ public class PacketWrapper { } public T read(Type type) throws Exception { - if(type == Type.NOTHING) return null; + if (type == Type.NOTHING) return null; if (readableObjects.isEmpty()) { Preconditions.checkNotNull(inputBuffer, "This packet does not have an input buffer."); // We could in the future log input read values, but honestly for things like bulk maps, mem waste D: diff --git a/src/main/java/us/myles/ViaVersion2/api/util/Pair.java b/src/main/java/us/myles/ViaVersion/api/Pair.java similarity index 79% rename from src/main/java/us/myles/ViaVersion2/api/util/Pair.java rename to src/main/java/us/myles/ViaVersion/api/Pair.java index c57280547..2f744bb9b 100644 --- a/src/main/java/us/myles/ViaVersion2/api/util/Pair.java +++ b/src/main/java/us/myles/ViaVersion/api/Pair.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion2.api.util; +package us.myles.ViaVersion.api; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -13,7 +13,7 @@ public class Pair { private X key; private Y value; - public Pair(X key, Y value){ + public Pair(X key, Y value) { this.key = key; this.value = value; } diff --git a/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java b/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java index e05389461..38bf56827 100644 --- a/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java +++ b/src/main/java/us/myles/ViaVersion/api/ViaVersionAPI.java @@ -19,6 +19,7 @@ public interface ViaVersionAPI { /** * Get protocol number from a player + * * @param player Bukkit player object * @return Protocol ID, For example (47=1.8-1.8.8, 107=1.9, 108=1.9.1) */ diff --git a/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java b/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java index da9010cd6..07cfd4b34 100644 --- a/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java +++ b/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java @@ -6,13 +6,6 @@ import java.util.Set; import java.util.UUID; public interface BossBar { - /** - * Change the title - * - * @param title Title can be in either JSON or just text - */ - void setTitle(String title); - /** * Get the current title * @@ -21,11 +14,11 @@ public interface BossBar { String getTitle(); /** - * Change the health + * Change the title * - * @param health this float has to be between 0F - 1F + * @param title Title can be in either JSON or just text */ - void setHealth(float health); + void setTitle(String title); /** * Get the health @@ -35,11 +28,11 @@ public interface BossBar { float getHealth(); /** - * Yay colors! + * Change the health * - * @param color Whatever color you want! + * @param health this float has to be between 0F - 1F */ - void setColor(BossColor color); + void setHealth(float health); /** * Get the bossbar color @@ -49,11 +42,11 @@ public interface BossBar { BossColor getColor(); /** - * Change the bosbar style + * Yay colors! * - * @param style BossStyle + * @param color Whatever color you want! */ - void setStyle(BossStyle style); + void setColor(BossColor color); /** * Get the bosbar style @@ -62,6 +55,13 @@ public interface BossBar { */ BossStyle getStyle(); + /** + * Change the bosbar style + * + * @param style BossStyle + */ + void setStyle(BossStyle style); + /** * Show the bossbar to a player. * diff --git a/src/main/java/us/myles/ViaVersion2/api/data/StoredObject.java b/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java similarity index 83% rename from src/main/java/us/myles/ViaVersion2/api/data/StoredObject.java rename to src/main/java/us/myles/ViaVersion/api/data/StoredObject.java index 6613bd6ce..aa9b29584 100644 --- a/src/main/java/us/myles/ViaVersion2/api/data/StoredObject.java +++ b/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java @@ -1,8 +1,9 @@ -package us.myles.ViaVersion2.api.data; +package us.myles.ViaVersion.api.data; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; + @Getter(AccessLevel.PROTECTED) @AllArgsConstructor public class StoredObject { diff --git a/src/main/java/us/myles/ViaVersion2/api/data/UserConnection.java b/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java similarity index 97% rename from src/main/java/us/myles/ViaVersion2/api/data/UserConnection.java rename to src/main/java/us/myles/ViaVersion/api/data/UserConnection.java index 1a5065f73..9a702dd6e 100644 --- a/src/main/java/us/myles/ViaVersion2/api/data/UserConnection.java +++ b/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion2.api.data; +package us.myles.ViaVersion.api.data; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; @@ -10,13 +10,13 @@ import java.util.ArrayList; import java.util.List; public class UserConnection { + @Getter + private final SocketChannel channel; List storedObjects = new ArrayList<>(); @Getter @Setter private boolean active = true; @Getter - private final SocketChannel channel; - @Getter @Setter private Object lastPacket; diff --git a/src/main/java/us/myles/ViaVersion2/api/util/Position.java b/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java similarity index 80% rename from src/main/java/us/myles/ViaVersion2/api/util/Position.java rename to src/main/java/us/myles/ViaVersion/api/minecraft/Position.java index 3ad5e0002..7d59aba0f 100644 --- a/src/main/java/us/myles/ViaVersion2/api/util/Position.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion2.api.util; +package us.myles.ViaVersion.api.minecraft; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/us/myles/ViaVersion/chunks/Chunk.java b/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java similarity index 93% rename from src/main/java/us/myles/ViaVersion/chunks/Chunk.java rename to src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java index e57029742..4c74b99b0 100644 --- a/src/main/java/us/myles/ViaVersion/chunks/Chunk.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.chunks; +package us.myles.ViaVersion.api.minecraft.chunks; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/us/myles/ViaVersion/chunks/ChunkSection.java b/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java similarity index 79% rename from src/main/java/us/myles/ViaVersion/chunks/ChunkSection.java rename to src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java index 599da1ca8..5308f41b0 100644 --- a/src/main/java/us/myles/ViaVersion/chunks/ChunkSection.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java @@ -1,10 +1,9 @@ -package us.myles.ViaVersion.chunks; +package us.myles.ViaVersion.api.minecraft.chunks; import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import org.bukkit.Material; -import us.myles.ViaVersion.util.PacketUtil; +import us.myles.ViaVersion.api.type.Type; import java.util.List; @@ -20,7 +19,6 @@ public class ChunkSection { /** * Length of the block data array. */ -// public static final int BLOCK_LENGTH = 16 * 16 * 16 * 2; // size * size * size * 2 (char bit count) private final List palette = Lists.newArrayList(); private final int[] blocks; @@ -40,7 +38,7 @@ public class ChunkSection { public void setBlock(int idx, int type, int data) { int hash = type << 4 | (data & 0xF); int index = palette.indexOf(hash); - if(index == -1) { + if (index == -1) { index = palette.size(); palette.add(hash); } @@ -53,7 +51,7 @@ public class ChunkSection { } public void setSkyLight(byte[] data) { - if(data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH); + if (data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH); this.skyLight = new NibbleArray(data); } @@ -61,37 +59,39 @@ public class ChunkSection { return z << 8 | y << 4 | x; } - public void writeBlocks(ByteBuf output) { + public void writeBlocks(ByteBuf output) throws Exception { // Write bits per block int bitsPerBlock = 4; - while(palette.size() > 1 << bitsPerBlock) { + while (palette.size() > 1 << bitsPerBlock) { bitsPerBlock += 1; } long maxEntryValue = (1L << bitsPerBlock) - 1; output.writeByte(bitsPerBlock); // Write pallet (or not) - PacketUtil.writeVarInt(palette.size(), output); - for(int mappedId : palette) { - PacketUtil.writeVarInt(mappedId, output); + Type.VAR_INT.write(output, palette.size()); + for (int mappedId : palette) { + Type.VAR_INT.write(output, mappedId); } int length = (int) Math.ceil(SIZE * bitsPerBlock / 64.0); - PacketUtil.writeVarInt(length, output); + Type.VAR_INT.write(output, length); long[] data = new long[length]; - for(int index = 0; index < blocks.length; index++) { + for (int index = 0; index < blocks.length; index++) { int value = blocks[index]; int bitIndex = index * bitsPerBlock; int startIndex = bitIndex / 64; int endIndex = ((index + 1) * bitsPerBlock - 1) / 64; int startBitSubIndex = bitIndex % 64; data[startIndex] = data[startIndex] & ~(maxEntryValue << startBitSubIndex) | ((long) value & maxEntryValue) << startBitSubIndex; - if(startIndex != endIndex) { + if (startIndex != endIndex) { int endBitSubIndex = 64 - startBitSubIndex; data[endIndex] = data[endIndex] >>> endBitSubIndex << endBitSubIndex | ((long) value & maxEntryValue) >> endBitSubIndex; } } - PacketUtil.writeLongs(data, output); + for (long l : data) { + Type.LONG.write(output, l); + } } public void writeBlockLight(ByteBuf output) { @@ -111,7 +111,7 @@ public class ChunkSection { * * @return Amount of bytes sent by this section */ - public int getExpectedSize() { + public int getExpectedSize() throws Exception { int bitsPerBlock = palette.size() > 255 ? 16 : 8; int bytes = 1; // bits per block bytes += paletteBytes(); // palette @@ -122,19 +122,19 @@ public class ChunkSection { return bytes; } - private int paletteBytes() { + private int paletteBytes() throws Exception { // Count bytes used by pallet int bytes = countBytes(palette.size()); - for(int mappedId : palette) { + for (int mappedId : palette) { bytes += countBytes(mappedId); } return bytes; } - private int countBytes(int value) { + private int countBytes(int value) throws Exception { // Count amount of bytes that would be sent if the value were sent as a VarInt ByteBuf buf = Unpooled.buffer(); - PacketUtil.writeVarInt(value, buf); + Type.VAR_INT.write(buf, value); buf.readerIndex(0); int bitCount = buf.readableBytes(); buf.release(); diff --git a/src/main/java/us/myles/ViaVersion/chunks/NibbleArray.java b/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/NibbleArray.java similarity index 86% rename from src/main/java/us/myles/ViaVersion/chunks/NibbleArray.java rename to src/main/java/us/myles/ViaVersion/api/minecraft/chunks/NibbleArray.java index e8dd07565..670f007e8 100644 --- a/src/main/java/us/myles/ViaVersion/chunks/NibbleArray.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/NibbleArray.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.chunks; +package us.myles.ViaVersion.api.minecraft.chunks; import java.util.Arrays; @@ -6,7 +6,7 @@ public class NibbleArray { private final byte[] handle; public NibbleArray(int length) { - if(length == 0 || length % 2 != 0) { + if (length == 0 || length % 2 != 0) { throw new IllegalArgumentException("Length of nibble array must be a positive number dividable by 2!"); } @@ -14,7 +14,7 @@ public class NibbleArray { } public NibbleArray(byte[] handle) { - if(handle.length == 0 || handle.length % 2 != 0) { + if (handle.length == 0 || handle.length % 2 != 0) { throw new IllegalArgumentException("Length of nibble array must be a positive number dividable by 2!"); } @@ -27,7 +27,7 @@ public class NibbleArray { public byte get(int index) { byte value = handle[index / 2]; - if(index % 2 == 0) { + if (index % 2 == 0) { return (byte) (value & 0xF); } else { return (byte) ((value >> 4) & 0xF); @@ -40,7 +40,7 @@ public class NibbleArray { public void set(int index, int value) { index /= 2; - if(index % 2 == 0) { + if (index % 2 == 0) { handle[index] = (byte) (handle[index] & 0xF0 | value & 0xF); } else { handle[index] = (byte) (handle[index] & 0xF | (value & 0xF) << 4); @@ -60,15 +60,15 @@ public class NibbleArray { Arrays.fill(handle, (byte) ((value << 4) | value)); } + public byte[] getHandle() { + return handle; + } + public void setHandle(byte[] handle) { - if(handle.length != this.handle.length) { + if (handle.length != this.handle.length) { throw new IllegalArgumentException("Length of handle must equal to size of nibble array!"); } System.arraycopy(handle, 0, this.handle, 0, handle.length); } - - public byte[] getHandle() { - return handle; - } } diff --git a/src/main/java/us/myles/ViaVersion2/api/item/Item.java b/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java similarity index 86% rename from src/main/java/us/myles/ViaVersion2/api/item/Item.java rename to src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java index ed4abcacd..0f8d20568 100644 --- a/src/main/java/us/myles/ViaVersion2/api/item/Item.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion2.api.item; +package us.myles.ViaVersion.api.minecraft.item; import lombok.AllArgsConstructor; import lombok.Getter; @@ -18,7 +18,7 @@ public class Item { private CompoundTag tag; public static Item getItem(ItemStack stack) { - if(stack == null) return null; + if (stack == null) return null; return new Item((short) stack.getTypeId(), (byte) stack.getAmount(), stack.getDurability(), null); } } diff --git a/src/main/java/us/myles/ViaVersion2/api/metadata/Metadata.java b/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java similarity index 71% rename from src/main/java/us/myles/ViaVersion2/api/metadata/Metadata.java rename to src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java index 7c9559357..adefbd856 100644 --- a/src/main/java/us/myles/ViaVersion2/api/metadata/Metadata.java +++ b/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java @@ -1,9 +1,9 @@ -package us.myles.ViaVersion2.api.metadata; +package us.myles.ViaVersion.api.minecraft.metadata; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; @AllArgsConstructor @Getter diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol/Protocol.java b/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java similarity index 91% rename from src/main/java/us/myles/ViaVersion2/api/protocol/Protocol.java rename to src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index dd0b5cd68..a766a84e2 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol/Protocol.java +++ b/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -1,14 +1,14 @@ -package us.myles.ViaVersion2.api.protocol; +package us.myles.ViaVersion.api.protocol; import lombok.AllArgsConstructor; import lombok.Getter; import us.myles.ViaVersion.CancelException; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.packets.Direction; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.remapper.PacketRemapper; -import us.myles.ViaVersion2.api.util.Pair; +import us.myles.ViaVersion.api.Pair; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol/ProtocolPipeline.java b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java similarity index 91% rename from src/main/java/us/myles/ViaVersion2/api/protocol/ProtocolPipeline.java rename to src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java index 80af7de4f..38864ec6d 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol/ProtocolPipeline.java +++ b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolPipeline.java @@ -1,11 +1,11 @@ -package us.myles.ViaVersion2.api.protocol; +package us.myles.ViaVersion.api.protocol; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.base.BaseProtocol; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.packets.Direction; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol.base.BaseProtocol; -import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol/ProtocolRegistry.java b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java similarity index 85% rename from src/main/java/us/myles/ViaVersion2/api/protocol/ProtocolRegistry.java rename to src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index 4af67c409..6f921c55e 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol/ProtocolRegistry.java +++ b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -1,21 +1,20 @@ -package us.myles.ViaVersion2.api.protocol; +package us.myles.ViaVersion.api.protocol; -import us.myles.ViaVersion2.api.protocol1_9_1to1_9.Protocol1_9_1TO1_9; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; -import us.myles.ViaVersion2.api.util.Pair; +import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.api.Pair; import java.util.*; public class ProtocolRegistry { + public static int SERVER_PROTOCOL = -1; // Input Version -> Output Version & Protocol (Allows fast lookup) private static Map> registryMap = new HashMap<>(); - public static int SERVER_PROTOCOL = -1; - static { // Register built in protocols - registerProtocol(new Protocol1_9TO1_8(), Arrays.asList(ProtocolVersion.V1_9), ProtocolVersion.V1_8); - registerProtocol(new Protocol1_9_1TO1_9(), Arrays.asList(ProtocolVersion.V1_9_1_PRE2), ProtocolVersion.V1_9); + registerProtocol(new Protocol1_9TO1_8(), Collections.singletonList(ProtocolVersion.V1_9), ProtocolVersion.V1_8); + registerProtocol(new Protocol1_9_1TO1_9(), Collections.singletonList(ProtocolVersion.V1_9_1_PRE2), ProtocolVersion.V1_9); } public static void registerProtocol(Protocol protocol, List supported, Integer output) { diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol/ProtocolVersion.java b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java similarity index 85% rename from src/main/java/us/myles/ViaVersion2/api/protocol/ProtocolVersion.java rename to src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index c800db6c1..ab33bf5ff 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol/ProtocolVersion.java +++ b/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion2.api.protocol; +package us.myles.ViaVersion.api.protocol; public class ProtocolVersion { /* Defined protocol constants */ diff --git a/src/main/java/us/myles/ViaVersion2/api/remapper/PacketHandler.java b/src/main/java/us/myles/ViaVersion/api/remapper/PacketHandler.java similarity index 74% rename from src/main/java/us/myles/ViaVersion2/api/remapper/PacketHandler.java rename to src/main/java/us/myles/ViaVersion/api/remapper/PacketHandler.java index 55668cc17..fc2193b15 100644 --- a/src/main/java/us/myles/ViaVersion2/api/remapper/PacketHandler.java +++ b/src/main/java/us/myles/ViaVersion/api/remapper/PacketHandler.java @@ -1,6 +1,6 @@ -package us.myles.ViaVersion2.api.remapper; +package us.myles.ViaVersion.api.remapper; -import us.myles.ViaVersion2.api.PacketWrapper; +import us.myles.ViaVersion.api.PacketWrapper; public abstract class PacketHandler implements ValueWriter { public abstract void handle(PacketWrapper wrapper) throws Exception; diff --git a/src/main/java/us/myles/ViaVersion2/api/remapper/PacketRemapper.java b/src/main/java/us/myles/ViaVersion/api/remapper/PacketRemapper.java similarity index 89% rename from src/main/java/us/myles/ViaVersion2/api/remapper/PacketRemapper.java rename to src/main/java/us/myles/ViaVersion/api/remapper/PacketRemapper.java index 14899b327..314eac1a3 100644 --- a/src/main/java/us/myles/ViaVersion2/api/remapper/PacketRemapper.java +++ b/src/main/java/us/myles/ViaVersion/api/remapper/PacketRemapper.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.remapper; +package us.myles.ViaVersion.api.remapper; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.util.Pair; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.Pair; import java.util.ArrayList; import java.util.List; @@ -41,7 +41,7 @@ public abstract class PacketRemapper { public abstract void registerMap(); - public void remap(PacketWrapper packetWrapper) throws Exception{ + public void remap(PacketWrapper packetWrapper) throws Exception { // Read all the current values for (Pair valueRemapper : valueRemappers) { Object object = valueRemapper.getKey().read(packetWrapper); diff --git a/src/main/java/us/myles/ViaVersion2/api/remapper/TypeRemapper.java b/src/main/java/us/myles/ViaVersion/api/remapper/TypeRemapper.java similarity index 75% rename from src/main/java/us/myles/ViaVersion2/api/remapper/TypeRemapper.java rename to src/main/java/us/myles/ViaVersion/api/remapper/TypeRemapper.java index 8b23117a7..20faf7f52 100644 --- a/src/main/java/us/myles/ViaVersion2/api/remapper/TypeRemapper.java +++ b/src/main/java/us/myles/ViaVersion/api/remapper/TypeRemapper.java @@ -1,7 +1,7 @@ -package us.myles.ViaVersion2.api.remapper; +package us.myles.ViaVersion.api.remapper; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.type.Type; public class TypeRemapper implements ValueReader, ValueWriter { private final Type type; diff --git a/src/main/java/us/myles/ViaVersion2/api/remapper/ValueCreator.java b/src/main/java/us/myles/ViaVersion/api/remapper/ValueCreator.java similarity index 74% rename from src/main/java/us/myles/ViaVersion2/api/remapper/ValueCreator.java rename to src/main/java/us/myles/ViaVersion/api/remapper/ValueCreator.java index 00952ed1a..67da5b65b 100644 --- a/src/main/java/us/myles/ViaVersion2/api/remapper/ValueCreator.java +++ b/src/main/java/us/myles/ViaVersion/api/remapper/ValueCreator.java @@ -1,6 +1,6 @@ -package us.myles.ViaVersion2.api.remapper; +package us.myles.ViaVersion.api.remapper; -import us.myles.ViaVersion2.api.PacketWrapper; +import us.myles.ViaVersion.api.PacketWrapper; public abstract class ValueCreator implements ValueWriter { public abstract void write(PacketWrapper wrapper) throws Exception; diff --git a/src/main/java/us/myles/ViaVersion/api/remapper/ValueReader.java b/src/main/java/us/myles/ViaVersion/api/remapper/ValueReader.java new file mode 100644 index 000000000..e52b9013d --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/api/remapper/ValueReader.java @@ -0,0 +1,7 @@ +package us.myles.ViaVersion.api.remapper; + +import us.myles.ViaVersion.api.PacketWrapper; + +public interface ValueReader { + T read(PacketWrapper wrapper) throws Exception; +} diff --git a/src/main/java/us/myles/ViaVersion2/api/remapper/ValueTransformer.java b/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java similarity index 77% rename from src/main/java/us/myles/ViaVersion2/api/remapper/ValueTransformer.java rename to src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java index cf9eea803..b8fbdea7c 100644 --- a/src/main/java/us/myles/ViaVersion2/api/remapper/ValueTransformer.java +++ b/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java @@ -1,7 +1,7 @@ -package us.myles.ViaVersion2.api.remapper; +package us.myles.ViaVersion.api.remapper; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.type.Type; public abstract class ValueTransformer implements ValueWriter { private final Type outputType; diff --git a/src/main/java/us/myles/ViaVersion/api/remapper/ValueWriter.java b/src/main/java/us/myles/ViaVersion/api/remapper/ValueWriter.java new file mode 100644 index 000000000..961fff775 --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/api/remapper/ValueWriter.java @@ -0,0 +1,7 @@ +package us.myles.ViaVersion.api.remapper; + +import us.myles.ViaVersion.api.PacketWrapper; + +public interface ValueWriter { + void write(PacketWrapper writer, T inputValue) throws Exception; +} diff --git a/src/main/java/us/myles/ViaVersion/api/type/ByteBufReader.java b/src/main/java/us/myles/ViaVersion/api/type/ByteBufReader.java new file mode 100644 index 000000000..3c5ae0d4d --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/api/type/ByteBufReader.java @@ -0,0 +1,7 @@ +package us.myles.ViaVersion.api.type; + +import io.netty.buffer.ByteBuf; + +public interface ByteBufReader { + T read(ByteBuf buffer) throws Exception; +} diff --git a/src/main/java/us/myles/ViaVersion/api/type/ByteBufWriter.java b/src/main/java/us/myles/ViaVersion/api/type/ByteBufWriter.java new file mode 100644 index 000000000..95554ee85 --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/api/type/ByteBufWriter.java @@ -0,0 +1,7 @@ +package us.myles.ViaVersion.api.type; + +import io.netty.buffer.ByteBuf; + +public interface ByteBufWriter { + void write(ByteBuf buffer, T object) throws Exception; +} diff --git a/src/main/java/us/myles/ViaVersion2/api/type/PartialType.java b/src/main/java/us/myles/ViaVersion/api/type/PartialType.java similarity index 62% rename from src/main/java/us/myles/ViaVersion2/api/type/PartialType.java rename to src/main/java/us/myles/ViaVersion/api/type/PartialType.java index 63e6ae540..376134aa3 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/PartialType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/PartialType.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion2.api.type; +package us.myles.ViaVersion.api.type; import io.netty.buffer.ByteBuf; @@ -10,17 +10,17 @@ public abstract class PartialType extends Type { this.param = param; } - public abstract T read(ByteBuf buffer, X param); + public abstract T read(ByteBuf buffer, X param) throws Exception; - public abstract void write(ByteBuf buffer, X param, T object); + public abstract void write(ByteBuf buffer, X param, T object) throws Exception; @Override - public T read(ByteBuf buffer) { + public T read(ByteBuf buffer) throws Exception { return read(buffer, this.param); } @Override - public void write(ByteBuf buffer, T object) { + public void write(ByteBuf buffer, T object) throws Exception { write(buffer, this.param, object); } } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/Type.java b/src/main/java/us/myles/ViaVersion/api/type/Type.java similarity index 93% rename from src/main/java/us/myles/ViaVersion2/api/type/Type.java rename to src/main/java/us/myles/ViaVersion/api/type/Type.java index 2db1b0fe7..3d10ab997 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/Type.java +++ b/src/main/java/us/myles/ViaVersion/api/type/Type.java @@ -1,14 +1,14 @@ -package us.myles.ViaVersion2.api.type; +package us.myles.ViaVersion.api.type; import lombok.Getter; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; import org.spacehq.opennbt.tag.builtin.CompoundTag; -import us.myles.ViaVersion2.api.item.Item; -import us.myles.ViaVersion2.api.type.types.*; -import us.myles.ViaVersion2.api.type.types.minecraft.*; -import us.myles.ViaVersion2.api.util.Position; +import us.myles.ViaVersion.api.minecraft.Position; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.type.types.*; +import us.myles.ViaVersion.api.type.types.minecraft.*; import java.util.UUID; diff --git a/src/main/java/us/myles/ViaVersion/api/type/TypeConverter.java b/src/main/java/us/myles/ViaVersion/api/type/TypeConverter.java new file mode 100644 index 000000000..a255c6615 --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/api/type/TypeConverter.java @@ -0,0 +1,5 @@ +package us.myles.ViaVersion.api.type; + +public interface TypeConverter { + T from(Object o); +} diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/ArrayType.java b/src/main/java/us/myles/ViaVersion/api/type/types/ArrayType.java similarity index 93% rename from src/main/java/us/myles/ViaVersion2/api/type/types/ArrayType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/ArrayType.java index c5a7e961a..fa6401e5f 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/ArrayType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/ArrayType.java @@ -1,7 +1,7 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; import java.lang.reflect.Array; @@ -13,25 +13,6 @@ public class ArrayType extends Type { this.elementType = type; } - @Override - public T[] read(ByteBuf buffer) throws Exception{ - int amount = Type.VAR_INT.read(buffer); - T[] array = (T[]) Array.newInstance(elementType.getOutputClass(), amount); - - for (int i = 0; i < amount; i++) { - array[i] = elementType.read(buffer); - } - return array; - } - - @Override - public void write(ByteBuf buffer, T[] object) throws Exception{ - Type.VAR_INT.write(buffer, object.length); - for (T o : object) { - elementType.write(buffer, o); - } - } - /* Taken from http://stackoverflow.com/questions/4901128/obtaining-the-array-class-of-a-component-type */ public static Class getArrayClass(Class componentType) { ClassLoader classLoader = componentType.getClassLoader(); @@ -65,4 +46,23 @@ public class ArrayType extends Type { return null; // oh } } + + @Override + public T[] read(ByteBuf buffer) throws Exception { + int amount = Type.VAR_INT.read(buffer); + T[] array = (T[]) Array.newInstance(elementType.getOutputClass(), amount); + + for (int i = 0; i < amount; i++) { + array[i] = elementType.read(buffer); + } + return array; + } + + @Override + public void write(ByteBuf buffer, T[] object) throws Exception { + Type.VAR_INT.write(buffer, object.length); + for (T o : object) { + elementType.write(buffer, o); + } + } } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/BooleanType.java b/src/main/java/us/myles/ViaVersion/api/type/types/BooleanType.java similarity index 77% rename from src/main/java/us/myles/ViaVersion2/api/type/types/BooleanType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/BooleanType.java index 17723fb01..b8a6e797d 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/BooleanType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/BooleanType.java @@ -1,10 +1,10 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; -public class BooleanType extends Type implements TypeConverter{ +public class BooleanType extends Type implements TypeConverter { public BooleanType() { super(Boolean.class); } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/ByteType.java b/src/main/java/us/myles/ViaVersion/api/type/types/ByteType.java similarity index 70% rename from src/main/java/us/myles/ViaVersion2/api/type/types/ByteType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/ByteType.java index 1d6971e9e..e4c50d8c6 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/ByteType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/ByteType.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; public class ByteType extends Type implements TypeConverter { public ByteType() { @@ -25,8 +25,8 @@ public class ByteType extends Type implements TypeConverter { if (o instanceof Number) { return ((Number) o).byteValue(); } - if(o instanceof Boolean){ - return ((Boolean)o) == true ? (byte) 1 : 0; + if (o instanceof Boolean) { + return (Boolean) o ? (byte) 1 : 0; } return (Byte) o; } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/DoubleType.java b/src/main/java/us/myles/ViaVersion/api/type/types/DoubleType.java similarity index 69% rename from src/main/java/us/myles/ViaVersion2/api/type/types/DoubleType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/DoubleType.java index e1f05baff..72389c14c 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/DoubleType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/DoubleType.java @@ -1,10 +1,10 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; -public class DoubleType extends Type implements TypeConverter{ +public class DoubleType extends Type implements TypeConverter { public DoubleType() { super(Double.class); } @@ -24,8 +24,8 @@ public class DoubleType extends Type implements TypeConverter{ if (o instanceof Number) { return ((Number) o).doubleValue(); } - if(o instanceof Boolean){ - return ((Boolean)o) == true ? 1D : 0D; + if (o instanceof Boolean) { + return (Boolean) o ? (byte) 1D : 0D; } return (Double) o; } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/FloatType.java b/src/main/java/us/myles/ViaVersion/api/type/types/FloatType.java similarity index 69% rename from src/main/java/us/myles/ViaVersion2/api/type/types/FloatType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/FloatType.java index b1319ab96..15f0c7044 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/FloatType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/FloatType.java @@ -1,10 +1,10 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; -public class FloatType extends Type implements TypeConverter{ +public class FloatType extends Type implements TypeConverter { public FloatType() { super(Float.class); } @@ -25,8 +25,8 @@ public class FloatType extends Type implements TypeConverter{ if (o instanceof Number) { return ((Number) o).floatValue(); } - if(o instanceof Boolean){ - return ((Boolean)o) == true ? 1F : 0; + if (o instanceof Boolean) { + return ((Boolean) o) ? 1F : 0; } return (Float) o; } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/IntType.java b/src/main/java/us/myles/ViaVersion/api/type/types/IntType.java similarity index 69% rename from src/main/java/us/myles/ViaVersion2/api/type/types/IntType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/IntType.java index 73a91326c..6f9b5317a 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/IntType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/IntType.java @@ -1,10 +1,10 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; -public class IntType extends Type implements TypeConverter{ +public class IntType extends Type implements TypeConverter { public IntType() { super(Integer.class); } @@ -24,8 +24,8 @@ public class IntType extends Type implements TypeConverter{ if (o instanceof Number) { return ((Number) o).intValue(); } - if(o instanceof Boolean){ - return ((Boolean)o) == true ? 1 : 0; + if (o instanceof Boolean) { + return ((Boolean) o) ? 1 : 0; } return (Integer) o; } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/LongType.java b/src/main/java/us/myles/ViaVersion/api/type/types/LongType.java similarity index 71% rename from src/main/java/us/myles/ViaVersion2/api/type/types/LongType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/LongType.java index f0129a140..f2712efb9 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/LongType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/LongType.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; public class LongType extends Type implements TypeConverter { public LongType() { @@ -25,8 +25,8 @@ public class LongType extends Type implements TypeConverter { if (o instanceof Number) { return ((Number) o).longValue(); } - if(o instanceof Boolean){ - return ((Boolean)o) == true ? 1L : 0; + if (o instanceof Boolean) { + return ((Boolean) o) ? 1L : 0; } return (Long) o; } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/RemainingBytesType.java b/src/main/java/us/myles/ViaVersion/api/type/types/RemainingBytesType.java similarity index 83% rename from src/main/java/us/myles/ViaVersion2/api/type/types/RemainingBytesType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/RemainingBytesType.java index 9c5ae6e1e..4d8e68ed4 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/RemainingBytesType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/RemainingBytesType.java @@ -1,7 +1,7 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; public class RemainingBytesType extends Type { public RemainingBytesType() { diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/ShortType.java b/src/main/java/us/myles/ViaVersion/api/type/types/ShortType.java similarity index 70% rename from src/main/java/us/myles/ViaVersion2/api/type/types/ShortType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/ShortType.java index e50704c4c..f4896a790 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/ShortType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/ShortType.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; public class ShortType extends Type implements TypeConverter { public ShortType() { @@ -24,8 +24,8 @@ public class ShortType extends Type implements TypeConverter { if (o instanceof Number) { return ((Number) o).shortValue(); } - if(o instanceof Boolean){ - return ((Boolean)o) == true ? (short) 1 : 0; + if (o instanceof Boolean) { + return ((Boolean) o) ? (short) 1 : 0; } return (short) o; } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/StringType.java b/src/main/java/us/myles/ViaVersion/api/type/types/StringType.java similarity index 91% rename from src/main/java/us/myles/ViaVersion2/api/type/types/StringType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/StringType.java index a4eede755..497d3fd34 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/StringType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/StringType.java @@ -1,9 +1,9 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; public class StringType extends Type { public StringType() { diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/UUIDType.java b/src/main/java/us/myles/ViaVersion/api/type/types/UUIDType.java similarity index 84% rename from src/main/java/us/myles/ViaVersion2/api/type/types/UUIDType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/UUIDType.java index 7cb6c1a66..41badf7ac 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/UUIDType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/UUIDType.java @@ -1,7 +1,7 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; import java.util.UUID; diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/UnsignedByteType.java b/src/main/java/us/myles/ViaVersion/api/type/types/UnsignedByteType.java similarity index 71% rename from src/main/java/us/myles/ViaVersion2/api/type/types/UnsignedByteType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/UnsignedByteType.java index a5e8ff02b..7c293b362 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/UnsignedByteType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/UnsignedByteType.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; public class UnsignedByteType extends Type implements TypeConverter { public UnsignedByteType() { @@ -24,8 +24,8 @@ public class UnsignedByteType extends Type implements TypeConverter implements TypeConverter { public UnsignedShortType() { @@ -24,8 +24,8 @@ public class UnsignedShortType extends Type implements TypeConverter implements TypeConverter { @@ -58,7 +58,7 @@ public class VarIntType extends Type implements TypeConverter return ((Number) o).intValue(); } if (o instanceof Boolean) { - return ((Boolean) o) == true ? 1 : 0; + return ((Boolean) o) ? 1 : 0; } return (Integer) o; } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/VoidType.java b/src/main/java/us/myles/ViaVersion/api/type/types/VoidType.java similarity index 72% rename from src/main/java/us/myles/ViaVersion2/api/type/types/VoidType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/VoidType.java index 9a154cd2e..5a475a49f 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/VoidType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/VoidType.java @@ -1,10 +1,10 @@ -package us.myles.ViaVersion2.api.type.types; +package us.myles.ViaVersion.api.type.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.type.TypeConverter; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.api.type.TypeConverter; -public class VoidType extends Type implements TypeConverter{ +public class VoidType extends Type implements TypeConverter { public VoidType() { super(Void.class); } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/EulerAngleType.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/EulerAngleType.java similarity index 84% rename from src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/EulerAngleType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/minecraft/EulerAngleType.java index 566931fe6..5d324dd62 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/EulerAngleType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/EulerAngleType.java @@ -1,9 +1,8 @@ -package us.myles.ViaVersion2.api.type.types.minecraft; +package us.myles.ViaVersion.api.type.types.minecraft; import io.netty.buffer.ByteBuf; import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; public class EulerAngleType extends Type { public EulerAngleType() { diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/ItemArrayType.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/ItemArrayType.java similarity index 82% rename from src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/ItemArrayType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/minecraft/ItemArrayType.java index b5980eadb..bc7e93f8a 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/ItemArrayType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/ItemArrayType.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.type.types.minecraft; +package us.myles.ViaVersion.api.type.types.minecraft; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.item.Item; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.type.Type; public class ItemArrayType extends Type { diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/ItemType.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/ItemType.java similarity index 86% rename from src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/ItemType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/minecraft/ItemType.java index 402766e7a..89b6e9412 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/ItemType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/ItemType.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.type.types.minecraft; +package us.myles.ViaVersion.api.type.types.minecraft; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.item.Item; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.type.Type; public class ItemType extends Type { public ItemType() { diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/NBTType.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/NBTType.java similarity index 84% rename from src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/NBTType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/minecraft/NBTType.java index c7067aa58..862e26b21 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/NBTType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/NBTType.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion2.api.type.types.minecraft; +package us.myles.ViaVersion.api.type.types.minecraft; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; @@ -6,7 +6,7 @@ import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufOutputStream; import org.spacehq.opennbt.NBTIO; import org.spacehq.opennbt.tag.builtin.CompoundTag; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -27,11 +27,8 @@ public class NBTType extends Type { } else { buffer.readerIndex(readerIndex); ByteBufInputStream bytebufStream = new ByteBufInputStream(buffer); - DataInputStream dataInputStream = new DataInputStream(bytebufStream); - try { + try (DataInputStream dataInputStream = new DataInputStream(bytebufStream)) { return (CompoundTag) NBTIO.readTag(dataInputStream); - } finally { - dataInputStream.close(); } } } diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/OptUUIDType.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/OptUUIDType.java similarity index 76% rename from src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/OptUUIDType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/minecraft/OptUUIDType.java index 3c40be4cb..441fae93b 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/OptUUIDType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/OptUUIDType.java @@ -1,7 +1,7 @@ -package us.myles.ViaVersion2.api.type.types.minecraft; +package us.myles.ViaVersion.api.type.types.minecraft; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; import java.util.UUID; @@ -13,16 +13,15 @@ public class OptUUIDType extends Type { @Override public UUID read(ByteBuf buffer) { boolean present = buffer.readBoolean(); - if(!present) return null; + if (!present) return null; return new UUID(buffer.readLong(), buffer.readLong()); } @Override public void write(ByteBuf buffer, UUID object) { - if(object == null){ + if (object == null) { buffer.writeBoolean(false); - return; - }else{ + } else { buffer.writeBoolean(true); buffer.writeLong(object.getMostSignificantBits()); buffer.writeLong(object.getLeastSignificantBits()); diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/PositionType.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/PositionType.java similarity index 82% rename from src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/PositionType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/minecraft/PositionType.java index 51892c8c1..6079982be 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/PositionType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/PositionType.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.type.types.minecraft; +package us.myles.ViaVersion.api.type.types.minecraft; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.util.Position; +import us.myles.ViaVersion.api.minecraft.Position; +import us.myles.ViaVersion.api.type.Type; public class PositionType extends Type { public PositionType() { diff --git a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/VectorType.java b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/VectorType.java similarity index 87% rename from src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/VectorType.java rename to src/main/java/us/myles/ViaVersion/api/type/types/minecraft/VectorType.java index bdb5716e7..968e4413e 100644 --- a/src/main/java/us/myles/ViaVersion2/api/type/types/minecraft/VectorType.java +++ b/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/VectorType.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.type.types.minecraft; +package us.myles.ViaVersion.api.type.types.minecraft; import io.netty.buffer.ByteBuf; import org.bukkit.util.Vector; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; public class VectorType extends Type { public VectorType() { diff --git a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java index 236a85db9..50cbbd93a 100644 --- a/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java +++ b/src/main/java/us/myles/ViaVersion/boss/ViaBossBar.java @@ -11,9 +11,9 @@ import us.myles.ViaVersion.api.boss.BossBar; import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossFlag; import us.myles.ViaVersion.api.boss.BossStyle; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.PacketType; -import us.myles.ViaVersion.util.PacketUtil; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import java.util.*; @@ -152,36 +152,41 @@ public class ViaBossBar implements BossBar { } private ByteBuf getPacket(UpdateAction action) { - ByteBuf buf = Unpooled.buffer(); - PacketUtil.writeVarInt(PacketType.PLAY_BOSS_BAR.getNewPacketID(), buf); - PacketUtil.writeUUID(uuid, buf); - PacketUtil.writeVarInt(action.getId(), buf); - switch (action) { - case ADD: - PacketUtil.writeString(fixJson(title), buf); - buf.writeFloat(health); - PacketUtil.writeVarInt(color.getId(), buf); - PacketUtil.writeVarInt(style.getId(), buf); - buf.writeByte(flagToBytes()); - break; - case REMOVE: - break; - case UPDATE_HEALTH: - buf.writeFloat(health); - break; - case UPDATE_TITLE: - PacketUtil.writeString(fixJson(title), buf); - break; - case UPDATE_STYLE: - PacketUtil.writeVarInt(color.getId(), buf); - PacketUtil.writeVarInt(style.getId(), buf); - break; - case UPDATE_FLAGS: - buf.writeByte(flagToBytes()); - break; - } + try { + ByteBuf buf = Unpooled.buffer(); + Type.VAR_INT.write(buf, 0x0C); // Boss bar packet + Type.UUID.write(buf, uuid); + Type.VAR_INT.write(buf, action.getId()); + switch (action) { + case ADD: + Type.STRING.write(buf, fixJson(title)); + buf.writeFloat(health); + Type.VAR_INT.write(buf, color.getId()); + Type.VAR_INT.write(buf, style.getId()); + buf.writeByte(flagToBytes()); + break; + case REMOVE: + break; + case UPDATE_HEALTH: + buf.writeFloat(health); + break; + case UPDATE_TITLE: + Type.STRING.write(buf, fixJson(title)); + break; + case UPDATE_STYLE: + Type.VAR_INT.write(buf, color.getId()); + Type.VAR_INT.write(buf, style.getId()); + break; + case UPDATE_FLAGS: + buf.writeByte(flagToBytes()); + break; + } - return buf; + return buf; + } catch (Exception e) { + e.printStackTrace(); + } + return null; } private int flagToBytes() { diff --git a/src/main/java/us/myles/ViaVersion/commands/ViaVersionCommand.java b/src/main/java/us/myles/ViaVersion/commands/ViaVersionCommand.java index 43b29f2a1..ce426e474 100644 --- a/src/main/java/us/myles/ViaVersion/commands/ViaVersionCommand.java +++ b/src/main/java/us/myles/ViaVersion/commands/ViaVersionCommand.java @@ -12,9 +12,6 @@ import us.myles.ViaVersion.api.ViaVersion; import java.util.ArrayList; import java.util.List; -/** - * Created by fillefilip8 on 2016-03-03. - */ @RequiredArgsConstructor public class ViaVersionCommand implements CommandExecutor { @@ -62,7 +59,7 @@ public class ViaVersionCommand implements CommandExecutor { return false; } - public void sendHelp(CommandSender sender){ + public void sendHelp(CommandSender sender) { sender.sendMessage(color("&aViaVersion &c" + ViaVersion.getInstance().getVersion())); sender.sendMessage(color("&6Commands:")); sender.sendMessage(color("&2/viaversion list &7- &6Shows lists of all 1.9 clients and 1.8 clients.")); diff --git a/src/main/java/us/myles/ViaVersion/handlers/ViaChunkHandler.java b/src/main/java/us/myles/ViaVersion/handlers/ViaChunkHandler.java index 792254870..e0d9a5dd8 100644 --- a/src/main/java/us/myles/ViaVersion/handlers/ViaChunkHandler.java +++ b/src/main/java/us/myles/ViaVersion/handlers/ViaChunkHandler.java @@ -3,8 +3,8 @@ package us.myles.ViaVersion.handlers; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageEncoder; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.ClientChunks; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks; import java.util.List; @@ -23,7 +23,7 @@ public class ViaChunkHandler extends MessageToMessageEncoder { if (!(o instanceof ByteBuf)) { info.setLastPacket(o); /* This transformer is more for fixing issues which we find hard at packet level :) */ - if(o.getClass().getName().endsWith("PacketPlayOutMapChunkBulk") && info.isActive()) { + if (o.getClass().getName().endsWith("PacketPlayOutMapChunkBulk") && info.isActive()) { list.addAll(info.get(ClientChunks.class).transformMapChunkBulk(o)); return; } diff --git a/src/main/java/us/myles/ViaVersion/handlers/ViaDecodeHandler.java b/src/main/java/us/myles/ViaVersion/handlers/ViaDecodeHandler.java index 841ebb530..3381b2fd2 100644 --- a/src/main/java/us/myles/ViaVersion/handlers/ViaDecodeHandler.java +++ b/src/main/java/us/myles/ViaVersion/handlers/ViaDecodeHandler.java @@ -4,11 +4,12 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; import us.myles.ViaVersion.CancelException; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.Direction; -import us.myles.ViaVersion.util.PacketUtil; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo; +import us.myles.ViaVersion.util.PipelineUtil; import java.lang.reflect.InvocationTargetException; import java.util.List; @@ -28,7 +29,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder { // use transformers if (bytebuf.readableBytes() > 0) { if (info.isActive()) { - int id = PacketUtil.readVarInt(bytebuf); + int id = Type.VAR_INT.read(bytebuf); // Transform try { @@ -47,7 +48,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder { } // call minecraft decoder try { - list.addAll(PacketUtil.callDecode(this.minecraftDecoder, ctx, bytebuf)); + list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, bytebuf)); } catch (InvocationTargetException e) { if (e.getCause() instanceof Exception) { throw (Exception) e.getCause(); @@ -58,7 +59,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (PacketUtil.containsCause(cause, CancelException.class)) return; + if (PipelineUtil.containsCause(cause, CancelException.class)) return; super.exceptionCaught(ctx, cause); } } diff --git a/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java b/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java index d54c625f5..4fdb89821 100644 --- a/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java +++ b/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java @@ -4,11 +4,12 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; import us.myles.ViaVersion.CancelException; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.Direction; -import us.myles.ViaVersion.util.PacketUtil; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo; +import us.myles.ViaVersion.util.PipelineUtil; import java.lang.reflect.InvocationTargetException; @@ -28,7 +29,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder { if (!(o instanceof ByteBuf)) { // call minecraft encoder try { - PacketUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf); + PipelineUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf); } catch (InvocationTargetException e) { if (e.getCause() instanceof Exception) { throw (Exception) e.getCause(); @@ -39,7 +40,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder { throw new CancelException(); } if (info.isActive()) { - int id = PacketUtil.readVarInt(bytebuf); + int id = Type.VAR_INT.read(bytebuf); // Transform ByteBuf oldPacket = bytebuf.copy(); bytebuf.clear(); @@ -59,7 +60,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (PacketUtil.containsCause(cause, CancelException.class)) return; + if (PipelineUtil.containsCause(cause, CancelException.class)) return; super.exceptionCaught(ctx, cause); } } diff --git a/src/main/java/us/myles/ViaVersion/handlers/ViaVersionInitializer.java b/src/main/java/us/myles/ViaVersion/handlers/ViaVersionInitializer.java index 07cd426a9..837d7d67d 100644 --- a/src/main/java/us/myles/ViaVersion/handlers/ViaVersionInitializer.java +++ b/src/main/java/us/myles/ViaVersion/handlers/ViaVersionInitializer.java @@ -5,8 +5,8 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.MessageToByteEncoder; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol.ProtocolPipeline; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import java.lang.reflect.Method; diff --git a/src/main/java/us/myles/ViaVersion/packets/PacketType.java b/src/main/java/us/myles/ViaVersion/packets/PacketType.java index 7fa7d8ac0..43bb5cf0c 100644 --- a/src/main/java/us/myles/ViaVersion/packets/PacketType.java +++ b/src/main/java/us/myles/ViaVersion/packets/PacketType.java @@ -2,9 +2,7 @@ package us.myles.ViaVersion.packets; import java.util.HashMap; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.Table; - +@Deprecated public enum PacketType { /* Handshake serverbound */ HANDSHAKE(State.HANDSHAKE, Direction.INCOMING, 0x00), // Mapped @@ -138,9 +136,19 @@ public enum PacketType { PLAY_ENTITY_PROPERTIES(State.PLAY, Direction.OUTGOING, 0x20, 0x4B), // Mapped PLAY_ENTITY_EFFECT(State.PLAY, Direction.OUTGOING, 0x1D, 0x4C), // Mapped - PLAY_MAP_CHUNK_BULK(State.PLAY, Direction.OUTGOING, 0x26, -1), // TODO? - PLAY_SET_COMPRESSION(State.PLAY, Direction.OUTGOING, 0x46, -1), // TODO? - PLAY_UPDATE_ENTITY_NBT(State.PLAY, Direction.OUTGOING, 0x49, -1),; // TODO? + PLAY_MAP_CHUNK_BULK(State.PLAY, Direction.OUTGOING, 0x26, -1), + PLAY_SET_COMPRESSION(State.PLAY, Direction.OUTGOING, 0x46, -1), + PLAY_UPDATE_ENTITY_NBT(State.PLAY, Direction.OUTGOING, 0x49, -1); + + private static HashMap oldids = new HashMap<>(); + private static HashMap newids = new HashMap<>(); + + static { + for (PacketType pt : PacketType.values()) { + oldids.put(toShort((short) pt.getPacketID(), (short) pt.getDirection().ordinal(), (short) pt.getState().ordinal()), pt); + newids.put(toShort((short) pt.getNewPacketID(), (short) pt.getDirection().ordinal(), (short) pt.getState().ordinal()), pt); + } + } private State state; private Direction direction; @@ -161,6 +169,26 @@ public enum PacketType { this.newPacketID = newPacketID; } + public static PacketType findNewPacket(State state, Direction direction, int id) { + return newids.get(toShort((short) id, (short) direction.ordinal(), (short) state.ordinal())); + } + + public static PacketType findOldPacket(State state, Direction direction, int id) { + return oldids.get(toShort((short) id, (short) direction.ordinal(), (short) state.ordinal())); + } + + public static PacketType getIncomingPacket(State state, int id) { + return findNewPacket(state, Direction.INCOMING, id); + } + + public static PacketType getOutgoingPacket(State state, int id) { + return findOldPacket(state, Direction.OUTGOING, id); + } + + private static short toShort(short id, short direction, short state) { + return (short) ((id & 0x00FF) | (direction << 8) & 0x0F00 | (state << 12) & 0xF000); + } + public State getState() { return state; } @@ -177,33 +205,4 @@ public enum PacketType { return newPacketID; } - public static PacketType findNewPacket(State state, Direction direction, int id) { - return newids.get(toShort((short) id, (short)direction.ordinal(), (short) state.ordinal())); - } - - public static PacketType findOldPacket(State state, Direction direction, int id) { - return oldids.get(toShort((short) id, (short)direction.ordinal(), (short) state.ordinal())); - } - - public static PacketType getIncomingPacket(State state, int id) { - return findNewPacket(state, Direction.INCOMING, id); - } - - public static PacketType getOutgoingPacket(State state, int id) { - return findOldPacket(state, Direction.OUTGOING, id); - } - - private static short toShort(short id, short direction, short state) { - return (short) ((id & 0x00FF) | (direction<<8) & 0x0F00 | (state << 12) & 0xF000); - } - - private static HashMap oldids = new HashMap(); - private static HashMap newids = new HashMap(); - static { - for(PacketType pt : PacketType.values()) { - oldids.put(toShort((short) pt.getPacketID(), (short)pt.getDirection().ordinal(), (short)pt.getState().ordinal()), pt); - newids.put(toShort((short) pt.getNewPacketID(), (short)pt.getDirection().ordinal(), (short)pt.getState().ordinal()), pt); - } - } - } diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol/base/BaseProtocol.java b/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java similarity index 92% rename from src/main/java/us/myles/ViaVersion2/api/protocol/base/BaseProtocol.java rename to src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java index e43e9b2cf..db1118474 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol/base/BaseProtocol.java +++ b/src/main/java/us/myles/ViaVersion/protocols/base/BaseProtocol.java @@ -1,20 +1,20 @@ -package us.myles.ViaVersion2.api.protocol.base; +package us.myles.ViaVersion.protocols.base; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import us.myles.ViaVersion.ViaVersionPlugin; +import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.ViaVersion; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.protocol.ProtocolPipeline; +import us.myles.ViaVersion.api.protocol.ProtocolRegistry; +import us.myles.ViaVersion.api.remapper.PacketHandler; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol.Protocol; -import us.myles.ViaVersion2.api.protocol.ProtocolPipeline; -import us.myles.ViaVersion2.api.protocol.ProtocolRegistry; -import us.myles.ViaVersion2.api.remapper.PacketHandler; -import us.myles.ViaVersion2.api.remapper.PacketRemapper; -import us.myles.ViaVersion2.api.type.Type; -import us.myles.ViaVersion2.api.util.Pair; +import us.myles.ViaVersion.api.Pair; import java.util.List; import java.util.UUID; diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol/base/ProtocolInfo.java b/src/main/java/us/myles/ViaVersion/protocols/base/ProtocolInfo.java similarity index 59% rename from src/main/java/us/myles/ViaVersion2/api/protocol/base/ProtocolInfo.java rename to src/main/java/us/myles/ViaVersion/protocols/base/ProtocolInfo.java index 6789a4a69..6e1a05645 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol/base/ProtocolInfo.java +++ b/src/main/java/us/myles/ViaVersion/protocols/base/ProtocolInfo.java @@ -1,17 +1,17 @@ -package us.myles.ViaVersion2.api.protocol.base; +package us.myles.ViaVersion.protocols.base; import lombok.Getter; import lombok.Setter; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion2.api.data.StoredObject; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol.ProtocolPipeline; import java.util.UUID; @Getter @Setter -public class ProtocolInfo extends StoredObject{ +public class ProtocolInfo extends StoredObject { private State state = State.HANDSHAKE; private int protocolVersion = -1; private String username; diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9_1to1_9/Protocol1_9_1TO1_9.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1to1_9/Protocol1_9_1TO1_9.java similarity index 73% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9_1to1_9/Protocol1_9_1TO1_9.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1to1_9/Protocol1_9_1TO1_9.java index 7452435f4..da366152c 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9_1to1_9/Protocol1_9_1TO1_9.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1to1_9/Protocol1_9_1TO1_9.java @@ -1,12 +1,12 @@ -package us.myles.ViaVersion2.api.protocol1_9_1to1_9; +package us.myles.ViaVersion.protocols.protocol1_9_1to1_9; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.protocol.Protocol; -import us.myles.ViaVersion2.api.remapper.PacketRemapper; -import us.myles.ViaVersion2.api.type.Type; -public class Protocol1_9_1TO1_9 extends Protocol{ +public class Protocol1_9_1TO1_9 extends Protocol { @Override protected void registerPackets() { // Currently supports 1.9.1 PRE 2 diff --git a/src/main/java/us/myles/ViaVersion/armor/ArmorType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ArmorType.java similarity index 86% rename from src/main/java/us/myles/ViaVersion/armor/ArmorType.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ArmorType.java index 3069d3784..146ae91f0 100644 --- a/src/main/java/us/myles/ViaVersion/armor/ArmorType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ArmorType.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.armor; +package us.myles.ViaVersion.protocols.protocol1_9to1_8; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -36,8 +36,8 @@ public enum ArmorType { private final Material type; public static ArmorType findByType(Material type) { - for(ArmorType a : ArmorType.values()) - if(a.getType() == type) + for (ArmorType a : ArmorType.values()) + if (a.getType() == type) return a; return ArmorType.NONE; } @@ -52,15 +52,15 @@ public enum ArmorType { } public static ArmorType findById(int id) { - for(ArmorType a : ArmorType.values()) - if(a.getId() == id) + for (ArmorType a : ArmorType.values()) + if (a.getId() == id) return a; return ArmorType.NONE; } - public static boolean isArmor(Material material){ - for(ArmorType a : ArmorType.values()) - if(a.getType() == material) + public static boolean isArmor(Material material) { + for (ArmorType a : ArmorType.values()) + if (a.getType() == material) return true; return false; } diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/ItemRewriter.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java similarity index 98% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/ItemRewriter.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java index 5394f3b51..1d059ecb8 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/ItemRewriter.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/ItemRewriter.java @@ -1,11 +1,11 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8; +package us.myles.ViaVersion.protocols.protocol1_9to1_8; import org.bukkit.Material; import org.spacehq.opennbt.tag.builtin.CompoundTag; import org.spacehq.opennbt.tag.builtin.ListTag; import org.spacehq.opennbt.tag.builtin.StringTag; import org.spacehq.opennbt.tag.builtin.Tag; -import us.myles.ViaVersion2.api.item.Item; +import us.myles.ViaVersion.api.minecraft.item.Item; import java.util.Collections; import java.util.HashMap; diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/PlayerMovementMapper.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/PlayerMovementMapper.java similarity index 54% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/PlayerMovementMapper.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/PlayerMovementMapper.java index ad8e8069a..2f5b4f1ad 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/PlayerMovementMapper.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/PlayerMovementMapper.java @@ -1,9 +1,9 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8; +package us.myles.ViaVersion.protocols.protocol1_9to1_8; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.MovementTracker; -import us.myles.ViaVersion2.api.remapper.PacketHandler; -import us.myles.ViaVersion2.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.remapper.PacketHandler; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; public class PlayerMovementMapper extends PacketRemapper { @Override diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/Protocol1_9TO1_8.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java similarity index 77% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/Protocol1_9TO1_8.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java index ee48bda6b..751e7d6aa 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/Protocol1_9TO1_8.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java @@ -1,27 +1,25 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8; +package us.myles.ViaVersion.protocols.protocol1_9to1_8; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import org.bukkit.Bukkit; import org.bukkit.inventory.ItemStack; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; +import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.ViaVersion; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.metadata.Metadata; -import us.myles.ViaVersion2.api.protocol.Protocol; -import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo; -import us.myles.ViaVersion2.api.protocol1_9to1_8.packets.*; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.ClientChunks; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.InventoryTracker; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.MovementTracker; -import us.myles.ViaVersion2.api.protocol1_9to1_8.types.MetadataListType; -import us.myles.ViaVersion2.api.protocol1_9to1_8.types.MetadataType; -import us.myles.ViaVersion2.api.remapper.ValueTransformer; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.api.remapper.ValueTransformer; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.InventoryTracker; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.MetadataListType; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.MetadataType; import java.util.List; import java.util.UUID; @@ -29,11 +27,9 @@ import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; public class Protocol1_9TO1_8 extends Protocol { - private static Gson gson = new GsonBuilder().create(); - public static Type> METADATA_LIST = new MetadataListType(); public static Type METADATA = new MetadataType(); - + private static Gson gson = new GsonBuilder().create(); public static ValueTransformer FIX_JSON = new ValueTransformer(Type.STRING) { @Override public String transform(PacketWrapper wrapper, String line) { @@ -41,27 +37,6 @@ public class Protocol1_9TO1_8 extends Protocol { } }; - @Override - protected void registerPackets() { - SpawnPackets.register(this); - InventoryPackets.register(this); - EntityPackets.register(this); - PlayerPackets.register(this); - WorldPackets.register(this); - } - - @Override - public void init(UserConnection userConnection) { - // Entity tracker - userConnection.put(new EntityTracker(userConnection)); - // Chunk tracker - userConnection.put(new ClientChunks(userConnection)); - // Movement tracker - userConnection.put(new MovementTracker(userConnection)); - // Inventory tracker - userConnection.put(new InventoryTracker(userConnection)); - } - public static String fixJson(String line) { if (line == null || line.equalsIgnoreCase("null")) { line = "{\"text\":\"\"}"; @@ -103,4 +78,25 @@ public class Protocol1_9TO1_8 extends Protocol { return null; } } + + @Override + protected void registerPackets() { + SpawnPackets.register(this); + InventoryPackets.register(this); + EntityPackets.register(this); + PlayerPackets.register(this); + WorldPackets.register(this); + } + + @Override + public void init(UserConnection userConnection) { + // Entity tracker + userConnection.put(new EntityTracker(userConnection)); + // Chunk tracker + userConnection.put(new ClientChunks(userConnection)); + // Movement tracker + userConnection.put(new MovementTracker(userConnection)); + // Inventory tracker + userConnection.put(new InventoryTracker(userConnection)); + } } diff --git a/src/main/java/us/myles/ViaVersion/armor/ArmorListener.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/ArmorListener.java similarity index 72% rename from src/main/java/us/myles/ViaVersion/armor/ArmorListener.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/ArmorListener.java index 9c882de69..3352122a6 100644 --- a/src/main/java/us/myles/ViaVersion/armor/ArmorListener.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/ArmorListener.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.armor; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -18,12 +18,15 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.inventory.CraftingInventory; import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.api.ViaVersion; -import us.myles.ViaVersion.packets.PacketType; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import java.util.UUID; -import static us.myles.ViaVersion.util.PacketUtil.*; - @RequiredArgsConstructor public class ArmorListener implements Listener { @@ -31,20 +34,27 @@ public class ArmorListener implements Listener { private final ViaVersionPlugin plugin; public static void sendArmorUpdate(Player player) { + // Ensure that the player is on our pipe + UserConnection userConnection = ((ViaVersionPlugin)ViaVersion.getInstance()).getConnection(player); + if(userConnection == null) return; + if(!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return; + int armor = ArmorType.calculateArmorPoints(player.getInventory().getArmorContents()); + try { + ByteBuf buf = Unpooled.buffer(); + Type.VAR_INT.write(buf, 0x4B); // Entity Properties + Type.VAR_INT.write(buf, player.getEntityId()); + buf.writeInt(1); // only 1 property + Type.STRING.write(buf, "generic.armor"); + buf.writeDouble(0); //default 0 armor + Type.VAR_INT.write(buf, 1); // 1 modifier + Type.UUID.write(buf, ARMOR_ATTRIBUTE); // armor modifier uuid + buf.writeDouble((double) armor); // the modifier value + buf.writeByte(0); // the modifier operation, 0 is add number - ByteBuf buf = Unpooled.buffer(); - writeVarInt(PacketType.PLAY_ENTITY_PROPERTIES.getNewPacketID(), buf); - writeVarInt(player.getEntityId(), buf); - buf.writeInt(1); // only 1 property - writeString("generic.armor", buf); - buf.writeDouble(0); //default 0 armor - writeVarInt(1, buf); // 1 modifier - writeUUID(ARMOR_ATTRIBUTE, buf); // armor modifier uuid - buf.writeDouble((double) armor); // the modifier value - buf.writeByte(0); // the modifier operation, 0 is add number - - ViaVersion.getInstance().sendRawPacket(player, buf); + ViaVersion.getInstance().sendRawPacket(player, buf); + } catch (Exception ignored) { + } } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) diff --git a/src/main/java/us/myles/ViaVersion/listeners/CommandBlockListener.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/CommandBlockListener.java similarity index 71% rename from src/main/java/us/myles/ViaVersion/listeners/CommandBlockListener.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/CommandBlockListener.java index 8149248f2..7517be1c1 100644 --- a/src/main/java/us/myles/ViaVersion/listeners/CommandBlockListener.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/listeners/CommandBlockListener.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.listeners; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; @@ -19,8 +19,13 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.spacehq.opennbt.tag.builtin.ByteTag; import org.spacehq.opennbt.tag.builtin.CompoundTag; import us.myles.ViaVersion.ViaVersionPlugin; -import us.myles.ViaVersion.packets.PacketType; -import us.myles.ViaVersion.util.PacketUtil; +import us.myles.ViaVersion.api.ViaVersion; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.minecraft.Position; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.util.ReflectionUtil; import java.io.DataOutput; @@ -55,6 +60,11 @@ public class CommandBlockListener implements Listener { @EventHandler(ignoreCancelled = true) public void onInteract(PlayerInteractEvent e) { if (e.getAction() == Action.RIGHT_CLICK_BLOCK && plugin.isPorted(e.getPlayer()) && e.getPlayer().isOp()) { + // Ensure that the player is on our pipe + UserConnection userConnection = ((ViaVersionPlugin)ViaVersion.getInstance()).getConnection(e.getPlayer()); + if(userConnection == null) return; + if(!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return; + try { sendCommandBlockPacket(e.getClickedBlock(), e.getPlayer()); } catch (Exception ex) { @@ -65,11 +75,19 @@ public class CommandBlockListener implements Listener { private void sendOp(Player p) { if (p.isOp() && plugin.isPorted(p)) { - ByteBuf buf = Unpooled.buffer(); - PacketUtil.writeVarInt(PacketType.PLAY_ENTITY_STATUS.getNewPacketID(), buf); - buf.writeInt(p.getEntityId()); - buf.writeByte(26); - plugin.sendRawPacket(p, buf); + // Ensure that the player is on our pipe + UserConnection userConnection = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(p); + if(userConnection == null) return; + if(!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return; + + try { + ByteBuf buf = Unpooled.buffer(); + Type.VAR_INT.write(buf, 0x1B); // Entity Status + buf.writeInt(p.getEntityId()); + buf.writeByte(26); + plugin.sendRawPacket(p, buf); + } catch (Exception ignored) { + } } } @@ -86,9 +104,9 @@ public class CommandBlockListener implements Listener { private ByteBuf packetToByteBuf(Object updatePacket) throws Exception { ByteBuf buf = Unpooled.buffer(); - PacketUtil.writeVarInt(PacketType.PLAY_UPDATE_BLOCK_ENTITY.getNewPacketID(), buf); //Packet ID + Type.VAR_INT.write(buf, 0x09); //Block Entity Packet ID long[] pos = getPosition(ReflectionUtil.get(updatePacket, "a", ReflectionUtil.nms("BlockPosition"))); - PacketUtil.writeBlockPosition(buf, pos[0], pos[1], pos[2]); //Block position + Type.POSITION.write(buf, new Position(pos[0], pos[1], pos[2])); //Block position buf.writeByte(2); //Action id always 2 CompoundTag nbt = getNBT(ReflectionUtil.get(updatePacket, "c", ReflectionUtil.nms("NBTTagCompound"))); if (nbt == null) { @@ -98,7 +116,7 @@ public class CommandBlockListener implements Listener { nbt.put(new ByteTag("powered", (byte) 0)); nbt.put(new ByteTag("auto", (byte) 0)); nbt.put(new ByteTag("conditionMet", (byte) 0)); - PacketUtil.writeNBT(buf, nbt); //NBT tag + Type.NBT.write(buf, nbt); //NBT tag return buf; } @@ -115,7 +133,7 @@ public class CommandBlockListener implements Listener { Method m = ReflectionUtil.nms("NBTCompressedStreamTools").getMethod("a", ReflectionUtil.nms("NBTTagCompound"), DataOutput.class); m.invoke(null, obj, new DataOutputStream(new ByteBufOutputStream(buf))); try { - return PacketUtil.readNBT(buf); + return Type.NBT.read(buf); } finally { buf.release(); } diff --git a/src/main/java/us/myles/ViaVersion/metadata/MetaIndex.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java similarity index 97% rename from src/main/java/us/myles/ViaVersion/metadata/MetaIndex.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java index 71af09183..298d48cd1 100644 --- a/src/main/java/us/myles/ViaVersion/metadata/MetaIndex.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java @@ -1,192 +1,192 @@ -package us.myles.ViaVersion.metadata; - -import lombok.Getter; -import org.bukkit.entity.*; - -@Getter -public enum MetaIndex { - - // entity - ENTITY_STATUS(org.bukkit.entity.Entity.class, 0, Type.Byte, NewType.Byte), - ENTITY_AIR(org.bukkit.entity.Entity.class, 1, Type.Short, NewType.VarInt), - ENTITY_SILENT(org.bukkit.entity.Entity.class, 4, Type.Byte, NewType.Boolean), - // living entity - LIVINGENTITY_NAMETAG(LivingEntity.class, 2, Type.String, NewType.String), - LIVINGENTITY_ALWAYS_SHOW_NAMETAG(LivingEntity.class, 3, Type.Byte, NewType.Boolean), - LIVINGENTITY_HEALTH(LivingEntity.class, 6, Type.Float, NewType.Float), - LIVINGENTITY_POTION_EFFECT_COLOR(LivingEntity.class, 7, Type.Int, NewType.VarInt), - LIVINGENTITY_IS_POTION_AMBIENT(LivingEntity.class, 8, Type.Byte, NewType.Boolean), - LIVINGENTITY_NUMBER_OF_ARROWS_IN(LivingEntity.class, 9, Type.Byte, NewType.VarInt), - LIVINGENTITY_NO_AI(LivingEntity.class, 15, Type.Byte, 10, NewType.Byte), // in 1.9 this is combined with Left handed, oh. - // ageable - AGEABLE_AGE(Ageable.class, 12, Type.Byte, 11, NewType.Boolean), - // armour stand - STAND_INFO(ArmorStand.class, 10, Type.Byte, NewType.Byte), - STAND_HEAD_POS(ArmorStand.class, 11, Type.Rotation, NewType.Vector3F), - STAND_BODY_POS(ArmorStand.class, 12, Type.Rotation, NewType.Vector3F), - STAND_LA_POS(ArmorStand.class, 13, Type.Rotation, NewType.Vector3F), - STAND_RA_POS(ArmorStand.class, 14, Type.Rotation, NewType.Vector3F), - STAND_LL_POS(ArmorStand.class, 15, Type.Rotation, NewType.Vector3F), - STAND_RL_POS(ArmorStand.class, 16, Type.Rotation, NewType.Vector3F), - // human, discountined? - PLAYER_SKIN_FLAGS(HumanEntity.class, 10, Type.Byte, 12, NewType.Byte), // unsigned on 1.8 - PLAYER_HUMAN_BYTE(HumanEntity.class, 16, Type.Byte, NewType.Discontinued), // unused on 1.8 - PLAYER_ADDITIONAL_HEARTS(HumanEntity.class, 17, Type.Float, 10, NewType.Float), - PLAYER_SCORE(HumanEntity.class, 18, Type.Int, 11, NewType.VarInt), - PLAYER_HAND(HumanEntity.class, -1, Type.NonExistent, 5, NewType.Byte), // new in 1.9 - SOMETHING_ANTICHEAT_PLUGINS_FOR_SOME_REASON_USE(HumanEntity.class, 11, Type.Byte, NewType.Discontinued), //For what we know, This doesn't exists. If you think it exists and knows what it does. Please tell us. - // horse - HORSE_INFO(Horse.class, 16, Type.Int, 12, NewType.Byte), - HORSE_TYPE(Horse.class, 19, Type.Byte, 13, NewType.VarInt), - HORSE_SUBTYPE(Horse.class, 20, Type.Int, 14, NewType.VarInt), - HORSE_OWNER(Horse.class, 21, Type.String, 15, NewType.OptUUID), - HORSE_ARMOR(Horse.class, 22, Type.Int, 16, NewType.VarInt), - // bat - BAT_ISHANGING(Bat.class, 16, Type.Byte, 11, NewType.Byte), - // tameable - TAMING_INFO(Tameable.class, 16, Type.Byte, 12, NewType.Byte), - TAMING_OWNER(Tameable.class, 17, Type.String, 13, NewType.OptUUID), - // ocelot - OCELOT_TYPE(Ocelot.class, 18, Type.Byte, 14, NewType.VarInt), - // wolf - WOLF_HEALTH(Wolf.class, 18, Type.Float, 14, NewType.Float), - WOLF_BEGGING(Wolf.class, 19, Type.Byte, 15, NewType.Boolean), - WOLF_COLLAR(Wolf.class, 20, Type.Byte, 16, NewType.VarInt), - // pig - PIG_SADDLE(Pig.class, 16, Type.Byte, 12, NewType.Boolean), - // rabbit - RABBIT_TYPE(Rabbit.class, 18, Type.Byte, 12, NewType.VarInt), - // sheep - SHEEP_COLOR(Sheep.class, 16, Type.Byte, 12, NewType.Byte), - // villager - VILLAGER_PROFESSION(Villager.class, 16, Type.Int, 12, NewType.VarInt), // TODO write this to wiki.vg - // enderman - ENDERMAN_BLOCK(Enderman.class, 16, Type.Short, 11, NewType.BlockID), // special case - ENDERMAN_BLOCKDATA(Enderman.class, 17, Type.Byte, 11, NewType.BlockID), // special case - ENDERMAN_ISSCREAMING(Enderman.class, 18, Type.Byte, 12, NewType.Boolean), - // zombie - ZOMBIE_ISCHILD(Zombie.class, 12, Type.Byte, 11, NewType.Boolean), - ZOMBIE_ISVILLAGER(Zombie.class, 13, Type.Byte, 12, NewType.VarInt), - ZOMBIE_ISCONVERTING(Zombie.class, 14, Type.Byte, 13, NewType.Boolean), - // ZOMBIE_RISINGHANDS added in 1.9 - // blaze - BLAZE_ONFIRE(Blaze.class, 16, Type.Byte, 11, NewType.Byte), - // spider - SPIDER_CIMBING(Spider.class, 16, Type.Byte, 11, NewType.Byte), - // creeper - CREEPER_FUSE(Creeper.class, 16, Type.Byte, 11, NewType.VarInt), // -1 idle, 1 is fuse - CREEPER_ISPOWERED(Creeper.class, 17, Type.Byte, 12, NewType.Boolean), - CREEPER_ISIGNITED(Creeper.class, 18, Type.Byte, 13, NewType.Boolean), - // ghast - GHAST_ISATTACKING(Ghast.class, 16, Type.Byte, 11, NewType.Boolean), - // slime - SLIME_SIZE(Slime.class, 16, Type.Byte, 11, NewType.VarInt), - // skeleton - SKELETON_TYPE(Skeleton.class, 13, Type.Byte, 11, NewType.VarInt), - // witch - WITCH_AGGRO(Witch.class, 21, Type.Byte, 11, NewType.Boolean), - // iron golem - IRON_PLAYERMADE(IronGolem.class, 16, Type.Byte, 11, NewType.Byte), - // wither - WITHER_TARGET1(Wither.class, 17, Type.Int, 11, NewType.VarInt), - WITHER_TARGET2(Wither.class, 18, Type.Int, 12, NewType.VarInt), - WITHER_TARGET3(Wither.class, 19, Type.Int, 13, NewType.VarInt), - WITHER_INVULN_TIME(Wither.class, 20, Type.Int, 14, NewType.VarInt), - WITHER_PROPERTIES(Wither.class, 10, Type.Byte, NewType.Byte), - WITHER_UNKNOWN(Wither.class, 11, Type.Byte, NewType.Discontinued), - // wither skull - WITHERSKULL_INVULN(WitherSkull.class, 10, Type.Byte, 5, NewType.Boolean), - // guardian - GUARDIAN_INFO(Guardian.class, 16, Type.Int, 11, NewType.Byte), - GUARDIAN_TARGET(Guardian.class, 17, Type.Int, 12, NewType.VarInt), - // boat - BOAT_SINCEHIT(Boat.class, 17, Type.Int, 5, NewType.VarInt), - BOAT_FORWARDDIR(Boat.class, 18, Type.Int, 6, NewType.VarInt), - BOAT_DMGTAKEN(Boat.class, 19, Type.Float, 7, NewType.Float), - // BOAT_TYPE in 1.9 - // minecart - MINECART_SHAKINGPOWER(Minecart.class, 17, Type.Int, 5, NewType.VarInt), - MINECART_SHAKINGDIRECTION(Minecart.class, 18, Type.Int, 6, NewType.VarInt), - MINECART_DAMAGETAKEN(Minecart.class, 19, Type.Float, 7, NewType.Float), // also shaking modifier :P - MINECART_BLOCK(Minecart.class, 20, Type.Int, 8, NewType.VarInt), - MINECART_BLOCK_Y(Minecart.class, 21, Type.Int, 9, NewType.VarInt), - MINECART_SHOWBLOCK(Minecart.class, 22, Type.Byte, 10, NewType.Boolean), - // Command minecart (they are still broken) - MINECART_COMMANDBLOCK_COMMAND(Minecart.class, 23, Type.String, 11, NewType.String), - MINECART_COMMANDBLOCK_OUTPUT(Minecart.class, 24, Type.String, 12, NewType.Chat), - // furnace cart - FURNACECART_ISPOWERED(Minecart.class, 16, Type.Byte, 11, NewType.Boolean), - // item drop - ITEM_ITEM(Item.class, 10, Type.Slot, 5, NewType.Slot), - // arrow - ARROW_ISCRIT(Arrow.class, 16, Type.Byte, 5, NewType.Byte), - // firework - FIREWORK_INFO(Firework.class, 8, Type.Slot, 5, NewType.Slot), - // item frame - ITEMFRAME_ITEM(ItemFrame.class, 8, Type.Slot, 5, NewType.Slot), - ITEMFRAME_ROTATION(ItemFrame.class, 9, Type.Byte, 6, NewType.VarInt), - // ender crystal - ENDERCRYSTAL_HEALTH(EnderCrystal.class, 8, Type.Int, NewType.Discontinued), - // Ender dragon boss bar issues - ENDERDRAGON_UNKNOWN(EnderDragon.class, 5, Type.Byte, NewType.Discontinued), - ENDERDRAGON_NAME(EnderDragon.class, 10, Type.String, NewType.Discontinued), - // Normal Ender dragon - ENDERDRAGON_FLAG(EnderDragon.class, 15, Type.Byte, NewType.Discontinued), - ENDERDRAGON_PHASE(EnderDragon.class, 11, Type.Byte, NewType.VarInt); - - private Class clazz; - private int newIndex; - private NewType newType; - private Type oldType; - private int index; - - MetaIndex(Class type, int index, Type oldType, NewType newType) { - this.clazz = type; - this.index = index; - this.newIndex = index; - this.oldType = oldType; - this.newType = newType; - } - - MetaIndex(Class type, int index, Type oldType, int newIndex, NewType newType) { - this.clazz = type; - this.index = index; - this.oldType = oldType; - this.newIndex = newIndex; - this.newType = newType; - } - - public static MetaIndex getIndex(EntityType type, int index) { - Class entityClass = type.getEntityClass(); - if (entityClass == null) { - System.out.println("Could not get entity class for " + type); - return null; - } - for (MetaIndex mi : MetaIndex.values()) { - if (mi.getIndex() == index) { - // To fix issue with armour stands colliding with new values - if (mi.getApplicableClass().equals(LivingEntity.class)) continue; - - if ((mi.getApplicableClass().isAssignableFrom(entityClass) || - mi.getApplicableClass().equals(entityClass))) { - return mi; - } - } - } - // fall back to living entity - for (MetaIndex mi : MetaIndex.values()) { - if (mi.getIndex() == index) { - if (mi.getApplicableClass().isAssignableFrom(LivingEntity.class) || - mi.getApplicableClass().equals(LivingEntity.class)) { - return mi; - } - } - } - return null; - } - - public Class getApplicableClass() { - return this.clazz; - } -} - +package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata; + +import lombok.Getter; +import org.bukkit.entity.*; + +@Getter +public enum MetaIndex { + + // entity + ENTITY_STATUS(org.bukkit.entity.Entity.class, 0, Type.Byte, NewType.Byte), + ENTITY_AIR(org.bukkit.entity.Entity.class, 1, Type.Short, NewType.VarInt), + ENTITY_SILENT(org.bukkit.entity.Entity.class, 4, Type.Byte, NewType.Boolean), + // living entity + LIVINGENTITY_NAMETAG(LivingEntity.class, 2, Type.String, NewType.String), + LIVINGENTITY_ALWAYS_SHOW_NAMETAG(LivingEntity.class, 3, Type.Byte, NewType.Boolean), + LIVINGENTITY_HEALTH(LivingEntity.class, 6, Type.Float, NewType.Float), + LIVINGENTITY_POTION_EFFECT_COLOR(LivingEntity.class, 7, Type.Int, NewType.VarInt), + LIVINGENTITY_IS_POTION_AMBIENT(LivingEntity.class, 8, Type.Byte, NewType.Boolean), + LIVINGENTITY_NUMBER_OF_ARROWS_IN(LivingEntity.class, 9, Type.Byte, NewType.VarInt), + LIVINGENTITY_NO_AI(LivingEntity.class, 15, Type.Byte, 10, NewType.Byte), // in 1.9 this is combined with Left handed, oh. + // ageable + AGEABLE_AGE(Ageable.class, 12, Type.Byte, 11, NewType.Boolean), + // armour stand + STAND_INFO(ArmorStand.class, 10, Type.Byte, NewType.Byte), + STAND_HEAD_POS(ArmorStand.class, 11, Type.Rotation, NewType.Vector3F), + STAND_BODY_POS(ArmorStand.class, 12, Type.Rotation, NewType.Vector3F), + STAND_LA_POS(ArmorStand.class, 13, Type.Rotation, NewType.Vector3F), + STAND_RA_POS(ArmorStand.class, 14, Type.Rotation, NewType.Vector3F), + STAND_LL_POS(ArmorStand.class, 15, Type.Rotation, NewType.Vector3F), + STAND_RL_POS(ArmorStand.class, 16, Type.Rotation, NewType.Vector3F), + // human, discountined? + PLAYER_SKIN_FLAGS(HumanEntity.class, 10, Type.Byte, 12, NewType.Byte), // unsigned on 1.8 + PLAYER_HUMAN_BYTE(HumanEntity.class, 16, Type.Byte, NewType.Discontinued), // unused on 1.8 + PLAYER_ADDITIONAL_HEARTS(HumanEntity.class, 17, Type.Float, 10, NewType.Float), + PLAYER_SCORE(HumanEntity.class, 18, Type.Int, 11, NewType.VarInt), + PLAYER_HAND(HumanEntity.class, -1, Type.NonExistent, 5, NewType.Byte), // new in 1.9 + SOMETHING_ANTICHEAT_PLUGINS_FOR_SOME_REASON_USE(HumanEntity.class, 11, Type.Byte, NewType.Discontinued), //For what we know, This doesn't exists. If you think it exists and knows what it does. Please tell us. + // horse + HORSE_INFO(Horse.class, 16, Type.Int, 12, NewType.Byte), + HORSE_TYPE(Horse.class, 19, Type.Byte, 13, NewType.VarInt), + HORSE_SUBTYPE(Horse.class, 20, Type.Int, 14, NewType.VarInt), + HORSE_OWNER(Horse.class, 21, Type.String, 15, NewType.OptUUID), + HORSE_ARMOR(Horse.class, 22, Type.Int, 16, NewType.VarInt), + // bat + BAT_ISHANGING(Bat.class, 16, Type.Byte, 11, NewType.Byte), + // tameable + TAMING_INFO(Tameable.class, 16, Type.Byte, 12, NewType.Byte), + TAMING_OWNER(Tameable.class, 17, Type.String, 13, NewType.OptUUID), + // ocelot + OCELOT_TYPE(Ocelot.class, 18, Type.Byte, 14, NewType.VarInt), + // wolf + WOLF_HEALTH(Wolf.class, 18, Type.Float, 14, NewType.Float), + WOLF_BEGGING(Wolf.class, 19, Type.Byte, 15, NewType.Boolean), + WOLF_COLLAR(Wolf.class, 20, Type.Byte, 16, NewType.VarInt), + // pig + PIG_SADDLE(Pig.class, 16, Type.Byte, 12, NewType.Boolean), + // rabbit + RABBIT_TYPE(Rabbit.class, 18, Type.Byte, 12, NewType.VarInt), + // sheep + SHEEP_COLOR(Sheep.class, 16, Type.Byte, 12, NewType.Byte), + // villager + VILLAGER_PROFESSION(Villager.class, 16, Type.Int, 12, NewType.VarInt), // TODO write this to wiki.vg + // enderman + ENDERMAN_BLOCK(Enderman.class, 16, Type.Short, 11, NewType.BlockID), // special case + ENDERMAN_BLOCKDATA(Enderman.class, 17, Type.Byte, 11, NewType.BlockID), // special case + ENDERMAN_ISSCREAMING(Enderman.class, 18, Type.Byte, 12, NewType.Boolean), + // zombie + ZOMBIE_ISCHILD(Zombie.class, 12, Type.Byte, 11, NewType.Boolean), + ZOMBIE_ISVILLAGER(Zombie.class, 13, Type.Byte, 12, NewType.VarInt), + ZOMBIE_ISCONVERTING(Zombie.class, 14, Type.Byte, 13, NewType.Boolean), + // ZOMBIE_RISINGHANDS added in 1.9 + // blaze + BLAZE_ONFIRE(Blaze.class, 16, Type.Byte, 11, NewType.Byte), + // spider + SPIDER_CIMBING(Spider.class, 16, Type.Byte, 11, NewType.Byte), + // creeper + CREEPER_FUSE(Creeper.class, 16, Type.Byte, 11, NewType.VarInt), // -1 idle, 1 is fuse + CREEPER_ISPOWERED(Creeper.class, 17, Type.Byte, 12, NewType.Boolean), + CREEPER_ISIGNITED(Creeper.class, 18, Type.Byte, 13, NewType.Boolean), + // ghast + GHAST_ISATTACKING(Ghast.class, 16, Type.Byte, 11, NewType.Boolean), + // slime + SLIME_SIZE(Slime.class, 16, Type.Byte, 11, NewType.VarInt), + // skeleton + SKELETON_TYPE(Skeleton.class, 13, Type.Byte, 11, NewType.VarInt), + // witch + WITCH_AGGRO(Witch.class, 21, Type.Byte, 11, NewType.Boolean), + // iron golem + IRON_PLAYERMADE(IronGolem.class, 16, Type.Byte, 11, NewType.Byte), + // wither + WITHER_TARGET1(Wither.class, 17, Type.Int, 11, NewType.VarInt), + WITHER_TARGET2(Wither.class, 18, Type.Int, 12, NewType.VarInt), + WITHER_TARGET3(Wither.class, 19, Type.Int, 13, NewType.VarInt), + WITHER_INVULN_TIME(Wither.class, 20, Type.Int, 14, NewType.VarInt), + WITHER_PROPERTIES(Wither.class, 10, Type.Byte, NewType.Byte), + WITHER_UNKNOWN(Wither.class, 11, Type.Byte, NewType.Discontinued), + // wither skull + WITHERSKULL_INVULN(WitherSkull.class, 10, Type.Byte, 5, NewType.Boolean), + // guardian + GUARDIAN_INFO(Guardian.class, 16, Type.Int, 11, NewType.Byte), + GUARDIAN_TARGET(Guardian.class, 17, Type.Int, 12, NewType.VarInt), + // boat + BOAT_SINCEHIT(Boat.class, 17, Type.Int, 5, NewType.VarInt), + BOAT_FORWARDDIR(Boat.class, 18, Type.Int, 6, NewType.VarInt), + BOAT_DMGTAKEN(Boat.class, 19, Type.Float, 7, NewType.Float), + // BOAT_TYPE in 1.9 + // minecart + MINECART_SHAKINGPOWER(Minecart.class, 17, Type.Int, 5, NewType.VarInt), + MINECART_SHAKINGDIRECTION(Minecart.class, 18, Type.Int, 6, NewType.VarInt), + MINECART_DAMAGETAKEN(Minecart.class, 19, Type.Float, 7, NewType.Float), // also shaking modifier :P + MINECART_BLOCK(Minecart.class, 20, Type.Int, 8, NewType.VarInt), + MINECART_BLOCK_Y(Minecart.class, 21, Type.Int, 9, NewType.VarInt), + MINECART_SHOWBLOCK(Minecart.class, 22, Type.Byte, 10, NewType.Boolean), + // Command minecart (they are still broken) + MINECART_COMMANDBLOCK_COMMAND(Minecart.class, 23, Type.String, 11, NewType.String), + MINECART_COMMANDBLOCK_OUTPUT(Minecart.class, 24, Type.String, 12, NewType.Chat), + // furnace cart + FURNACECART_ISPOWERED(Minecart.class, 16, Type.Byte, 11, NewType.Boolean), + // item drop + ITEM_ITEM(Item.class, 10, Type.Slot, 5, NewType.Slot), + // arrow + ARROW_ISCRIT(Arrow.class, 16, Type.Byte, 5, NewType.Byte), + // firework + FIREWORK_INFO(Firework.class, 8, Type.Slot, 5, NewType.Slot), + // item frame + ITEMFRAME_ITEM(ItemFrame.class, 8, Type.Slot, 5, NewType.Slot), + ITEMFRAME_ROTATION(ItemFrame.class, 9, Type.Byte, 6, NewType.VarInt), + // ender crystal + ENDERCRYSTAL_HEALTH(EnderCrystal.class, 8, Type.Int, NewType.Discontinued), + // Ender dragon boss bar issues + ENDERDRAGON_UNKNOWN(EnderDragon.class, 5, Type.Byte, NewType.Discontinued), + ENDERDRAGON_NAME(EnderDragon.class, 10, Type.String, NewType.Discontinued), + // Normal Ender dragon + ENDERDRAGON_FLAG(EnderDragon.class, 15, Type.Byte, NewType.Discontinued), + ENDERDRAGON_PHASE(EnderDragon.class, 11, Type.Byte, NewType.VarInt); + + private Class clazz; + private int newIndex; + private NewType newType; + private Type oldType; + private int index; + + MetaIndex(Class type, int index, Type oldType, NewType newType) { + this.clazz = type; + this.index = index; + this.newIndex = index; + this.oldType = oldType; + this.newType = newType; + } + + MetaIndex(Class type, int index, Type oldType, int newIndex, NewType newType) { + this.clazz = type; + this.index = index; + this.oldType = oldType; + this.newIndex = newIndex; + this.newType = newType; + } + + public static MetaIndex getIndex(EntityType type, int index) { + Class entityClass = type.getEntityClass(); + if (entityClass == null) { + System.out.println("Could not get entity class for " + type); + return null; + } + for (MetaIndex mi : MetaIndex.values()) { + if (mi.getIndex() == index) { + // To fix issue with armour stands colliding with new values + if (mi.getApplicableClass().equals(LivingEntity.class)) continue; + + if ((mi.getApplicableClass().isAssignableFrom(entityClass) || + mi.getApplicableClass().equals(entityClass))) { + return mi; + } + } + } + // fall back to living entity + for (MetaIndex mi : MetaIndex.values()) { + if (mi.getIndex() == index) { + if (mi.getApplicableClass().isAssignableFrom(LivingEntity.class) || + mi.getApplicableClass().equals(LivingEntity.class)) { + return mi; + } + } + } + return null; + } + + public Class getApplicableClass() { + return this.clazz; + } +} + diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/metadata/MetadataRewriter.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter.java similarity index 82% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/metadata/MetadataRewriter.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter.java index 8a3c8ce20..9f01ea026 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/metadata/MetadataRewriter.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter.java @@ -1,17 +1,14 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.metadata; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata; import org.bukkit.entity.EntityType; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.api.ViaVersion; -import us.myles.ViaVersion.metadata.MetaIndex; -import us.myles.ViaVersion.metadata.NewType; -import us.myles.ViaVersion.metadata.Type; -import us.myles.ViaVersion2.api.item.Item; -import us.myles.ViaVersion2.api.metadata.Metadata; -import us.myles.ViaVersion2.api.protocol1_9to1_8.ItemRewriter; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import java.util.ArrayList; import java.util.List; @@ -32,7 +29,7 @@ public class MetadataRewriter { Object value = entry.getValue(); switch (metaIndex.getNewType()) { case Byte: - entry.setType(us.myles.ViaVersion2.api.type.Type.BYTE); + entry.setType(us.myles.ViaVersion.api.type.Type.BYTE); // convert from int, byte if (metaIndex.getOldType() == Type.Byte) { entry.setValue(value); @@ -48,12 +45,12 @@ public class MetadataRewriter { } int newIndex = MetaIndex.PLAYER_HAND.getNewIndex(); int typeID = MetaIndex.PLAYER_HAND.getNewType().getTypeID(); - Metadata metadata = new Metadata(newIndex, typeID, us.myles.ViaVersion2.api.type.Type.BYTE, val); + Metadata metadata = new Metadata(newIndex, typeID, us.myles.ViaVersion.api.type.Type.BYTE, val); list.add(metadata); } break; case OptUUID: - entry.setType(us.myles.ViaVersion2.api.type.Type.OPTIONAL_UUID); + entry.setType(us.myles.ViaVersion.api.type.Type.OPTIONAL_UUID); String owner = (String) value; UUID toWrite = null; if (owner.length() != 0) { @@ -65,7 +62,7 @@ public class MetadataRewriter { entry.setValue(toWrite); break; case BlockID: - entry.setType(us.myles.ViaVersion2.api.type.Type.VAR_INT); + entry.setType(us.myles.ViaVersion.api.type.Type.VAR_INT); // if we have both sources :)) if (metaIndex.getOldType() == Type.Byte) { data = (Byte) value; @@ -83,7 +80,7 @@ public class MetadataRewriter { } break; case VarInt: - entry.setType(us.myles.ViaVersion2.api.type.Type.VAR_INT); + entry.setType(us.myles.ViaVersion.api.type.Type.VAR_INT); // convert from int, short, byte if (metaIndex.getOldType() == Type.Byte) { entry.setValue(((Byte) value).intValue()); @@ -96,37 +93,37 @@ public class MetadataRewriter { } break; case Float: - entry.setType(us.myles.ViaVersion2.api.type.Type.FLOAT); + entry.setType(us.myles.ViaVersion.api.type.Type.FLOAT); entry.setValue(value); break; case String: - entry.setType(us.myles.ViaVersion2.api.type.Type.STRING); + entry.setType(us.myles.ViaVersion.api.type.Type.STRING); entry.setValue(value); break; case Boolean: - entry.setType(us.myles.ViaVersion2.api.type.Type.BOOLEAN); + entry.setType(us.myles.ViaVersion.api.type.Type.BOOLEAN); if (metaIndex == MetaIndex.AGEABLE_AGE) entry.setValue((Byte) value < 0); else entry.setValue((Byte) value != 0); break; case Slot: - entry.setType(us.myles.ViaVersion2.api.type.Type.ITEM); + entry.setType(us.myles.ViaVersion.api.type.Type.ITEM); entry.setValue(value); ItemRewriter.toClient((Item) entry.getValue()); break; case Position: - entry.setType(us.myles.ViaVersion2.api.type.Type.VECTOR); + entry.setType(us.myles.ViaVersion.api.type.Type.VECTOR); Vector vector = (Vector) value; entry.setValue(vector); break; case Vector3F: - entry.setType(us.myles.ViaVersion2.api.type.Type.ROTATION); + entry.setType(us.myles.ViaVersion.api.type.Type.ROTATION); EulerAngle angle = (EulerAngle) value; entry.setValue(angle); break; case Chat: - entry.setType(us.myles.ViaVersion2.api.type.Type.STRING); + entry.setType(us.myles.ViaVersion.api.type.Type.STRING); value = Protocol1_9TO1_8.fixJson((String) value); entry.setValue(value); break; diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/metadata/MetadataTypes.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataTypes.java similarity index 82% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/metadata/MetadataTypes.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataTypes.java index f4922e059..36060f9bd 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/metadata/MetadataTypes.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataTypes.java @@ -1,8 +1,8 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.metadata; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata; import lombok.Getter; import lombok.RequiredArgsConstructor; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.type.Type; @RequiredArgsConstructor @Getter diff --git a/src/main/java/us/myles/ViaVersion/metadata/NewType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/NewType.java similarity index 85% rename from src/main/java/us/myles/ViaVersion/metadata/NewType.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/NewType.java index 3fbb1aa70..3c8c8d874 100644 --- a/src/main/java/us/myles/ViaVersion/metadata/NewType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/NewType.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.metadata; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/us/myles/ViaVersion/metadata/Type.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/Type.java similarity index 84% rename from src/main/java/us/myles/ViaVersion/metadata/Type.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/Type.java index 5c0e9d20b..18bb90b4b 100644 --- a/src/main/java/us/myles/ViaVersion/metadata/Type.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/Type.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.metadata; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/EntityPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java similarity index 92% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/EntityPackets.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java index 88d5f9180..bc3d457f6 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/EntityPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/EntityPackets.java @@ -1,21 +1,21 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.packets; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; import org.bukkit.Material; import us.myles.ViaVersion.ViaVersionPlugin; +import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.ViaVersion; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.protocol.Protocol; +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.packets.State; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.item.Item; -import us.myles.ViaVersion2.api.metadata.Metadata; -import us.myles.ViaVersion2.api.protocol.Protocol; -import us.myles.ViaVersion2.api.protocol1_9to1_8.ItemRewriter; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; -import us.myles.ViaVersion2.api.protocol1_9to1_8.metadata.MetadataRewriter; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker; -import us.myles.ViaVersion2.api.remapper.PacketHandler; -import us.myles.ViaVersion2.api.remapper.PacketRemapper; -import us.myles.ViaVersion2.api.remapper.ValueTransformer; -import us.myles.ViaVersion2.api.type.Type; +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; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; import java.util.List; @@ -187,8 +187,8 @@ public class EntityPackets { int entityID = wrapper.get(Type.VAR_INT, 0); Item stack = wrapper.get(Type.ITEM, 0); - if(stack != null){ - if(Material.getMaterial(stack.getId()).name().endsWith("SWORD")){ + if (stack != null) { + if (Material.getMaterial(stack.getId()).name().endsWith("SWORD")) { entityTracker.getValidBlocking().add(entityID); return; } @@ -211,9 +211,9 @@ public class EntityPackets { List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); - if(tracker.getClientEntityTypes().containsKey(entityID)) { + if (tracker.getClientEntityTypes().containsKey(entityID)) { MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList); - }else{ + } else { System.out.println("Unable to find entity for metadata, entity ID: " + entityID); } } diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/InventoryPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/InventoryPackets.java similarity index 95% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/InventoryPackets.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/InventoryPackets.java index 3ce9673f9..64443ef5d 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/InventoryPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/InventoryPackets.java @@ -1,17 +1,17 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.packets; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.remapper.PacketHandler; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.remapper.ValueCreator; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.item.Item; -import us.myles.ViaVersion2.api.protocol.Protocol; -import us.myles.ViaVersion2.api.protocol1_9to1_8.ItemRewriter; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.InventoryTracker; -import us.myles.ViaVersion2.api.remapper.PacketHandler; -import us.myles.ViaVersion2.api.remapper.PacketRemapper; -import us.myles.ViaVersion2.api.remapper.ValueCreator; -import us.myles.ViaVersion2.api.type.Type; +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.storage.EntityTracker; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.InventoryTracker; public class InventoryPackets { public static void register(Protocol protocol) { diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/PlayerPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java similarity index 88% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/PlayerPackets.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java index a62097f3c..d423aa70a 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/PlayerPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/PlayerPackets.java @@ -1,21 +1,21 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.packets; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; import org.bukkit.Material; import org.bukkit.entity.EntityType; import us.myles.ViaVersion.ViaVersionPlugin; +import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.ViaVersion; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.api.remapper.PacketHandler; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.remapper.ValueCreator; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.item.Item; -import us.myles.ViaVersion2.api.protocol.Protocol; -import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo; -import us.myles.ViaVersion2.api.protocol1_9to1_8.PlayerMovementMapper; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker; -import us.myles.ViaVersion2.api.remapper.PacketHandler; -import us.myles.ViaVersion2.api.remapper.PacketRemapper; -import us.myles.ViaVersion2.api.remapper.ValueCreator; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.PlayerMovementMapper; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; public class PlayerPackets { public static void register(Protocol protocol) { @@ -230,7 +230,7 @@ public class PlayerPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { String name = wrapper.get(Type.STRING, 0); - if(name.equalsIgnoreCase("MC|BOpen")){ + if (name.equalsIgnoreCase("MC|BOpen")) { wrapper.passthrough(Type.REMAINING_BYTES); // This is so ugly, :( wrapper.write(Type.VAR_INT, 0); } @@ -239,6 +239,47 @@ public class PlayerPackets { } }); + /* Removed packets */ + + // Map Bulk + protocol.registerOutgoing(State.PLAY, 0x26, 0x26, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.cancel(); + } + }); + } + }); + + // Update Entity NBT + protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.cancel(); + } + }); + } + }); + + // Set Compression + protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.cancel(); + } + }); + } + }); + /* Packets which do not have any field remapping or handlers */ protocol.registerOutgoing(State.PLAY, 0x3A, 0x0E); // Tab Complete Response Packet @@ -383,13 +424,13 @@ public class PlayerPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { String name = wrapper.get(Type.STRING, 0); - if(name.equalsIgnoreCase("MC|BSign")){ + if (name.equalsIgnoreCase("MC|BSign")) { Item item = wrapper.passthrough(Type.ITEM); - if(item != null){ + if (item != null) { item.setId((short) Material.WRITTEN_BOOK.getId()); } } - if(name.equalsIgnoreCase("MC|AutoCmd")){ + if (name.equalsIgnoreCase("MC|AutoCmd")) { wrapper.set(Type.STRING, 0, "MC|AdvCdm"); wrapper.write(Type.BYTE, (byte) 0); wrapper.passthrough(Type.INT); // X @@ -399,7 +440,7 @@ public class PlayerPackets { wrapper.passthrough(Type.BOOLEAN); // Flag wrapper.clearInputBuffer(); } - if(name.equalsIgnoreCase("MC|AdvCmd")){ + if (name.equalsIgnoreCase("MC|AdvCmd")) { wrapper.set(Type.STRING, 0, "MC|AdvCdm"); } } @@ -420,6 +461,5 @@ public class PlayerPackets { protocol.registerIncoming(State.PLAY, 0x06, 0x0D, new PlayerMovementMapper()); // Player Move & Look Packet protocol.registerIncoming(State.PLAY, 0x05, 0x0E, new PlayerMovementMapper()); // Player Look Packet protocol.registerIncoming(State.PLAY, 0x03, 0x0F, new PlayerMovementMapper()); // Player Packet - } } diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/SpawnPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java similarity index 92% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/SpawnPackets.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java index c581ed42a..5a40fb1b3 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/SpawnPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/SpawnPackets.java @@ -1,19 +1,19 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.packets; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; import org.bukkit.entity.EntityType; +import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.remapper.PacketHandler; +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.packets.State; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; import us.myles.ViaVersion.util.EntityUtil; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.metadata.Metadata; -import us.myles.ViaVersion2.api.protocol.Protocol; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; -import us.myles.ViaVersion2.api.protocol1_9to1_8.metadata.MetadataRewriter; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker; -import us.myles.ViaVersion2.api.remapper.PacketHandler; -import us.myles.ViaVersion2.api.remapper.PacketRemapper; -import us.myles.ViaVersion2.api.remapper.ValueCreator; -import us.myles.ViaVersion2.api.remapper.ValueTransformer; -import us.myles.ViaVersion2.api.type.Type; import java.util.List; @@ -176,9 +176,9 @@ public class SpawnPackets { List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); - if(tracker.getClientEntityTypes().containsKey(entityID)) { + if (tracker.getClientEntityTypes().containsKey(entityID)) { MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList); - }else{ + } else { System.out.println("Unable to find entity for metadata, entity ID: " + entityID); } } @@ -252,9 +252,9 @@ public class SpawnPackets { List metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0); int entityID = wrapper.get(Type.VAR_INT, 0); EntityTracker tracker = wrapper.user().get(EntityTracker.class); - if(tracker.getClientEntityTypes().containsKey(entityID)) { + if (tracker.getClientEntityTypes().containsKey(entityID)) { MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList); - }else{ + } else { System.out.println("Unable to find entity for metadata, entity ID: " + entityID); } } diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/WorldPackets.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java similarity index 92% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/WorldPackets.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index 45d6d7adf..1c2069dde 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/packets/WorldPackets.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -1,25 +1,23 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.packets; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets; import org.spacehq.opennbt.tag.builtin.CompoundTag; import org.spacehq.opennbt.tag.builtin.StringTag; -import us.myles.ViaVersion.CancelException; import us.myles.ViaVersion.ViaVersionPlugin; +import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.ViaVersion; -import us.myles.ViaVersion.chunks.Chunk; +import us.myles.ViaVersion.api.minecraft.chunks.Chunk; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.remapper.PacketHandler; +import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.remapper.ValueCreator; +import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.sounds.SoundEffect; -import us.myles.ViaVersion.util.PacketUtil; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.item.Item; -import us.myles.ViaVersion2.api.protocol.Protocol; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.ClientChunks; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker; -import us.myles.ViaVersion2.api.protocol1_9to1_8.types.ChunkType; -import us.myles.ViaVersion2.api.remapper.PacketHandler; -import us.myles.ViaVersion2.api.remapper.PacketRemapper; -import us.myles.ViaVersion2.api.remapper.ValueCreator; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.SoundEffect; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.ChunkType; public class WorldPackets { public static void register(Protocol protocol) { diff --git a/src/main/java/us/myles/ViaVersion/sounds/SoundCategory.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundCategory.java similarity index 87% rename from src/main/java/us/myles/ViaVersion/sounds/SoundCategory.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundCategory.java index e32ebdcd7..2d058cfbd 100644 --- a/src/main/java/us/myles/ViaVersion/sounds/SoundCategory.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundCategory.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion.sounds; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/us/myles/ViaVersion/sounds/SoundEffect.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java similarity index 98% rename from src/main/java/us/myles/ViaVersion/sounds/SoundEffect.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java index 2c544b3e0..dd0f31af3 100644 --- a/src/main/java/us/myles/ViaVersion/sounds/SoundEffect.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/sounds/SoundEffect.java @@ -1,283 +1,283 @@ -package us.myles.ViaVersion.sounds; - -import lombok.Getter; - -@Getter -public enum SoundEffect { - - MOB_HORSE_ZOMBIE_IDLE("mob.horse.zombie.idle", "entity.zombie_horse.ambient", SoundCategory.NEUTRAL), - NOTE_SNARE("note.snare", "block.note.snare", SoundCategory.RECORD), - RANDOM_WOOD_CLICK("random.wood_click", "block.wood_button.click_on", SoundCategory.BLOCK), - DIG_GRAVEL("dig.gravel", "block.gravel.place", SoundCategory.BLOCK), - RANDOM_BOWHIT("random.bowhit", "block.tripwire.detach", SoundCategory.NEUTRAL), - DIG_GLASS("dig.glass", "block.glass.break", SoundCategory.BLOCK), - MOB_ZOMBIE_SAY("mob.zombie.say", "entity.zombie_villager.ambient", SoundCategory.HOSTILE), - MOB_PIG_DEATH("mob.pig.death", "entity.pig.death", SoundCategory.NEUTRAL), - MOB_HORSE_DONKEY_HIT("mob.horse.donkey.hit", "entity.donkey.hurt", SoundCategory.NEUTRAL), - GAME_NEUTRAL_SWIM("game.neutral.swim", "entity.player.swim", SoundCategory.NEUTRAL), - GAME_PLAYER_SWIM("game.player.swim", "entity.player.swim", SoundCategory.PLAYER), - MOB_ENDERMEN_IDLE("mob.endermen.idle", "entity.endermen.ambient", SoundCategory.HOSTILE), - PORTAL_PORTAL("portal.portal", "block.portal.ambient", SoundCategory.BLOCK), - RANDOM_FIZZ("random.fizz", "entity.generic.extinguish_fire", SoundCategory.BLOCK), - NOTE_HARP("note.harp", "block.note.harp", SoundCategory.RECORD), - STEP_SNOW("step.snow", "block.snow.step", SoundCategory.NEUTRAL), - RANDOM_SUCCESSFUL_HIT("random.successful_hit", "entity.arrow.hit_player", SoundCategory.PLAYER), - MOB_ZOMBIEPIG_ZPIGHURT("mob.zombiepig.zpighurt", "entity.zombie_pig.hurt", SoundCategory.HOSTILE), - MOB_WOLF_HOWL("mob.wolf.howl", "entity.wolf.howl", SoundCategory.NEUTRAL), - FIREWORKS_LAUNCH("fireworks.launch", "entity.firework.launch", SoundCategory.AMBIENT), - MOB_COW_HURT("mob.cow.hurt", "entity.cow.death", SoundCategory.NEUTRAL), - FIREWORKS_LARGEBLAST("fireworks.largeBlast", "entity.firework.large_blast", SoundCategory.AMBIENT), - MOB_BLAZE_HIT("mob.blaze.hit", "entity.blaze.hurt", SoundCategory.HOSTILE), - MOB_VILLAGER_DEATH("mob.villager.death", "entity.villager.death", SoundCategory.NEUTRAL), - MOB_BLAZE_DEATH("mob.blaze.death", "entity.blaze.death", SoundCategory.HOSTILE), - MOB_HORSE_ZOMBIE_DEATH("mob.horse.zombie.death", "entity.zombie_horse.death", SoundCategory.NEUTRAL), - MOB_SILVERFISH_KILL("mob.silverfish.kill", "entity.endermite.death", SoundCategory.HOSTILE), - MOB_WOLF_PANTING("mob.wolf.panting", "entity.wolf.pant", SoundCategory.NEUTRAL), - NOTE_BASS("note.bass", "null", SoundCategory.RECORD), - DIG_STONE("dig.stone", "block.glass.place", SoundCategory.BLOCK), - MOB_ENDERMEN_STARE("mob.endermen.stare", "entity.endermen.stare", SoundCategory.HOSTILE), - GAME_PLAYER_SWIM_SPLASH("game.player.swim.splash", "entity.generic.splash", SoundCategory.BLOCK), - MOB_SLIME_SMALL("mob.slime.small", "block.slime.hit", SoundCategory.HOSTILE), - MOB_GHAST_DEATH("mob.ghast.death", "entity.ghast.death", SoundCategory.HOSTILE), - MOB_GUARDIAN_ATTACK("mob.guardian.attack", "entity.guardian.attack", SoundCategory.HOSTILE), - RANDOM_CLICK("random.click", "block.wood_pressureplate.click_on", SoundCategory.BLOCK), - MOB_ZOMBIEPIG_ZPIG("mob.zombiepig.zpig", "entity.zombie_pig.ambient", SoundCategory.HOSTILE), - GAME_PLAYER_DIE("game.player.die", "entity.player.death", SoundCategory.PLAYER), - FIREWORKS_TWINKLE_FAR("fireworks.twinkle_far", "entity.firework.twinkle_far", SoundCategory.AMBIENT), - MOB_GUARDIAN_LAND_IDLE("mob.guardian.land.idle", "entity.guardian.ambient_land", SoundCategory.HOSTILE), - DIG_GRASS("dig.grass", "block.grass.place", SoundCategory.BLOCK), - MOB_SKELETON_STEP("mob.skeleton.step", "entity.skeleton.step", SoundCategory.HOSTILE), - MOB_WITHER_DEATH("mob.wither.death", "entity.wither.death", SoundCategory.HOSTILE), - MOB_WOLF_HURT("mob.wolf.hurt", "entity.wolf.hurt", SoundCategory.NEUTRAL), - MOB_HORSE_LEATHER("mob.horse.leather", "entity.horse.saddle", SoundCategory.NEUTRAL), - MOB_BAT_LOOP("mob.bat.loop", "entity.bat.loop", SoundCategory.NEUTRAL), - MOB_GHAST_SCREAM("mob.ghast.scream", "entity.ghast.hurt", SoundCategory.HOSTILE), - GAME_PLAYER_HURT("game.player.hurt", "entity.player.death", SoundCategory.PLAYER), - GAME_NEUTRAL_DIE("game.neutral.die", "entity.player.death", SoundCategory.NEUTRAL), - MOB_CREEPER_DEATH("mob.creeper.death", "entity.creeper.death", SoundCategory.HOSTILE), - MOB_HORSE_GALLOP("mob.horse.gallop", "entity.horse.gallop", SoundCategory.NEUTRAL), - MOB_WITHER_SPAWN("mob.wither.spawn", "entity.wither.spawn", SoundCategory.HOSTILE), - MOB_ENDERMEN_HIT("mob.endermen.hit", "entity.endermen.hurt", SoundCategory.HOSTILE), - MOB_CREEPER_SAY("mob.creeper.say", "entity.creeper.hurt", SoundCategory.HOSTILE), - MOB_HORSE_WOOD("mob.horse.wood", "entity.horse.step_wood", SoundCategory.NEUTRAL), - MOB_ZOMBIE_UNFECT("mob.zombie.unfect", "entity.zombie_villager.converted", SoundCategory.HOSTILE), - RANDOM_ANVIL_USE("random.anvil_use", "block.anvil.use", SoundCategory.BLOCK), - RANDOM_CHESTCLOSED("random.chestclosed", "block.enderchest.close", SoundCategory.BLOCK), - MOB_SHEEP_SHEAR("mob.sheep.shear", "entity.sheep.shear", SoundCategory.NEUTRAL), - RANDOM_POP("random.pop", "entity.item.pickup", SoundCategory.PLAYER), - MOB_BAT_DEATH("mob.bat.death", "entity.bat.death", SoundCategory.NEUTRAL), - DIG_WOOD("dig.wood", "block.ladder.break", SoundCategory.BLOCK), - MOB_HORSE_DONKEY_DEATH("mob.horse.donkey.death", "entity.donkey.death", SoundCategory.NEUTRAL), - FIREWORKS_BLAST("fireworks.blast", "entity.firework.blast", SoundCategory.AMBIENT), - MOB_ZOMBIEPIG_ZPIGANGRY("mob.zombiepig.zpigangry", "entity.zombie_pig.angry", SoundCategory.HOSTILE), - GAME_HOSTILE_SWIM("game.hostile.swim", "entity.player.swim", SoundCategory.HOSTILE), - MOB_GUARDIAN_FLOP("mob.guardian.flop", "entity.guardian.flop", SoundCategory.HOSTILE), - MOB_VILLAGER_YES("mob.villager.yes", "entity.villager.yes", SoundCategory.NEUTRAL), - MOB_GHAST_CHARGE("mob.ghast.charge", "entity.ghast.warn", SoundCategory.HOSTILE), - CREEPER_PRIMED("creeper.primed", "entity.creeper.primed", SoundCategory.HOSTILE), - DIG_SAND("dig.sand", "block.sand.break", SoundCategory.BLOCK), - MOB_CHICKEN_SAY("mob.chicken.say", "entity.chicken.ambient", SoundCategory.NEUTRAL), - RANDOM_DOOR_CLOSE("random.door_close", "null", SoundCategory.BLOCK), - MOB_GUARDIAN_ELDER_DEATH("mob.guardian.elder.death", "entity.elder_guardian.death", SoundCategory.HOSTILE), - FIREWORKS_TWINKLE("fireworks.twinkle", "entity.firework.twinkle", SoundCategory.AMBIENT), - MOB_HORSE_SKELETON_DEATH("mob.horse.skeleton.death", "entity.skeleton_horse.death", SoundCategory.NEUTRAL), - AMBIENT_WEATHER_RAIN("ambient.weather.rain", "weather.rain.above", SoundCategory.WEATHER), - PORTAL_TRIGGER("portal.trigger", "block.portal.trigger", SoundCategory.BLOCK), - RANDOM_CHESTOPEN("random.chestopen", "block.enderchest.open", SoundCategory.BLOCK), - MOB_HORSE_LAND("mob.horse.land", "entity.horse.land", SoundCategory.NEUTRAL), - MOB_SILVERFISH_STEP("mob.silverfish.step", "entity.silverfish.step", SoundCategory.HOSTILE), - MOB_BAT_TAKEOFF("mob.bat.takeoff", "entity.bat.takeoff", SoundCategory.NEUTRAL), - MOB_VILLAGER_NO("mob.villager.no", "entity.villager.no", SoundCategory.NEUTRAL), - GAME_HOSTILE_HURT_FALL_BIG("game.hostile.hurt.fall.big", "entity.hostile.big_fall", SoundCategory.HOSTILE), - MOB_IRONGOLEM_WALK("mob.irongolem.walk", "entity.irongolem.step", SoundCategory.NEUTRAL), - NOTE_HAT("note.hat", "block.note.hat", SoundCategory.RECORD), - MOB_ZOMBIE_METAL("mob.zombie.metal", "entity.zombie.attack_iron_door", SoundCategory.HOSTILE), - MOB_VILLAGER_HAGGLE("mob.villager.haggle", "entity.villager.trading", SoundCategory.NEUTRAL), - MOB_GHAST_FIREBALL("mob.ghast.fireball", "entity.blaze.shoot", SoundCategory.HOSTILE), - MOB_IRONGOLEM_DEATH("mob.irongolem.death", "entity.irongolem.death", SoundCategory.NEUTRAL), - RANDOM_BREAK("random.break", "item.shield.break", SoundCategory.PLAYER), - MOB_ZOMBIE_REMEDY("mob.zombie.remedy", "entity.zombie_villager.cure", SoundCategory.HOSTILE), - RANDOM_BOW("random.bow", "entity.splash_potion.throw", SoundCategory.NEUTRAL), - MOB_VILLAGER_IDLE("mob.villager.idle", "entity.villager.ambient", SoundCategory.NEUTRAL), - STEP_CLOTH("step.cloth", "block.cloth.fall", SoundCategory.NEUTRAL), - MOB_SILVERFISH_HIT("mob.silverfish.hit", "entity.endermite.hurt", SoundCategory.HOSTILE), - LIQUID_LAVA("liquid.lava", "block.lava.ambient", SoundCategory.BLOCK), - GAME_NEUTRAL_HURT_FALL_BIG("game.neutral.hurt.fall.big", "entity.hostile.big_fall", SoundCategory.NEUTRAL), - FIRE_FIRE("fire.fire", "block.fire.ambient", SoundCategory.BLOCK), - MOB_ZOMBIE_WOOD("mob.zombie.wood", "entity.zombie.attack_door_wood", SoundCategory.HOSTILE), - MOB_CHICKEN_STEP("mob.chicken.step", "entity.chicken.step", SoundCategory.NEUTRAL), - MOB_GUARDIAN_LAND_HIT("mob.guardian.land.hit", "entity.guardian.hurt_land", SoundCategory.HOSTILE), - MOB_CHICKEN_PLOP("mob.chicken.plop", "entity.donkey.chest", SoundCategory.NEUTRAL), - MOB_ENDERDRAGON_WINGS("mob.enderdragon.wings", "entity.enderdragon.flap", SoundCategory.HOSTILE), - STEP_GRASS("step.grass", "block.grass.hit", SoundCategory.NEUTRAL), - MOB_HORSE_BREATHE("mob.horse.breathe", "entity.horse.breathe", SoundCategory.NEUTRAL), - GAME_PLAYER_HURT_FALL_BIG("game.player.hurt.fall.big", "entity.hostile.big_fall", SoundCategory.PLAYER), - MOB_HORSE_DONKEY_IDLE("mob.horse.donkey.idle", "entity.donkey.ambient", SoundCategory.NEUTRAL), - MOB_SPIDER_STEP("mob.spider.step", "entity.spider.step", SoundCategory.HOSTILE), - GAME_NEUTRAL_HURT("game.neutral.hurt", "entity.player.death", SoundCategory.NEUTRAL), - MOB_COW_SAY("mob.cow.say", "entity.cow.ambient", SoundCategory.NEUTRAL), - MOB_HORSE_JUMP("mob.horse.jump", "entity.horse.jump", SoundCategory.NEUTRAL), - MOB_HORSE_SOFT("mob.horse.soft", "entity.horse.step", SoundCategory.NEUTRAL), - GAME_NEUTRAL_SWIM_SPLASH("game.neutral.swim.splash", "entity.generic.splash", SoundCategory.NEUTRAL), - MOB_GUARDIAN_HIT("mob.guardian.hit", "entity.guardian.hurt", SoundCategory.HOSTILE), - MOB_ENDERDRAGON_END("mob.enderdragon.end", "entity.enderdragon.death", SoundCategory.HOSTILE), - MOB_ZOMBIE_STEP("mob.zombie.step", "entity.zombie.step", SoundCategory.HOSTILE), - MOB_ENDERDRAGON_GROWL("mob.enderdragon.growl", "entity.enderdragon.growl", SoundCategory.HOSTILE), - MOB_WOLF_SHAKE("mob.wolf.shake", "entity.wolf.shake", SoundCategory.NEUTRAL), - MOB_ENDERMEN_DEATH("mob.endermen.death", "entity.endermen.death", SoundCategory.HOSTILE), - RANDOM_ANVIL_LAND("random.anvil_land", "block.anvil.land", SoundCategory.BLOCK), - GAME_HOSTILE_HURT("game.hostile.hurt", "entity.player.death", SoundCategory.HOSTILE), - MINECART_INSIDE("minecart.inside", "entity.minecart.inside", SoundCategory.PLAYER), - MOB_SLIME_BIG("mob.slime.big", "entity.slime.death", SoundCategory.HOSTILE), - LIQUID_WATER("liquid.water", "block.water.ambient", SoundCategory.BLOCK), - MOB_PIG_SAY("mob.pig.say", "entity.pig.ambient", SoundCategory.NEUTRAL), - MOB_WITHER_SHOOT("mob.wither.shoot", "entity.wither.shoot", SoundCategory.HOSTILE), - ITEM_FIRECHARGE_USE("item.fireCharge.use", "entity.blaze.shoot", SoundCategory.BLOCK), - STEP_SAND("step.sand", "block.sand.fall", SoundCategory.NEUTRAL), - MOB_IRONGOLEM_HIT("mob.irongolem.hit", "entity.irongolem.hurt", SoundCategory.NEUTRAL), - MOB_HORSE_DEATH("mob.horse.death", "entity.horse.death", SoundCategory.NEUTRAL), - MOB_BAT_HURT("mob.bat.hurt", "entity.bat.hurt", SoundCategory.NEUTRAL), - MOB_GHAST_AFFECTIONATE_SCREAM("mob.ghast.affectionate_scream", "entity.ghast.scream", SoundCategory.HOSTILE), - MOB_GUARDIAN_ELDER_IDLE("mob.guardian.elder.idle", "entity.elder_guardian.ambient", SoundCategory.HOSTILE), - MOB_ZOMBIEPIG_ZPIGDEATH("mob.zombiepig.zpigdeath", "entity.zombie_pig.death", SoundCategory.HOSTILE), - AMBIENT_WEATHER_THUNDER("ambient.weather.thunder", "entity.lightning.thunder", SoundCategory.WEATHER), - MINECART_BASE("minecart.base", "entity.minecart.riding", SoundCategory.NEUTRAL), - STEP_LADDER("step.ladder", "block.ladder.hit", SoundCategory.NEUTRAL), - MOB_HORSE_DONKEY_ANGRY("mob.horse.donkey.angry", "entity.donkey.angry", SoundCategory.NEUTRAL), - AMBIENT_CAVE_CAVE("ambient.cave.cave", "ambient.cave", SoundCategory.AMBIENT), - FIREWORKS_BLAST_FAR("fireworks.blast_far", "entity.firework.blast_far", SoundCategory.AMBIENT), - GAME_NEUTRAL_HURT_FALL_SMALL("game.neutral.hurt.fall.small", "entity.generic.small_fall", SoundCategory.NEUTRAL), - GAME_HOSTILE_SWIM_SPLASH("game.hostile.swim.splash", "entity.generic.splash", SoundCategory.HOSTILE), - RANDOM_DRINK("random.drink", "entity.generic.drink", SoundCategory.PLAYER), - GAME_HOSTILE_DIE("game.hostile.die", "entity.player.death", SoundCategory.HOSTILE), - MOB_CAT_HISS("mob.cat.hiss", "entity.cat.hiss", SoundCategory.NEUTRAL), - NOTE_BD("note.bd", "block.note.basedrum", SoundCategory.RECORD), - MOB_SPIDER_SAY("mob.spider.say", "entity.spider.hurt", SoundCategory.HOSTILE), - STEP_STONE("step.stone", "block.anvil.hit", SoundCategory.NEUTRAL), - RANDOM_LEVELUP("random.levelup", "entity.player.levelup", SoundCategory.PLAYER), - LIQUID_LAVAPOP("liquid.lavapop", "block.lava.pop", SoundCategory.BLOCK), - MOB_SHEEP_SAY("mob.sheep.say", "entity.sheep.ambient", SoundCategory.NEUTRAL), - MOB_SKELETON_SAY("mob.skeleton.say", "entity.skeleton.ambient", SoundCategory.HOSTILE), - MOB_BLAZE_BREATHE("mob.blaze.breathe", "entity.blaze.ambient", SoundCategory.HOSTILE), - MOB_BAT_IDLE("mob.bat.idle", "entity.bat.ambient", SoundCategory.NEUTRAL), - MOB_MAGMACUBE_BIG("mob.magmacube.big", "entity.magmacube.squish", SoundCategory.HOSTILE), - MOB_HORSE_IDLE("mob.horse.idle", "entity.horse.ambient", SoundCategory.NEUTRAL), - GAME_HOSTILE_HURT_FALL_SMALL("game.hostile.hurt.fall.small", "entity.generic.small_fall", SoundCategory.HOSTILE), - MOB_HORSE_ZOMBIE_HIT("mob.horse.zombie.hit", "entity.zombie_horse.hurt", SoundCategory.NEUTRAL), - MOB_IRONGOLEM_THROW("mob.irongolem.throw", "entity.irongolem.attack", SoundCategory.NEUTRAL), - DIG_CLOTH("dig.cloth", "block.cloth.place", SoundCategory.BLOCK), - STEP_GRAVEL("step.gravel", "block.gravel.hit", SoundCategory.NEUTRAL), - MOB_SILVERFISH_SAY("mob.silverfish.say", "entity.silverfish.ambient", SoundCategory.HOSTILE), - MOB_CAT_PURR("mob.cat.purr", "entity.cat.purr", SoundCategory.NEUTRAL), - MOB_ZOMBIE_INFECT("mob.zombie.infect", "entity.zombie.infect", SoundCategory.HOSTILE), - RANDOM_EAT("random.eat", "entity.generic.eat", SoundCategory.PLAYER), - MOB_WOLF_BARK("mob.wolf.bark", "entity.wolf.ambient", SoundCategory.NEUTRAL), - GAME_TNT_PRIMED("game.tnt.primed", "entity.creeper.primed", SoundCategory.BLOCK), - MOB_SHEEP_STEP("mob.sheep.step", "entity.sheep.step", SoundCategory.NEUTRAL), - MOB_ZOMBIE_DEATH("mob.zombie.death", "entity.zombie.death", SoundCategory.HOSTILE), - RANDOM_DOOR_OPEN("random.door_open", "null", SoundCategory.BLOCK), - MOB_ENDERMEN_PORTAL("mob.endermen.portal", "entity.endermen.teleport", SoundCategory.HOSTILE), - MOB_HORSE_ANGRY("mob.horse.angry", "entity.horse.angry", SoundCategory.NEUTRAL), - MOB_WOLF_GROWL("mob.wolf.growl", "entity.wolf.growl", SoundCategory.NEUTRAL), - DIG_SNOW("dig.snow", "block.snow.place", SoundCategory.BLOCK), - TILE_PISTON_OUT("tile.piston.out", "block.piston.extend", SoundCategory.BLOCK), - RANDOM_BURP("random.burp", "entity.player.burp", SoundCategory.PLAYER), - MOB_COW_STEP("mob.cow.step", "entity.cow.step", SoundCategory.NEUTRAL), - MOB_WITHER_HURT("mob.wither.hurt", "entity.wither.hurt", SoundCategory.HOSTILE), - MOB_GUARDIAN_LAND_DEATH("mob.guardian.land.death", "entity.elder_guardian.death_land", SoundCategory.HOSTILE), - MOB_CHICKEN_HURT("mob.chicken.hurt", "entity.chicken.death", SoundCategory.NEUTRAL), - MOB_WOLF_STEP("mob.wolf.step", "entity.wolf.step", SoundCategory.NEUTRAL), - MOB_WOLF_DEATH("mob.wolf.death", "entity.wolf.death", SoundCategory.NEUTRAL), - MOB_WOLF_WHINE("mob.wolf.whine", "entity.wolf.whine", SoundCategory.NEUTRAL), - NOTE_PLING("note.pling", "block.note.pling", SoundCategory.RECORD), - GAME_PLAYER_HURT_FALL_SMALL("game.player.hurt.fall.small", "entity.generic.small_fall", SoundCategory.PLAYER), - MOB_CAT_PURREOW("mob.cat.purreow", "entity.cat.purreow", SoundCategory.NEUTRAL), - FIREWORKS_LARGEBLAST_FAR("fireworks.largeBlast_far", "entity.firework.large_blast_far", SoundCategory.AMBIENT), - MOB_SKELETON_HURT("mob.skeleton.hurt", "entity.skeleton.hurt", SoundCategory.HOSTILE), - MOB_SPIDER_DEATH("mob.spider.death", "entity.spider.death", SoundCategory.HOSTILE), - RANDOM_ANVIL_BREAK("random.anvil_break", "block.anvil.destroy", SoundCategory.BLOCK), - MOB_WITHER_IDLE("mob.wither.idle", "entity.wither.ambient", SoundCategory.HOSTILE), - MOB_GUARDIAN_ELDER_HIT("mob.guardian.elder.hit", "entity.elder_guardian.hurt", SoundCategory.HOSTILE), - MOB_ENDERMEN_SCREAM("mob.endermen.scream", "entity.endermen.scream", SoundCategory.HOSTILE), - MOB_CAT_HITT("mob.cat.hitt", "entity.cat.hurt", SoundCategory.NEUTRAL), - MOB_MAGMACUBE_SMALL("mob.magmacube.small", "entity.small_magmacube.squish", SoundCategory.HOSTILE), - FIRE_IGNITE("fire.ignite", "item.flintandsteel.use", SoundCategory.BLOCK, true), - MOB_ENDERDRAGON_HIT("mob.enderdragon.hit", "entity.enderdragon.hurt", SoundCategory.HOSTILE), - MOB_ZOMBIE_HURT("mob.zombie.hurt", "entity.zombie_villager.hurt", SoundCategory.HOSTILE), - RANDOM_EXPLODE("random.explode", "block.end_gateway.spawn", SoundCategory.BLOCK), - MOB_SLIME_ATTACK("mob.slime.attack", "entity.slime.attack", SoundCategory.HOSTILE), - MOB_MAGMACUBE_JUMP("mob.magmacube.jump", "entity.magmacube.jump", SoundCategory.HOSTILE), - RANDOM_SPLASH("random.splash", "entity.bobber.splash", SoundCategory.PLAYER), - MOB_HORSE_SKELETON_HIT("mob.horse.skeleton.hit", "entity.skeleton_horse.hurt", SoundCategory.NEUTRAL), - MOB_GHAST_MOAN("mob.ghast.moan", "entity.ghast.ambient", SoundCategory.HOSTILE), - MOB_GUARDIAN_CURSE("mob.guardian.curse", "entity.elder_guardian.curse", SoundCategory.HOSTILE), - GAME_POTION_SMASH("game.potion.smash", "block.glass.break", SoundCategory.NEUTRAL), - NOTE_BASSATTACK("note.bassattack", "block.note.bass", SoundCategory.RECORD), - GUI_BUTTON_PRESS("gui.button.press", "block.wood_pressureplate.click_on", SoundCategory.MASTER), - RANDOM_ORB("random.orb", "entity.experience_orb.pickup", SoundCategory.PLAYER), - MOB_ZOMBIE_WOODBREAK("mob.zombie.woodbreak", "entity.zombie.break_door_wood", SoundCategory.HOSTILE), - MOB_HORSE_ARMOR("mob.horse.armor", "entity.horse.armor", SoundCategory.NEUTRAL), - TILE_PISTON_IN("tile.piston.in", "block.piston.contract", SoundCategory.BLOCK), - MOB_CAT_MEOW("mob.cat.meow", "entity.cat.ambient", SoundCategory.NEUTRAL), - MOB_PIG_STEP("mob.pig.step", "entity.pig.step", SoundCategory.NEUTRAL), - STEP_WOOD("step.wood", "block.wood.step", SoundCategory.NEUTRAL), - PORTAL_TRAVEL("portal.travel", "block.portal.travel", SoundCategory.PLAYER), - MOB_GUARDIAN_DEATH("mob.guardian.death", "entity.guardian.death", SoundCategory.HOSTILE), - MOB_SKELETON_DEATH("mob.skeleton.death", "entity.skeleton.death", SoundCategory.HOSTILE), - MOB_HORSE_HIT("mob.horse.hit", "entity.horse.hurt", SoundCategory.NEUTRAL), - MOB_VILLAGER_HIT("mob.villager.hit", "entity.villager.hurt", SoundCategory.NEUTRAL), - MOB_HORSE_SKELETON_IDLE("mob.horse.skeleton.idle", "entity.skeleton_horse.ambient", SoundCategory.NEUTRAL), - RECORDS_CHIRP("records.chirp", "record.chirp", SoundCategory.RECORD), - MOB_RABBIT_HURT("mob.rabbit.hurt", "entity.rabbit.hurt", SoundCategory.NEUTRAL), - RECORDS_STAL("records.stal", "record.stal", SoundCategory.RECORD), - MUSIC_GAME_NETHER("music.game.nether", "music.nether", SoundCategory.MUSIC), - MUSIC_MENU("music.menu", "music.menu", SoundCategory.MUSIC), - RECORDS_MELLOHI("records.mellohi", "record.mellohi", SoundCategory.RECORD), - RECORDS_CAT("records.cat", "record.cat", SoundCategory.RECORD), - RECORDS_FAR("records.far", "record.far", SoundCategory.RECORD), - MUSIC_GAME_END_DRAGON("music.game.end.dragon", "music.dragon", SoundCategory.MUSIC), - MOB_RABBIT_DEATH("mob.rabbit.death", "entity.rabbit.death", SoundCategory.NEUTRAL), - MOB_RABBIT_IDLE("mob.rabbit.idle", "entity.rabbit.ambient", SoundCategory.NEUTRAL), - MUSIC_GAME_END("music.game.end", "music.end", SoundCategory.MUSIC), - MUSIC_GAME("music.game", "music.game", SoundCategory.MUSIC), - MOB_GUARDIAN_IDLE("mob.guardian.idle", "null", SoundCategory.HOSTILE), - RECORDS_WARD("records.ward", "record.ward", SoundCategory.RECORD), - RECORDS_13("records.13", "record.13", SoundCategory.RECORD), - MOB_RABBIT_HOP("mob.rabbit.hop", "entity.rabbit.jump", SoundCategory.NEUTRAL), - RECORDS_STRAD("records.strad", "record.strad", SoundCategory.RECORD), - RECORDS_11("records.11", "record.11", SoundCategory.RECORD), - RECORDS_MALL("records.mall", "record.mall", SoundCategory.RECORD), - RECORDS_BLOCKS("records.blocks", "record.blocks", SoundCategory.RECORD), - RECORDS_WAIT("records.wait", "record.wait", SoundCategory.RECORD), - MUSIC_GAME_END_CREDITS("music.game.end.credits", "music.credits", SoundCategory.MUSIC), - MUSIC_GAME_CREATIVE("music.game.creative", "music.creative", SoundCategory.MUSIC); - - private final String name; - private final String newName; - private final SoundCategory category; - private final boolean breaksound; - - SoundEffect(String name, String newname, SoundCategory cat) { - this.category = cat; - this.newName = newname; - this.name = name; - this.breaksound = name.startsWith("dig."); - } - - SoundEffect(String name, String newname, SoundCategory cat, boolean shouldIgnore) { - this.category = cat; - this.newName = newname; - this.name = name; - this.breaksound = name.startsWith("dig.") || shouldIgnore; - } - - public static SoundEffect getByName(String name) { - name = name.toLowerCase(); - for (SoundEffect e : SoundEffect.values()) { - if (e.getName().equals(name)) - return e; - } - return null; - } - -} +package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds; + +import lombok.Getter; + +@Getter +public enum SoundEffect { + + MOB_HORSE_ZOMBIE_IDLE("mob.horse.zombie.idle", "entity.zombie_horse.ambient", SoundCategory.NEUTRAL), + NOTE_SNARE("note.snare", "block.note.snare", SoundCategory.RECORD), + RANDOM_WOOD_CLICK("random.wood_click", "block.wood_button.click_on", SoundCategory.BLOCK), + DIG_GRAVEL("dig.gravel", "block.gravel.place", SoundCategory.BLOCK), + RANDOM_BOWHIT("random.bowhit", "block.tripwire.detach", SoundCategory.NEUTRAL), + DIG_GLASS("dig.glass", "block.glass.break", SoundCategory.BLOCK), + MOB_ZOMBIE_SAY("mob.zombie.say", "entity.zombie_villager.ambient", SoundCategory.HOSTILE), + MOB_PIG_DEATH("mob.pig.death", "entity.pig.death", SoundCategory.NEUTRAL), + MOB_HORSE_DONKEY_HIT("mob.horse.donkey.hit", "entity.donkey.hurt", SoundCategory.NEUTRAL), + GAME_NEUTRAL_SWIM("game.neutral.swim", "entity.player.swim", SoundCategory.NEUTRAL), + GAME_PLAYER_SWIM("game.player.swim", "entity.player.swim", SoundCategory.PLAYER), + MOB_ENDERMEN_IDLE("mob.endermen.idle", "entity.endermen.ambient", SoundCategory.HOSTILE), + PORTAL_PORTAL("portal.portal", "block.portal.ambient", SoundCategory.BLOCK), + RANDOM_FIZZ("random.fizz", "entity.generic.extinguish_fire", SoundCategory.BLOCK), + NOTE_HARP("note.harp", "block.note.harp", SoundCategory.RECORD), + STEP_SNOW("step.snow", "block.snow.step", SoundCategory.NEUTRAL), + RANDOM_SUCCESSFUL_HIT("random.successful_hit", "entity.arrow.hit_player", SoundCategory.PLAYER), + MOB_ZOMBIEPIG_ZPIGHURT("mob.zombiepig.zpighurt", "entity.zombie_pig.hurt", SoundCategory.HOSTILE), + MOB_WOLF_HOWL("mob.wolf.howl", "entity.wolf.howl", SoundCategory.NEUTRAL), + FIREWORKS_LAUNCH("fireworks.launch", "entity.firework.launch", SoundCategory.AMBIENT), + MOB_COW_HURT("mob.cow.hurt", "entity.cow.death", SoundCategory.NEUTRAL), + FIREWORKS_LARGEBLAST("fireworks.largeBlast", "entity.firework.large_blast", SoundCategory.AMBIENT), + MOB_BLAZE_HIT("mob.blaze.hit", "entity.blaze.hurt", SoundCategory.HOSTILE), + MOB_VILLAGER_DEATH("mob.villager.death", "entity.villager.death", SoundCategory.NEUTRAL), + MOB_BLAZE_DEATH("mob.blaze.death", "entity.blaze.death", SoundCategory.HOSTILE), + MOB_HORSE_ZOMBIE_DEATH("mob.horse.zombie.death", "entity.zombie_horse.death", SoundCategory.NEUTRAL), + MOB_SILVERFISH_KILL("mob.silverfish.kill", "entity.endermite.death", SoundCategory.HOSTILE), + MOB_WOLF_PANTING("mob.wolf.panting", "entity.wolf.pant", SoundCategory.NEUTRAL), + NOTE_BASS("note.bass", "null", SoundCategory.RECORD), + DIG_STONE("dig.stone", "block.glass.place", SoundCategory.BLOCK), + MOB_ENDERMEN_STARE("mob.endermen.stare", "entity.endermen.stare", SoundCategory.HOSTILE), + GAME_PLAYER_SWIM_SPLASH("game.player.swim.splash", "entity.generic.splash", SoundCategory.BLOCK), + MOB_SLIME_SMALL("mob.slime.small", "block.slime.hit", SoundCategory.HOSTILE), + MOB_GHAST_DEATH("mob.ghast.death", "entity.ghast.death", SoundCategory.HOSTILE), + MOB_GUARDIAN_ATTACK("mob.guardian.attack", "entity.guardian.attack", SoundCategory.HOSTILE), + RANDOM_CLICK("random.click", "block.wood_pressureplate.click_on", SoundCategory.BLOCK), + MOB_ZOMBIEPIG_ZPIG("mob.zombiepig.zpig", "entity.zombie_pig.ambient", SoundCategory.HOSTILE), + GAME_PLAYER_DIE("game.player.die", "entity.player.death", SoundCategory.PLAYER), + FIREWORKS_TWINKLE_FAR("fireworks.twinkle_far", "entity.firework.twinkle_far", SoundCategory.AMBIENT), + MOB_GUARDIAN_LAND_IDLE("mob.guardian.land.idle", "entity.guardian.ambient_land", SoundCategory.HOSTILE), + DIG_GRASS("dig.grass", "block.grass.place", SoundCategory.BLOCK), + MOB_SKELETON_STEP("mob.skeleton.step", "entity.skeleton.step", SoundCategory.HOSTILE), + MOB_WITHER_DEATH("mob.wither.death", "entity.wither.death", SoundCategory.HOSTILE), + MOB_WOLF_HURT("mob.wolf.hurt", "entity.wolf.hurt", SoundCategory.NEUTRAL), + MOB_HORSE_LEATHER("mob.horse.leather", "entity.horse.saddle", SoundCategory.NEUTRAL), + MOB_BAT_LOOP("mob.bat.loop", "entity.bat.loop", SoundCategory.NEUTRAL), + MOB_GHAST_SCREAM("mob.ghast.scream", "entity.ghast.hurt", SoundCategory.HOSTILE), + GAME_PLAYER_HURT("game.player.hurt", "entity.player.death", SoundCategory.PLAYER), + GAME_NEUTRAL_DIE("game.neutral.die", "entity.player.death", SoundCategory.NEUTRAL), + MOB_CREEPER_DEATH("mob.creeper.death", "entity.creeper.death", SoundCategory.HOSTILE), + MOB_HORSE_GALLOP("mob.horse.gallop", "entity.horse.gallop", SoundCategory.NEUTRAL), + MOB_WITHER_SPAWN("mob.wither.spawn", "entity.wither.spawn", SoundCategory.HOSTILE), + MOB_ENDERMEN_HIT("mob.endermen.hit", "entity.endermen.hurt", SoundCategory.HOSTILE), + MOB_CREEPER_SAY("mob.creeper.say", "entity.creeper.hurt", SoundCategory.HOSTILE), + MOB_HORSE_WOOD("mob.horse.wood", "entity.horse.step_wood", SoundCategory.NEUTRAL), + MOB_ZOMBIE_UNFECT("mob.zombie.unfect", "entity.zombie_villager.converted", SoundCategory.HOSTILE), + RANDOM_ANVIL_USE("random.anvil_use", "block.anvil.use", SoundCategory.BLOCK), + RANDOM_CHESTCLOSED("random.chestclosed", "block.enderchest.close", SoundCategory.BLOCK), + MOB_SHEEP_SHEAR("mob.sheep.shear", "entity.sheep.shear", SoundCategory.NEUTRAL), + RANDOM_POP("random.pop", "entity.item.pickup", SoundCategory.PLAYER), + MOB_BAT_DEATH("mob.bat.death", "entity.bat.death", SoundCategory.NEUTRAL), + DIG_WOOD("dig.wood", "block.ladder.break", SoundCategory.BLOCK), + MOB_HORSE_DONKEY_DEATH("mob.horse.donkey.death", "entity.donkey.death", SoundCategory.NEUTRAL), + FIREWORKS_BLAST("fireworks.blast", "entity.firework.blast", SoundCategory.AMBIENT), + MOB_ZOMBIEPIG_ZPIGANGRY("mob.zombiepig.zpigangry", "entity.zombie_pig.angry", SoundCategory.HOSTILE), + GAME_HOSTILE_SWIM("game.hostile.swim", "entity.player.swim", SoundCategory.HOSTILE), + MOB_GUARDIAN_FLOP("mob.guardian.flop", "entity.guardian.flop", SoundCategory.HOSTILE), + MOB_VILLAGER_YES("mob.villager.yes", "entity.villager.yes", SoundCategory.NEUTRAL), + MOB_GHAST_CHARGE("mob.ghast.charge", "entity.ghast.warn", SoundCategory.HOSTILE), + CREEPER_PRIMED("creeper.primed", "entity.creeper.primed", SoundCategory.HOSTILE), + DIG_SAND("dig.sand", "block.sand.break", SoundCategory.BLOCK), + MOB_CHICKEN_SAY("mob.chicken.say", "entity.chicken.ambient", SoundCategory.NEUTRAL), + RANDOM_DOOR_CLOSE("random.door_close", "null", SoundCategory.BLOCK), + MOB_GUARDIAN_ELDER_DEATH("mob.guardian.elder.death", "entity.elder_guardian.death", SoundCategory.HOSTILE), + FIREWORKS_TWINKLE("fireworks.twinkle", "entity.firework.twinkle", SoundCategory.AMBIENT), + MOB_HORSE_SKELETON_DEATH("mob.horse.skeleton.death", "entity.skeleton_horse.death", SoundCategory.NEUTRAL), + AMBIENT_WEATHER_RAIN("ambient.weather.rain", "weather.rain.above", SoundCategory.WEATHER), + PORTAL_TRIGGER("portal.trigger", "block.portal.trigger", SoundCategory.BLOCK), + RANDOM_CHESTOPEN("random.chestopen", "block.enderchest.open", SoundCategory.BLOCK), + MOB_HORSE_LAND("mob.horse.land", "entity.horse.land", SoundCategory.NEUTRAL), + MOB_SILVERFISH_STEP("mob.silverfish.step", "entity.silverfish.step", SoundCategory.HOSTILE), + MOB_BAT_TAKEOFF("mob.bat.takeoff", "entity.bat.takeoff", SoundCategory.NEUTRAL), + MOB_VILLAGER_NO("mob.villager.no", "entity.villager.no", SoundCategory.NEUTRAL), + GAME_HOSTILE_HURT_FALL_BIG("game.hostile.hurt.fall.big", "entity.hostile.big_fall", SoundCategory.HOSTILE), + MOB_IRONGOLEM_WALK("mob.irongolem.walk", "entity.irongolem.step", SoundCategory.NEUTRAL), + NOTE_HAT("note.hat", "block.note.hat", SoundCategory.RECORD), + MOB_ZOMBIE_METAL("mob.zombie.metal", "entity.zombie.attack_iron_door", SoundCategory.HOSTILE), + MOB_VILLAGER_HAGGLE("mob.villager.haggle", "entity.villager.trading", SoundCategory.NEUTRAL), + MOB_GHAST_FIREBALL("mob.ghast.fireball", "entity.blaze.shoot", SoundCategory.HOSTILE), + MOB_IRONGOLEM_DEATH("mob.irongolem.death", "entity.irongolem.death", SoundCategory.NEUTRAL), + RANDOM_BREAK("random.break", "item.shield.break", SoundCategory.PLAYER), + MOB_ZOMBIE_REMEDY("mob.zombie.remedy", "entity.zombie_villager.cure", SoundCategory.HOSTILE), + RANDOM_BOW("random.bow", "entity.splash_potion.throw", SoundCategory.NEUTRAL), + MOB_VILLAGER_IDLE("mob.villager.idle", "entity.villager.ambient", SoundCategory.NEUTRAL), + STEP_CLOTH("step.cloth", "block.cloth.fall", SoundCategory.NEUTRAL), + MOB_SILVERFISH_HIT("mob.silverfish.hit", "entity.endermite.hurt", SoundCategory.HOSTILE), + LIQUID_LAVA("liquid.lava", "block.lava.ambient", SoundCategory.BLOCK), + GAME_NEUTRAL_HURT_FALL_BIG("game.neutral.hurt.fall.big", "entity.hostile.big_fall", SoundCategory.NEUTRAL), + FIRE_FIRE("fire.fire", "block.fire.ambient", SoundCategory.BLOCK), + MOB_ZOMBIE_WOOD("mob.zombie.wood", "entity.zombie.attack_door_wood", SoundCategory.HOSTILE), + MOB_CHICKEN_STEP("mob.chicken.step", "entity.chicken.step", SoundCategory.NEUTRAL), + MOB_GUARDIAN_LAND_HIT("mob.guardian.land.hit", "entity.guardian.hurt_land", SoundCategory.HOSTILE), + MOB_CHICKEN_PLOP("mob.chicken.plop", "entity.donkey.chest", SoundCategory.NEUTRAL), + MOB_ENDERDRAGON_WINGS("mob.enderdragon.wings", "entity.enderdragon.flap", SoundCategory.HOSTILE), + STEP_GRASS("step.grass", "block.grass.hit", SoundCategory.NEUTRAL), + MOB_HORSE_BREATHE("mob.horse.breathe", "entity.horse.breathe", SoundCategory.NEUTRAL), + GAME_PLAYER_HURT_FALL_BIG("game.player.hurt.fall.big", "entity.hostile.big_fall", SoundCategory.PLAYER), + MOB_HORSE_DONKEY_IDLE("mob.horse.donkey.idle", "entity.donkey.ambient", SoundCategory.NEUTRAL), + MOB_SPIDER_STEP("mob.spider.step", "entity.spider.step", SoundCategory.HOSTILE), + GAME_NEUTRAL_HURT("game.neutral.hurt", "entity.player.death", SoundCategory.NEUTRAL), + MOB_COW_SAY("mob.cow.say", "entity.cow.ambient", SoundCategory.NEUTRAL), + MOB_HORSE_JUMP("mob.horse.jump", "entity.horse.jump", SoundCategory.NEUTRAL), + MOB_HORSE_SOFT("mob.horse.soft", "entity.horse.step", SoundCategory.NEUTRAL), + GAME_NEUTRAL_SWIM_SPLASH("game.neutral.swim.splash", "entity.generic.splash", SoundCategory.NEUTRAL), + MOB_GUARDIAN_HIT("mob.guardian.hit", "entity.guardian.hurt", SoundCategory.HOSTILE), + MOB_ENDERDRAGON_END("mob.enderdragon.end", "entity.enderdragon.death", SoundCategory.HOSTILE), + MOB_ZOMBIE_STEP("mob.zombie.step", "entity.zombie.step", SoundCategory.HOSTILE), + MOB_ENDERDRAGON_GROWL("mob.enderdragon.growl", "entity.enderdragon.growl", SoundCategory.HOSTILE), + MOB_WOLF_SHAKE("mob.wolf.shake", "entity.wolf.shake", SoundCategory.NEUTRAL), + MOB_ENDERMEN_DEATH("mob.endermen.death", "entity.endermen.death", SoundCategory.HOSTILE), + RANDOM_ANVIL_LAND("random.anvil_land", "block.anvil.land", SoundCategory.BLOCK), + GAME_HOSTILE_HURT("game.hostile.hurt", "entity.player.death", SoundCategory.HOSTILE), + MINECART_INSIDE("minecart.inside", "entity.minecart.inside", SoundCategory.PLAYER), + MOB_SLIME_BIG("mob.slime.big", "entity.slime.death", SoundCategory.HOSTILE), + LIQUID_WATER("liquid.water", "block.water.ambient", SoundCategory.BLOCK), + MOB_PIG_SAY("mob.pig.say", "entity.pig.ambient", SoundCategory.NEUTRAL), + MOB_WITHER_SHOOT("mob.wither.shoot", "entity.wither.shoot", SoundCategory.HOSTILE), + ITEM_FIRECHARGE_USE("item.fireCharge.use", "entity.blaze.shoot", SoundCategory.BLOCK), + STEP_SAND("step.sand", "block.sand.fall", SoundCategory.NEUTRAL), + MOB_IRONGOLEM_HIT("mob.irongolem.hit", "entity.irongolem.hurt", SoundCategory.NEUTRAL), + MOB_HORSE_DEATH("mob.horse.death", "entity.horse.death", SoundCategory.NEUTRAL), + MOB_BAT_HURT("mob.bat.hurt", "entity.bat.hurt", SoundCategory.NEUTRAL), + MOB_GHAST_AFFECTIONATE_SCREAM("mob.ghast.affectionate_scream", "entity.ghast.scream", SoundCategory.HOSTILE), + MOB_GUARDIAN_ELDER_IDLE("mob.guardian.elder.idle", "entity.elder_guardian.ambient", SoundCategory.HOSTILE), + MOB_ZOMBIEPIG_ZPIGDEATH("mob.zombiepig.zpigdeath", "entity.zombie_pig.death", SoundCategory.HOSTILE), + AMBIENT_WEATHER_THUNDER("ambient.weather.thunder", "entity.lightning.thunder", SoundCategory.WEATHER), + MINECART_BASE("minecart.base", "entity.minecart.riding", SoundCategory.NEUTRAL), + STEP_LADDER("step.ladder", "block.ladder.hit", SoundCategory.NEUTRAL), + MOB_HORSE_DONKEY_ANGRY("mob.horse.donkey.angry", "entity.donkey.angry", SoundCategory.NEUTRAL), + AMBIENT_CAVE_CAVE("ambient.cave.cave", "ambient.cave", SoundCategory.AMBIENT), + FIREWORKS_BLAST_FAR("fireworks.blast_far", "entity.firework.blast_far", SoundCategory.AMBIENT), + GAME_NEUTRAL_HURT_FALL_SMALL("game.neutral.hurt.fall.small", "entity.generic.small_fall", SoundCategory.NEUTRAL), + GAME_HOSTILE_SWIM_SPLASH("game.hostile.swim.splash", "entity.generic.splash", SoundCategory.HOSTILE), + RANDOM_DRINK("random.drink", "entity.generic.drink", SoundCategory.PLAYER), + GAME_HOSTILE_DIE("game.hostile.die", "entity.player.death", SoundCategory.HOSTILE), + MOB_CAT_HISS("mob.cat.hiss", "entity.cat.hiss", SoundCategory.NEUTRAL), + NOTE_BD("note.bd", "block.note.basedrum", SoundCategory.RECORD), + MOB_SPIDER_SAY("mob.spider.say", "entity.spider.hurt", SoundCategory.HOSTILE), + STEP_STONE("step.stone", "block.anvil.hit", SoundCategory.NEUTRAL), + RANDOM_LEVELUP("random.levelup", "entity.player.levelup", SoundCategory.PLAYER), + LIQUID_LAVAPOP("liquid.lavapop", "block.lava.pop", SoundCategory.BLOCK), + MOB_SHEEP_SAY("mob.sheep.say", "entity.sheep.ambient", SoundCategory.NEUTRAL), + MOB_SKELETON_SAY("mob.skeleton.say", "entity.skeleton.ambient", SoundCategory.HOSTILE), + MOB_BLAZE_BREATHE("mob.blaze.breathe", "entity.blaze.ambient", SoundCategory.HOSTILE), + MOB_BAT_IDLE("mob.bat.idle", "entity.bat.ambient", SoundCategory.NEUTRAL), + MOB_MAGMACUBE_BIG("mob.magmacube.big", "entity.magmacube.squish", SoundCategory.HOSTILE), + MOB_HORSE_IDLE("mob.horse.idle", "entity.horse.ambient", SoundCategory.NEUTRAL), + GAME_HOSTILE_HURT_FALL_SMALL("game.hostile.hurt.fall.small", "entity.generic.small_fall", SoundCategory.HOSTILE), + MOB_HORSE_ZOMBIE_HIT("mob.horse.zombie.hit", "entity.zombie_horse.hurt", SoundCategory.NEUTRAL), + MOB_IRONGOLEM_THROW("mob.irongolem.throw", "entity.irongolem.attack", SoundCategory.NEUTRAL), + DIG_CLOTH("dig.cloth", "block.cloth.place", SoundCategory.BLOCK), + STEP_GRAVEL("step.gravel", "block.gravel.hit", SoundCategory.NEUTRAL), + MOB_SILVERFISH_SAY("mob.silverfish.say", "entity.silverfish.ambient", SoundCategory.HOSTILE), + MOB_CAT_PURR("mob.cat.purr", "entity.cat.purr", SoundCategory.NEUTRAL), + MOB_ZOMBIE_INFECT("mob.zombie.infect", "entity.zombie.infect", SoundCategory.HOSTILE), + RANDOM_EAT("random.eat", "entity.generic.eat", SoundCategory.PLAYER), + MOB_WOLF_BARK("mob.wolf.bark", "entity.wolf.ambient", SoundCategory.NEUTRAL), + GAME_TNT_PRIMED("game.tnt.primed", "entity.creeper.primed", SoundCategory.BLOCK), + MOB_SHEEP_STEP("mob.sheep.step", "entity.sheep.step", SoundCategory.NEUTRAL), + MOB_ZOMBIE_DEATH("mob.zombie.death", "entity.zombie.death", SoundCategory.HOSTILE), + RANDOM_DOOR_OPEN("random.door_open", "null", SoundCategory.BLOCK), + MOB_ENDERMEN_PORTAL("mob.endermen.portal", "entity.endermen.teleport", SoundCategory.HOSTILE), + MOB_HORSE_ANGRY("mob.horse.angry", "entity.horse.angry", SoundCategory.NEUTRAL), + MOB_WOLF_GROWL("mob.wolf.growl", "entity.wolf.growl", SoundCategory.NEUTRAL), + DIG_SNOW("dig.snow", "block.snow.place", SoundCategory.BLOCK), + TILE_PISTON_OUT("tile.piston.out", "block.piston.extend", SoundCategory.BLOCK), + RANDOM_BURP("random.burp", "entity.player.burp", SoundCategory.PLAYER), + MOB_COW_STEP("mob.cow.step", "entity.cow.step", SoundCategory.NEUTRAL), + MOB_WITHER_HURT("mob.wither.hurt", "entity.wither.hurt", SoundCategory.HOSTILE), + MOB_GUARDIAN_LAND_DEATH("mob.guardian.land.death", "entity.elder_guardian.death_land", SoundCategory.HOSTILE), + MOB_CHICKEN_HURT("mob.chicken.hurt", "entity.chicken.death", SoundCategory.NEUTRAL), + MOB_WOLF_STEP("mob.wolf.step", "entity.wolf.step", SoundCategory.NEUTRAL), + MOB_WOLF_DEATH("mob.wolf.death", "entity.wolf.death", SoundCategory.NEUTRAL), + MOB_WOLF_WHINE("mob.wolf.whine", "entity.wolf.whine", SoundCategory.NEUTRAL), + NOTE_PLING("note.pling", "block.note.pling", SoundCategory.RECORD), + GAME_PLAYER_HURT_FALL_SMALL("game.player.hurt.fall.small", "entity.generic.small_fall", SoundCategory.PLAYER), + MOB_CAT_PURREOW("mob.cat.purreow", "entity.cat.purreow", SoundCategory.NEUTRAL), + FIREWORKS_LARGEBLAST_FAR("fireworks.largeBlast_far", "entity.firework.large_blast_far", SoundCategory.AMBIENT), + MOB_SKELETON_HURT("mob.skeleton.hurt", "entity.skeleton.hurt", SoundCategory.HOSTILE), + MOB_SPIDER_DEATH("mob.spider.death", "entity.spider.death", SoundCategory.HOSTILE), + RANDOM_ANVIL_BREAK("random.anvil_break", "block.anvil.destroy", SoundCategory.BLOCK), + MOB_WITHER_IDLE("mob.wither.idle", "entity.wither.ambient", SoundCategory.HOSTILE), + MOB_GUARDIAN_ELDER_HIT("mob.guardian.elder.hit", "entity.elder_guardian.hurt", SoundCategory.HOSTILE), + MOB_ENDERMEN_SCREAM("mob.endermen.scream", "entity.endermen.scream", SoundCategory.HOSTILE), + MOB_CAT_HITT("mob.cat.hitt", "entity.cat.hurt", SoundCategory.NEUTRAL), + MOB_MAGMACUBE_SMALL("mob.magmacube.small", "entity.small_magmacube.squish", SoundCategory.HOSTILE), + FIRE_IGNITE("fire.ignite", "item.flintandsteel.use", SoundCategory.BLOCK, true), + MOB_ENDERDRAGON_HIT("mob.enderdragon.hit", "entity.enderdragon.hurt", SoundCategory.HOSTILE), + MOB_ZOMBIE_HURT("mob.zombie.hurt", "entity.zombie_villager.hurt", SoundCategory.HOSTILE), + RANDOM_EXPLODE("random.explode", "block.end_gateway.spawn", SoundCategory.BLOCK), + MOB_SLIME_ATTACK("mob.slime.attack", "entity.slime.attack", SoundCategory.HOSTILE), + MOB_MAGMACUBE_JUMP("mob.magmacube.jump", "entity.magmacube.jump", SoundCategory.HOSTILE), + RANDOM_SPLASH("random.splash", "entity.bobber.splash", SoundCategory.PLAYER), + MOB_HORSE_SKELETON_HIT("mob.horse.skeleton.hit", "entity.skeleton_horse.hurt", SoundCategory.NEUTRAL), + MOB_GHAST_MOAN("mob.ghast.moan", "entity.ghast.ambient", SoundCategory.HOSTILE), + MOB_GUARDIAN_CURSE("mob.guardian.curse", "entity.elder_guardian.curse", SoundCategory.HOSTILE), + GAME_POTION_SMASH("game.potion.smash", "block.glass.break", SoundCategory.NEUTRAL), + NOTE_BASSATTACK("note.bassattack", "block.note.bass", SoundCategory.RECORD), + GUI_BUTTON_PRESS("gui.button.press", "block.wood_pressureplate.click_on", SoundCategory.MASTER), + RANDOM_ORB("random.orb", "entity.experience_orb.pickup", SoundCategory.PLAYER), + MOB_ZOMBIE_WOODBREAK("mob.zombie.woodbreak", "entity.zombie.break_door_wood", SoundCategory.HOSTILE), + MOB_HORSE_ARMOR("mob.horse.armor", "entity.horse.armor", SoundCategory.NEUTRAL), + TILE_PISTON_IN("tile.piston.in", "block.piston.contract", SoundCategory.BLOCK), + MOB_CAT_MEOW("mob.cat.meow", "entity.cat.ambient", SoundCategory.NEUTRAL), + MOB_PIG_STEP("mob.pig.step", "entity.pig.step", SoundCategory.NEUTRAL), + STEP_WOOD("step.wood", "block.wood.step", SoundCategory.NEUTRAL), + PORTAL_TRAVEL("portal.travel", "block.portal.travel", SoundCategory.PLAYER), + MOB_GUARDIAN_DEATH("mob.guardian.death", "entity.guardian.death", SoundCategory.HOSTILE), + MOB_SKELETON_DEATH("mob.skeleton.death", "entity.skeleton.death", SoundCategory.HOSTILE), + MOB_HORSE_HIT("mob.horse.hit", "entity.horse.hurt", SoundCategory.NEUTRAL), + MOB_VILLAGER_HIT("mob.villager.hit", "entity.villager.hurt", SoundCategory.NEUTRAL), + MOB_HORSE_SKELETON_IDLE("mob.horse.skeleton.idle", "entity.skeleton_horse.ambient", SoundCategory.NEUTRAL), + RECORDS_CHIRP("records.chirp", "record.chirp", SoundCategory.RECORD), + MOB_RABBIT_HURT("mob.rabbit.hurt", "entity.rabbit.hurt", SoundCategory.NEUTRAL), + RECORDS_STAL("records.stal", "record.stal", SoundCategory.RECORD), + MUSIC_GAME_NETHER("music.game.nether", "music.nether", SoundCategory.MUSIC), + MUSIC_MENU("music.menu", "music.menu", SoundCategory.MUSIC), + RECORDS_MELLOHI("records.mellohi", "record.mellohi", SoundCategory.RECORD), + RECORDS_CAT("records.cat", "record.cat", SoundCategory.RECORD), + RECORDS_FAR("records.far", "record.far", SoundCategory.RECORD), + MUSIC_GAME_END_DRAGON("music.game.end.dragon", "music.dragon", SoundCategory.MUSIC), + MOB_RABBIT_DEATH("mob.rabbit.death", "entity.rabbit.death", SoundCategory.NEUTRAL), + MOB_RABBIT_IDLE("mob.rabbit.idle", "entity.rabbit.ambient", SoundCategory.NEUTRAL), + MUSIC_GAME_END("music.game.end", "music.end", SoundCategory.MUSIC), + MUSIC_GAME("music.game", "music.game", SoundCategory.MUSIC), + MOB_GUARDIAN_IDLE("mob.guardian.idle", "null", SoundCategory.HOSTILE), + RECORDS_WARD("records.ward", "record.ward", SoundCategory.RECORD), + RECORDS_13("records.13", "record.13", SoundCategory.RECORD), + MOB_RABBIT_HOP("mob.rabbit.hop", "entity.rabbit.jump", SoundCategory.NEUTRAL), + RECORDS_STRAD("records.strad", "record.strad", SoundCategory.RECORD), + RECORDS_11("records.11", "record.11", SoundCategory.RECORD), + RECORDS_MALL("records.mall", "record.mall", SoundCategory.RECORD), + RECORDS_BLOCKS("records.blocks", "record.blocks", SoundCategory.RECORD), + RECORDS_WAIT("records.wait", "record.wait", SoundCategory.RECORD), + MUSIC_GAME_END_CREDITS("music.game.end.credits", "music.credits", SoundCategory.MUSIC), + MUSIC_GAME_CREATIVE("music.game.creative", "music.creative", SoundCategory.MUSIC); + + private final String name; + private final String newName; + private final SoundCategory category; + private final boolean breaksound; + + SoundEffect(String name, String newname, SoundCategory cat) { + this.category = cat; + this.newName = newname; + this.name = name; + this.breaksound = name.startsWith("dig."); + } + + SoundEffect(String name, String newname, SoundCategory cat, boolean shouldIgnore) { + this.category = cat; + this.newName = newname; + this.name = name; + this.breaksound = name.startsWith("dig.") || shouldIgnore; + } + + public static SoundEffect getByName(String name) { + name = name.toLowerCase(); + for (SoundEffect e : SoundEffect.values()) { + if (e.getName().equals(name)) + return e; + } + return null; + } + +} diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/ClientChunks.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/ClientChunks.java similarity index 93% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/ClientChunks.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/ClientChunks.java index 74df72f9a..8db47f107 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/ClientChunks.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/ClientChunks.java @@ -1,12 +1,12 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.storage; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import lombok.Getter; import org.bukkit.Bukkit; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.util.ReflectionUtil; -import us.myles.ViaVersion2.api.data.StoredObject; -import us.myles.ViaVersion2.api.data.UserConnection; import java.util.List; import java.util.Set; @@ -14,8 +14,6 @@ import java.util.logging.Level; @Getter public class ClientChunks extends StoredObject { - private final Set loadedChunks = Sets.newConcurrentHashSet(); - private final Set bulkChunks = Sets.newConcurrentHashSet(); // Reflection private static ReflectionUtil.ClassReflection mapChunkBulkRef; private static ReflectionUtil.ClassReflection mapChunkRef; @@ -29,10 +27,17 @@ public class ClientChunks extends StoredObject { } } + private final Set loadedChunks = Sets.newConcurrentHashSet(); + private final Set bulkChunks = Sets.newConcurrentHashSet(); + public ClientChunks(UserConnection user) { super(user); } + private static long toLong(int msw, int lsw) { + return ((long) msw << 32) + lsw - -2147483648L; + } + public List transformMapChunkBulk(Object packet) { List list = Lists.newArrayList(); try { @@ -56,9 +61,4 @@ public class ClientChunks extends StoredObject { } return list; } - - - private static long toLong(int msw, int lsw) { - return ((long) msw << 32) + lsw - -2147483648L; - } } diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/EntityTracker.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java similarity index 86% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/EntityTracker.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java index 88b0f4c28..6d05162a1 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/EntityTracker.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java @@ -1,4 +1,4 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.storage; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage; import io.netty.buffer.ByteBuf; import lombok.Getter; @@ -7,18 +7,17 @@ import org.bukkit.Bukkit; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import us.myles.ViaVersion.ViaVersionPlugin; +import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.boss.BossBar; import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossStyle; -import us.myles.ViaVersion.util.PacketUtil; -import us.myles.ViaVersion2.api.PacketWrapper; -import us.myles.ViaVersion2.api.data.StoredObject; -import us.myles.ViaVersion2.api.data.UserConnection; -import us.myles.ViaVersion2.api.item.Item; -import us.myles.ViaVersion2.api.metadata.Metadata; -import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; +import us.myles.ViaVersion.api.type.Type; import java.util.*; @@ -119,15 +118,18 @@ public class EntityTracker extends StoredObject { if ((data & 0x20) == 0x20) { if (!knownHolograms.contains(entityID)) { knownHolograms.add(entityID); - // Send movement - ByteBuf buf = getUser().getChannel().alloc().buffer(); - PacketUtil.writeVarInt(0x25, buf); // Relative Move Packet - PacketUtil.writeVarInt(entityID, buf); - buf.writeShort(0); - buf.writeShort((short) (128D * (((ViaVersionPlugin) ViaVersion.getInstance()).getHologramYOffset() * 32D))); - buf.writeShort(0); - buf.writeBoolean(true); - getUser().sendRawPacket(buf, false); + try { + // Send movement + ByteBuf buf = getUser().getChannel().alloc().buffer(); + Type.VAR_INT.write(buf, 0x25); // Relative Move Packet + Type.VAR_INT.write(buf, entityID); + buf.writeShort(0); + buf.writeShort((short) (128D * (((ViaVersionPlugin) ViaVersion.getInstance()).getHologramYOffset() * 32D))); + buf.writeShort(0); + buf.writeBoolean(true); + getUser().sendRawPacket(buf, false); + } catch (Exception ignored) { + } } } } diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/InventoryTracker.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/InventoryTracker.java similarity index 57% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/InventoryTracker.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/InventoryTracker.java index 85639fd6d..dccda08ee 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/InventoryTracker.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/InventoryTracker.java @@ -1,9 +1,9 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.storage; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage; import lombok.Getter; import lombok.Setter; -import us.myles.ViaVersion2.api.data.StoredObject; -import us.myles.ViaVersion2.api.data.UserConnection; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; @Getter @Setter diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/MovementTracker.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/MovementTracker.java similarity index 73% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/MovementTracker.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/MovementTracker.java index 809b7b074..1bc0c548f 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/storage/MovementTracker.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/MovementTracker.java @@ -1,10 +1,10 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.storage; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage; import lombok.Getter; -import us.myles.ViaVersion2.api.data.StoredObject; -import us.myles.ViaVersion2.api.data.UserConnection; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; -public class MovementTracker extends StoredObject{ +public class MovementTracker extends StoredObject { private static final long IDLE_PACKET_DELAY = 50L; // Update every 50ms (20tps) private static final long IDLE_PACKET_LIMIT = 20; // Max 20 ticks behind @Getter diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/types/ChunkType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java similarity index 82% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/types/ChunkType.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java index 29a609405..230ad6f8d 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/types/ChunkType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java @@ -1,13 +1,13 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.types; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.types; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.bukkit.Bukkit; -import us.myles.ViaVersion.chunks.Chunk; -import us.myles.ViaVersion.chunks.ChunkSection; -import us.myles.ViaVersion.util.PacketUtil; -import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.ClientChunks; -import us.myles.ViaVersion2.api.type.PartialType; +import us.myles.ViaVersion.api.minecraft.chunks.Chunk; +import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; +import us.myles.ViaVersion.api.type.PartialType; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -33,14 +33,18 @@ public class ChunkType extends PartialType { super(chunks, Chunk.class); } + private static long toLong(int msw, int lsw) { + return ((long) msw << 32) + lsw - -2147483648L; + } + @Override - public Chunk read(ByteBuf input, ClientChunks param) { + public Chunk read(ByteBuf input, ClientChunks param) throws Exception { int chunkX = input.readInt(); int chunkZ = input.readInt(); long chunkHash = toLong(chunkX, chunkZ); boolean groundUp = input.readByte() != 0; int bitmask = input.readUnsignedShort(); - int dataLength = PacketUtil.readVarInt(input); + int dataLength = Type.VAR_INT.read(input); // Data to be read BitSet usedSections = new BitSet(16); @@ -123,40 +127,36 @@ public class ChunkType extends PartialType { } @Override - public void write(ByteBuf output, ClientChunks param, Chunk chunk) { - if(chunk.isUnloadPacket()) { + public void write(ByteBuf output, ClientChunks param, Chunk chunk) throws Exception { + if (chunk.isUnloadPacket()) { output.clear(); - PacketUtil.writeVarInt(0x1D, output); // Unload packet ID + Type.VAR_INT.write(output, 0x1D); // Unload packet ID } // Write primary info output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); - if(chunk.isUnloadPacket()) return; + if (chunk.isUnloadPacket()) return; output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00); - PacketUtil.writeVarInt(chunk.getPrimaryBitmask(), output); + Type.VAR_INT.write(output, chunk.getPrimaryBitmask()); ByteBuf buf = Unpooled.buffer(); - for(int i = 0; i < SECTION_COUNT; i++) { + for (int i = 0; i < SECTION_COUNT; i++) { ChunkSection section = chunk.getSections()[i]; - if(section == null) continue; // Section not set + if (section == null) continue; // Section not set section.writeBlocks(buf); section.writeBlockLight(buf); - if(!section.hasSkyLight()) continue; // No sky light, we're done here. + if (!section.hasSkyLight()) continue; // No sky light, we're done here. section.writeSkyLight(buf); } buf.readerIndex(0); - PacketUtil.writeVarInt(buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0), output); + Type.VAR_INT.write(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0)); output.writeBytes(buf); buf.release(); // release buffer // Write biome data - if(chunk.hasBiomeData()) { + if (chunk.hasBiomeData()) { output.writeBytes(chunk.getBiomeData()); } } - - private static long toLong(int msw, int lsw) { - return ((long) msw << 32) + lsw - -2147483648L; - } } diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/types/MetadataListType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java similarity index 78% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/types/MetadataListType.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java index 8e8a1deb9..9e6d761f8 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/types/MetadataListType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataListType.java @@ -1,9 +1,9 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.types; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.metadata.Metadata; -import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8; -import us.myles.ViaVersion2.api.type.Type; +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 java.util.ArrayList; import java.util.List; diff --git a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/types/MetadataType.java b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java similarity index 78% rename from src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/types/MetadataType.java rename to src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java index 41324867d..46c5e13ef 100644 --- a/src/main/java/us/myles/ViaVersion2/api/protocol1_9to1_8/types/MetadataType.java +++ b/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/MetadataType.java @@ -1,10 +1,10 @@ -package us.myles.ViaVersion2.api.protocol1_9to1_8.types; +package us.myles.ViaVersion.protocols.protocol1_9to1_8.types; import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.metadata.Metadata; -import us.myles.ViaVersion2.api.protocol1_9to1_8.metadata.MetadataTypes; -import us.myles.ViaVersion2.api.type.Type; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.type.Type; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataTypes; public class MetadataType extends Type { diff --git a/src/main/java/us/myles/ViaVersion/update/UpdateListener.java b/src/main/java/us/myles/ViaVersion/update/UpdateListener.java index b57cb5dd2..36220b02f 100644 --- a/src/main/java/us/myles/ViaVersion/update/UpdateListener.java +++ b/src/main/java/us/myles/ViaVersion/update/UpdateListener.java @@ -9,14 +9,14 @@ import org.bukkit.plugin.Plugin; @RequiredArgsConstructor public class UpdateListener implements Listener { - private final Plugin plugin; - - @EventHandler - public void onJoin(PlayerJoinEvent e) { - if(e.getPlayer().hasPermission("viaversion.update") - && plugin.getConfig().getBoolean("checkforupdates", true)) { - UpdateUtil.sendUpdateMessage(e.getPlayer().getUniqueId(), plugin); - } - } + private final Plugin plugin; + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + if (e.getPlayer().hasPermission("viaversion.update") + && plugin.getConfig().getBoolean("checkforupdates", true)) { + UpdateUtil.sendUpdateMessage(e.getPlayer().getUniqueId(), plugin); + } + } } diff --git a/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java b/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java index 4feeef233..7ed0ccdf2 100644 --- a/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java +++ b/src/main/java/us/myles/ViaVersion/update/UpdateUtil.java @@ -20,11 +20,10 @@ import java.util.UUID; public class UpdateUtil { + public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN; private final static String URL = "http://api.spiget.org/v1/resources/"; private final static int PLUGIN = 19254; - public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN; - public static void sendUpdateMessage(final UUID uuid, final Plugin plugin) { new BukkitRunnable() { diff --git a/src/main/java/us/myles/ViaVersion/util/Configuration.java b/src/main/java/us/myles/ViaVersion/util/Configuration.java index ee1c7c808..447f53f1e 100644 --- a/src/main/java/us/myles/ViaVersion/util/Configuration.java +++ b/src/main/java/us/myles/ViaVersion/util/Configuration.java @@ -17,9 +17,9 @@ import java.util.logging.Level; import java.util.regex.Pattern; public class Configuration extends YamlConfiguration { - private List mainHeader = Lists.newArrayList(); private final Map> headers = Maps.newConcurrentMap(); private final File file; + private List mainHeader = Lists.newArrayList(); private boolean loadHeaders; public Configuration(File file) { @@ -47,7 +47,7 @@ public class Configuration extends YamlConfiguration { /** * Set option header. * - * @param key of option (or section) + * @param key of option (or section) * @param header of option (or section) */ public void header(String key, String... header) { @@ -85,14 +85,14 @@ public class Configuration extends YamlConfiguration { this.loadHeaders = loadHeaders; try { load(file); - } catch(Exception e) { + } catch (Exception e) { Bukkit.getLogger().log(Level.WARNING, "failed to reload file", e); } } @Override public void loadFromString(String contents) throws InvalidConfigurationException { - if(!loadHeaders) { + if (!loadHeaders) { super.loadFromString(contents); return; } @@ -105,12 +105,12 @@ public class Configuration extends YamlConfiguration { int currentIndents = 0; String key = ""; List headers = Lists.newArrayList(); - for(String line : contents.split("\n")) { - if(line.isEmpty()) continue; // Skip empty lines + for (String line : contents.split("\n")) { + if (line.isEmpty()) continue; // Skip empty lines int indent = getSuccessiveCharCount(line, ' '); String subline = indent > 0 ? line.substring(indent) : line; - if(subline.startsWith("#")) { - if(subline.startsWith("#>")) { + if (subline.startsWith("#")) { + if (subline.startsWith("#>")) { String txt = subline.startsWith("#> ") ? subline.substring(3) : subline.substring(2); mainHeader.add(txt); continue; // Main header, handled by bukkit @@ -123,7 +123,7 @@ public class Configuration extends YamlConfiguration { } int indents = indent / indentLength; - if(indents <= currentIndents) { + if (indents <= currentIndents) { // Remove last section of key String[] array = key.split(Pattern.quote(pathSeparator)); int backspace = currentIndents - indents + 1; @@ -138,7 +138,7 @@ public class Configuration extends YamlConfiguration { currentIndents = indents; memoryData.append(line).append('\n'); - if(!headers.isEmpty()) { + if (!headers.isEmpty()) { this.headers.put(key, headers); headers = Lists.newArrayList(); } @@ -155,10 +155,10 @@ public class Configuration extends YamlConfiguration { * Save config to file */ public void save() { - if(headers.isEmpty() && mainHeader.isEmpty()) { + if (headers.isEmpty() && mainHeader.isEmpty()) { try { super.save(file); - } catch(IOException e) { + } catch (IOException e) { Bukkit.getLogger().log(Level.WARNING, "Failed to save file", e); } return; @@ -171,17 +171,17 @@ public class Configuration extends YamlConfiguration { StringBuilder fileData = new StringBuilder(buildHeader()); int currentIndents = 0; String key = ""; - for(String h : mainHeader) { + for (String h : mainHeader) { // Append main header to top of file fileData.append("#> ").append(h).append('\n'); } - for(String line : content.split("\n")) { - if(line.isEmpty()) continue; // Skip empty lines + for (String line : content.split("\n")) { + if (line.isEmpty()) continue; // Skip empty lines int indent = getSuccessiveCharCount(line, ' '); int indents = indent / indentLength; String indentText = indent > 0 ? line.substring(0, indent) : ""; - if(indents <= currentIndents) { + if (indents <= currentIndents) { // Remove last section of key String[] array = key.split(Pattern.quote(pathSeparator)); int backspace = currentIndents - indents + 1; @@ -206,13 +206,13 @@ public class Configuration extends YamlConfiguration { writer = new FileWriter(file); writer.write(fileData.toString()); writer.flush(); - } catch(IOException e) { + } catch (IOException e) { Bukkit.getLogger().log(Level.WARNING, "Failed to save file", e); } finally { - if(writer != null) { + if (writer != null) { try { writer.close(); - } catch(IOException e) { + } catch (IOException ignored) { } } } @@ -220,7 +220,7 @@ public class Configuration extends YamlConfiguration { private String addHeaderTags(List header, String indent) { StringBuilder builder = new StringBuilder(); - for(String line : header) { + for (String line : header) { builder.append(indent).append("# ").append(line).append('\n'); } return builder.toString(); @@ -234,8 +234,8 @@ public class Configuration extends YamlConfiguration { private int getSuccessiveCharCount(String text, char key) { int count = 0; - for(int i = 0; i < text.length(); i++) { - if(text.charAt(i) == key) { + for (int i = 0; i < text.length(); i++) { + if (text.charAt(i) == key) { count += 1; } else { break; diff --git a/src/main/java/us/myles/ViaVersion/util/PacketUtil.java b/src/main/java/us/myles/ViaVersion/util/PacketUtil.java deleted file mode 100644 index f5942e724..000000000 --- a/src/main/java/us/myles/ViaVersion/util/PacketUtil.java +++ /dev/null @@ -1,294 +0,0 @@ -package us.myles.ViaVersion.util; - -import com.google.common.base.Charsets; -import com.google.common.base.Preconditions; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import io.netty.handler.codec.MessageToByteEncoder; -import org.spacehq.opennbt.NBTIO; -import org.spacehq.opennbt.tag.builtin.CompoundTag; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class PacketUtil { - private static Method DECODE_METHOD; - private static Method ENCODE_METHOD; - - static { - try { - DECODE_METHOD = ByteToMessageDecoder.class.getDeclaredMethod("decode", ChannelHandlerContext.class, ByteBuf.class, List.class); - DECODE_METHOD.setAccessible(true); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - System.out.println("Netty issue?"); - } - try { - ENCODE_METHOD = MessageToByteEncoder.class.getDeclaredMethod("encode", ChannelHandlerContext.class, Object.class, ByteBuf.class); - ENCODE_METHOD.setAccessible(true); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - System.out.println("Netty issue?"); - } - } - - public static CompoundTag readNBT(ByteBuf input) throws IOException { - // Default client is limited to 2097152 bytes. (2.09mb) - Preconditions.checkArgument(input.readableBytes() <= 2097152, "Cannot read NBT (got %s bytes)", input.readableBytes()); - - int readerIndex = input.readerIndex(); - byte b = input.readByte(); - if (b == 0) { - return null; - } else { - input.readerIndex(readerIndex); - ByteBufInputStream bytebufStream = new ByteBufInputStream(input); - DataInputStream dataInputStream = new DataInputStream(bytebufStream); - try { - return (CompoundTag) NBTIO.readTag(dataInputStream); - } finally { - dataInputStream.close(); - } - } - } - - public static void writeNBT(ByteBuf output, CompoundTag tag) throws IOException { - if (tag == null) { - output.writeByte(0); - } else { - ByteBufOutputStream bytebufStream = new ByteBufOutputStream(output); - DataOutputStream dataOutputStream = new DataOutputStream(bytebufStream); - - NBTIO.writeTag(dataOutputStream, tag); - - dataOutputStream.close(); - } - } - - public static List callDecode(ByteToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException { - List output = new ArrayList<>(); - try { - PacketUtil.DECODE_METHOD.invoke(decoder, ctx, input, output); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return output; - } - - public static void callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, Object msg, ByteBuf output) throws InvocationTargetException { - try { - PacketUtil.ENCODE_METHOD.invoke(encoder, ctx, msg, output); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - - /* I take no credit, these are taken from BungeeCord */ - // https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java - public static void writeString(String s, ByteBuf buf) { - Preconditions.checkArgument(s.length() <= Short.MAX_VALUE, "Cannot send string longer than Short.MAX_VALUE (got %s characters)", s.length()); - - byte[] b = s.getBytes(Charsets.UTF_8); - writeVarInt(b.length, buf); - buf.writeBytes(b); - } - - public static String readString(ByteBuf buf) { - int len = readVarInt(buf); - Preconditions.checkArgument(len <= Short.MAX_VALUE, "Cannot receive string longer than Short.MAX_VALUE (got %s characters)", len); - - byte[] b = new byte[len]; - buf.readBytes(b); - - return new String(b, Charsets.UTF_8); - } - - public static void writeArrayLegacy(byte[] b, ByteBuf buf, boolean allowExtended) { - // (Integer.MAX_VALUE & 0x1FFF9A ) = 2097050 - Forge's current upper limit - if (allowExtended) { - Preconditions.checkArgument(b.length <= (Integer.MAX_VALUE & 0x1FFF9A), "Cannot send array longer than 2097050 (got %s bytes)", b.length); - } else { - Preconditions.checkArgument(b.length <= Short.MAX_VALUE, "Cannot send array longer than Short.MAX_VALUE (got %s bytes)", b.length); - } - // Write a 2 or 3 byte number that represents the length of the packet. (3 byte "shorts" for Forge only) - // No vanilla packet should give a 3 byte packet, this method will still retain vanilla behaviour. - writeVarShort(buf, b.length); - buf.writeBytes(b); - } - - public static byte[] readArrayLegacy(ByteBuf buf) { - // Read in a 2 or 3 byte number that represents the length of the packet. (3 byte "shorts" for Forge only) - // No vanilla packet should give a 3 byte packet, this method will still retain vanilla behaviour. - int len = readVarShort(buf); - - // (Integer.MAX_VALUE & 0x1FFF9A ) = 2097050 - Forge's current upper limit - Preconditions.checkArgument(len <= (Integer.MAX_VALUE & 0x1FFF9A), "Cannot receive array longer than 2097050 (got %s bytes)", len); - - byte[] ret = new byte[len]; - buf.readBytes(ret); - return ret; - } - - public static void writeArray(byte[] b, ByteBuf buf) { - writeVarInt(b.length, buf); - buf.writeBytes(b); - } - - public static byte[] readArray(ByteBuf buf) { - byte[] ret = new byte[readVarInt(buf)]; - buf.readBytes(ret); - return ret; - } - - public static void writeStringArray(List s, ByteBuf buf) { - writeVarInt(s.size(), buf); - for (String str : s) { - writeString(str, buf); - } - } - - public static List readStringArray(ByteBuf buf) { - int len = readVarInt(buf); - List ret = new ArrayList<>(len); - for (int i = 0; i < len; i++) { - ret.add(readString(buf)); - } - return ret; - } - - public static int readVarInt(ByteBuf input) { - return readVarInt(input, 5); - } - - public static int readVarInt(ByteBuf input, int maxBytes) { - int out = 0; - int bytes = 0; - byte in; - while (true) { - in = input.readByte(); - - out |= (in & 0x7F) << (bytes++ * 7); - - if (bytes > maxBytes) { - throw new RuntimeException("VarInt too big"); - } - - if ((in & 0x80) != 0x80) { - break; - } - } - - return out; - } - - public static void writeVarInt(int value, ByteBuf output) { - int part; - while (true) { - part = value & 0x7F; - - value >>>= 7; - if (value != 0) { - part |= 0x80; - } - - output.writeByte(part); - - if (value == 0) { - break; - } - } - } - - public static void writeVarIntArray(List integers, ByteBuf output) { - writeVarInt(integers.size(), output); - for (Integer i : integers) { - writeVarInt(i, output); - } - } - - public static int readVarShort(ByteBuf buf) { - int low = buf.readUnsignedShort(); - int high = 0; - if ((low & 0x8000) != 0) { - low = low & 0x7FFF; - high = buf.readUnsignedByte(); - } - return ((high & 0xFF) << 15) | low; - } - - public static void writeVarShort(ByteBuf buf, int toWrite) { - int low = toWrite & 0x7FFF; - int high = (toWrite & 0x7F8000) >> 15; - if (high != 0) { - low = low | 0x8000; - } - buf.writeShort(low); - if (high != 0) { - buf.writeByte(high); - } - } - - public static void writeUUID(UUID value, ByteBuf output) { - output.writeLong(value.getMostSignificantBits()); - output.writeLong(value.getLeastSignificantBits()); - } - - public static UUID readUUID(ByteBuf input) { - return new UUID(input.readLong(), input.readLong()); - } - - public static void writeLongs(long[] data, ByteBuf output) { - for (long aData : data) { - output.writeLong(aData); - } - } - - public static long[] readLongs(int amount, ByteBuf output) { - long data[] = new long[amount]; - for (int index = 0; index < amount; index++) { - data[index] = output.readLong(); - } - - return data; - } - - public static long[] readBlockPosition(ByteBuf buf) { - long val = buf.readLong(); - long x = (val >> 38); // signed - long y = (val >> 26) & 0xfff; // unsigned - // this shifting madness is used to preserve sign - long z = (val << 38) >> 38; // signed - return new long[]{x, y, z}; - } - - public static void writeBlockPosition(ByteBuf buf, long x, long y, long z) { - buf.writeLong(((x & 0x3ffffff) << 38) | ((y & 0xfff) << 26) | (z & 0x3ffffff)); - } - - public static int[] readVarInts(int amount, ByteBuf input) { - int data[] = new int[amount]; - for (int index = 0; index < amount; index++) { - data[index] = PacketUtil.readVarInt(input); - } - - return data; - } - - public static boolean containsCause(Throwable t, Class c) { - while (t != null) { - t = t.getCause(); - if (t != null) - if (c.isAssignableFrom(t.getClass())) return true; - } - return false; - } -} diff --git a/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java b/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java new file mode 100644 index 000000000..205323419 --- /dev/null +++ b/src/main/java/us/myles/ViaVersion/util/PipelineUtil.java @@ -0,0 +1,60 @@ +package us.myles.ViaVersion.util; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import io.netty.handler.codec.MessageToByteEncoder; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +public class PipelineUtil { + private static Method DECODE_METHOD; + private static Method ENCODE_METHOD; + + static { + try { + DECODE_METHOD = ByteToMessageDecoder.class.getDeclaredMethod("decode", ChannelHandlerContext.class, ByteBuf.class, List.class); + DECODE_METHOD.setAccessible(true); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + System.out.println("Netty issue?"); + } + try { + ENCODE_METHOD = MessageToByteEncoder.class.getDeclaredMethod("encode", ChannelHandlerContext.class, Object.class, ByteBuf.class); + ENCODE_METHOD.setAccessible(true); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + System.out.println("Netty issue?"); + } + } + + public static List callDecode(ByteToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException { + List output = new ArrayList<>(); + try { + PipelineUtil.DECODE_METHOD.invoke(decoder, ctx, input, output); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return output; + } + + public static void callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, Object msg, ByteBuf output) throws InvocationTargetException { + try { + PipelineUtil.ENCODE_METHOD.invoke(encoder, ctx, msg, output); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + public static boolean containsCause(Throwable t, Class c) { + while (t != null) { + t = t.getCause(); + if (t != null) + if (c.isAssignableFrom(t.getClass())) return true; + } + return false; + } +} diff --git a/src/main/java/us/myles/ViaVersion/util/ReflectionUtil.java b/src/main/java/us/myles/ViaVersion/util/ReflectionUtil.java index 59c2c2096..7b0c51a6e 100644 --- a/src/main/java/us/myles/ViaVersion/util/ReflectionUtil.java +++ b/src/main/java/us/myles/ViaVersion/util/ReflectionUtil.java @@ -17,6 +17,7 @@ public class ReflectionUtil { public static Class nms(String className) throws ClassNotFoundException { return Class.forName(NMS + "." + className); } + public static Class obc(String className) throws ClassNotFoundException { return Class.forName(BASE + "." + className); } @@ -77,22 +78,22 @@ public class ReflectionUtil { } private void scanFields(Class host, boolean recursive) { - if(host.getSuperclass() != null && recursive) { + if (host.getSuperclass() != null && recursive) { scanFields(host.getSuperclass(), true); } - for(Field field : host.getDeclaredFields()) { + for (Field field : host.getDeclaredFields()) { field.setAccessible(true); fields.put(field.getName(), field); } } private void scanMethods(Class host, boolean recursive) { - if(host.getSuperclass() != null && recursive) { + if (host.getSuperclass() != null && recursive) { scanMethods(host.getSuperclass(), true); } - for(Method method : host.getDeclaredMethods()) { + for (Method method : host.getDeclaredMethods()) { method.setAccessible(true); methods.put(method.getName(), method); } diff --git a/src/main/java/us/myles/ViaVersion2/api/remapper/ValueReader.java b/src/main/java/us/myles/ViaVersion2/api/remapper/ValueReader.java deleted file mode 100644 index 042eb4845..000000000 --- a/src/main/java/us/myles/ViaVersion2/api/remapper/ValueReader.java +++ /dev/null @@ -1,8 +0,0 @@ -package us.myles.ViaVersion2.api.remapper; - -import io.netty.buffer.ByteBuf; -import us.myles.ViaVersion2.api.PacketWrapper; - -public interface ValueReader { - public T read(PacketWrapper wrapper) throws Exception; -} diff --git a/src/main/java/us/myles/ViaVersion2/api/remapper/ValueWriter.java b/src/main/java/us/myles/ViaVersion2/api/remapper/ValueWriter.java deleted file mode 100644 index ad7dff859..000000000 --- a/src/main/java/us/myles/ViaVersion2/api/remapper/ValueWriter.java +++ /dev/null @@ -1,7 +0,0 @@ -package us.myles.ViaVersion2.api.remapper; - -import us.myles.ViaVersion2.api.PacketWrapper; - -public interface ValueWriter { - public void write(PacketWrapper writer, T inputValue) throws Exception; -} diff --git a/src/main/java/us/myles/ViaVersion2/api/type/ByteBufReader.java b/src/main/java/us/myles/ViaVersion2/api/type/ByteBufReader.java deleted file mode 100644 index 26befd28a..000000000 --- a/src/main/java/us/myles/ViaVersion2/api/type/ByteBufReader.java +++ /dev/null @@ -1,7 +0,0 @@ -package us.myles.ViaVersion2.api.type; - -import io.netty.buffer.ByteBuf; - -public interface ByteBufReader { - public T read(ByteBuf buffer) throws Exception; -} diff --git a/src/main/java/us/myles/ViaVersion2/api/type/ByteBufWriter.java b/src/main/java/us/myles/ViaVersion2/api/type/ByteBufWriter.java deleted file mode 100644 index fd376e7cc..000000000 --- a/src/main/java/us/myles/ViaVersion2/api/type/ByteBufWriter.java +++ /dev/null @@ -1,7 +0,0 @@ -package us.myles.ViaVersion2.api.type; - -import io.netty.buffer.ByteBuf; - -public interface ByteBufWriter { - public void write(ByteBuf buffer, T object) throws Exception; -} diff --git a/src/main/java/us/myles/ViaVersion2/api/type/TypeConverter.java b/src/main/java/us/myles/ViaVersion2/api/type/TypeConverter.java deleted file mode 100644 index 3fa165685..000000000 --- a/src/main/java/us/myles/ViaVersion2/api/type/TypeConverter.java +++ /dev/null @@ -1,5 +0,0 @@ -package us.myles.ViaVersion2.api.type; - -public interface TypeConverter { - public T from(Object o); -}