From bc2b4db41915cba186ed24333a3c7b4be4011fe3 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 16 Apr 2014 10:18:16 +1000 Subject: [PATCH] Replace literal numbers with usages of the ProtocolConstants class. --- .../src/main/java/net/md_5/bungee/protocol/Protocol.java | 2 +- .../java/net/md_5/bungee/protocol/ProtocolConstants.java | 9 +++++++++ proxy/src/main/java/net/md_5/bungee/BungeeCord.java | 5 +++-- proxy/src/main/java/net/md_5/bungee/EntityMap.java | 3 ++- .../java/net/md_5/bungee/connection/InitialHandler.java | 7 ++++--- .../java/net/md_5/bungee/connection/PingHandler.java | 3 ++- 6 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 2d55e568..314af5fc 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -93,7 +93,7 @@ public enum Protocol }; /*========================================================================*/ public static final int MAX_PACKET_ID = 0xFF; - public static List supportedVersions = Arrays.asList( 4, 5, 8 ); + public static List supportedVersions = Arrays.asList( ProtocolConstants.MINECRAFT_1_7_2, ProtocolConstants.MINECRAFT_1_7_6 ); /*========================================================================*/ public final ProtocolDirection TO_SERVER = new ProtocolDirection( "TO_SERVER" ); public final ProtocolDirection TO_CLIENT = new ProtocolDirection( "TO_CLIENT" ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java b/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java new file mode 100644 index 00000000..c3907aad --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java @@ -0,0 +1,9 @@ +package net.md_5.bungee.protocol; + +public class ProtocolConstants +{ + + public static int MINECRAFT_1_7_2 = 4; + public static int MINECRAFT_1_7_6 = 5; + public static int MINECRAFT_14_11_a = 14; +} diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 80ab55d2..b788e657 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -65,6 +65,7 @@ import net.md_5.bungee.log.LoggingOutputStream; import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.Protocol; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.Chat; import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.query.RemoteQuery; @@ -127,10 +128,10 @@ public class BungeeCord extends ProxyServer @Getter private final Logger logger; public final Gson gson = new GsonBuilder() - .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( 5 ) ) + .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( ProtocolConstants.MINECRAFT_1_7_6 ) ) .registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create(); public final Gson gsonLegacy = new GsonBuilder() - .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( 4 ) ) + .registerTypeAdapter( ServerPing.PlayerInfo.class, new PlayerInfoSerializer( ProtocolConstants.MINECRAFT_1_7_2 ) ) .registerTypeAdapter( Favicon.class, Favicon.getFaviconTypeAdapter() ).create(); @Getter private ConnectionThrottle connectionThrottle; diff --git a/proxy/src/main/java/net/md_5/bungee/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/EntityMap.java index f29f50b5..4faad9ed 100644 --- a/proxy/src/main/java/net/md_5/bungee/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/EntityMap.java @@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.connection.LoginResult; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.LoginRequest; /** @@ -143,7 +144,7 @@ public class EntityMap } } } - } else if ( packetId == 0x0C /* Spawn Player */ && version == 5 ) + } else if ( packetId == 0x0C /* Spawn Player */ && version == ProtocolConstants.MINECRAFT_1_7_6 ) { DefinedPacket.readVarInt( packet ); int idLength = packet.readerIndex() - readerIndex - packetIdLength; diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index a36fd048..cc20cd7e 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -48,6 +48,7 @@ import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.event.PlayerHandshakeEvent; import net.md_5.bungee.api.event.PreLoginEvent; import net.md_5.bungee.protocol.Protocol; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.LegacyHandshake; import net.md_5.bungee.protocol.packet.LegacyPing; import net.md_5.bungee.protocol.packet.LoginRequest; @@ -166,7 +167,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection result = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result ) ).getResponse(); BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() ); - Gson gson = handshake.getProtocolVersion() == 4 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; + Gson gson = handshake.getProtocolVersion() == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; unsafe.sendPacket( new StatusResponse( gson.toJson( result ) ) ); } }; @@ -381,8 +382,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection { uniqueId = offlineId; } - // Version 5 == 1.7.6. This is a screwup as 1.7.6 was also a snapshot. - if ( getVersion() == 5 ) + + if ( getVersion() == ProtocolConstants.MINECRAFT_1_7_6 ) { unsafe.sendPacket( new LoginSuccess( getUniqueId().toString(), getName() ) ); // With dashes in between } else diff --git a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java index a9acee8a..ad868828 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java @@ -13,6 +13,7 @@ import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.protocol.MinecraftDecoder; import net.md_5.bungee.protocol.MinecraftEncoder; import net.md_5.bungee.protocol.Protocol; +import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; @@ -50,7 +51,7 @@ public class PingHandler extends PacketHandler @Override public void handle(StatusResponse statusResponse) throws Exception { - Gson gson = protocol == 4 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; + Gson gson = protocol == ProtocolConstants.MINECRAFT_1_7_2 ? BungeeCord.getInstance().gsonLegacy : BungeeCord.getInstance().gson; callback.done( gson.fromJson( statusResponse.getResponse(), ServerPing.class ), null ); channel.close(); }