Replace literal numbers with usages of the ProtocolConstants class.
This commit is contained in:
parent
994a996981
commit
bc2b4db419
@ -93,7 +93,7 @@ public enum Protocol
|
||||
};
|
||||
/*========================================================================*/
|
||||
public static final int MAX_PACKET_ID = 0xFF;
|
||||
public static List<Integer> supportedVersions = Arrays.asList( 4, 5, 8 );
|
||||
public static List<Integer> 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" );
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user