Use static instances of EntityMap

This commit is contained in:
kamcio96 2016-01-16 12:44:32 +11:00 committed by md_5
parent 5cff0b2171
commit 83e27f07e6
4 changed files with 13 additions and 8 deletions

View File

@ -2,12 +2,15 @@ package net.md_5.bungee.entitymap;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.ProtocolConstants;
/** /**
* Class to rewrite integers within packets. * Class to rewrite integers within packets.
*/ */
@NoArgsConstructor(access = AccessLevel.PACKAGE)
public abstract class EntityMap public abstract class EntityMap
{ {
@ -17,21 +20,17 @@ public abstract class EntityMap
private final boolean[] serverboundInts = new boolean[ 256 ]; private final boolean[] serverboundInts = new boolean[ 256 ];
private final boolean[] serverboundVarInts = new boolean[ 256 ]; private final boolean[] serverboundVarInts = new boolean[ 256 ];
EntityMap()
{
}
// Returns the correct entity map for the protocol version // Returns the correct entity map for the protocol version
public static EntityMap getEntityMap(int version) public static EntityMap getEntityMap(int version)
{ {
switch ( version ) switch ( version )
{ {
case ProtocolConstants.MINECRAFT_1_7_2: case ProtocolConstants.MINECRAFT_1_7_2:
return new EntityMap_1_7_2(); return EntityMap_1_7_2.INSTANCE;
case ProtocolConstants.MINECRAFT_1_7_6: case ProtocolConstants.MINECRAFT_1_7_6:
return new EntityMap_1_7_6(); return EntityMap_1_7_6.INSTANCE;
case ProtocolConstants.MINECRAFT_1_8: case ProtocolConstants.MINECRAFT_1_8:
return new EntityMap_1_8(); return EntityMap_1_8.INSTANCE;
} }
throw new RuntimeException( "Version " + version + " has no entity map" ); throw new RuntimeException( "Version " + version + " has no entity map" );
} }

View File

@ -7,6 +7,8 @@ import net.md_5.bungee.protocol.ProtocolConstants;
class EntityMap_1_7_2 extends EntityMap class EntityMap_1_7_2 extends EntityMap
{ {
static final EntityMap INSTANCE = new EntityMap_1_7_2();
EntityMap_1_7_2() EntityMap_1_7_2()
{ {
addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Equipment addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Equipment

View File

@ -10,6 +10,8 @@ import net.md_5.bungee.protocol.DefinedPacket;
class EntityMap_1_7_6 extends EntityMap_1_7_2 class EntityMap_1_7_6 extends EntityMap_1_7_2
{ {
static final EntityMap_1_7_6 INSTANCE = new EntityMap_1_7_6();
@Override @Override
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
public void rewriteClientbound(ByteBuf packet, int oldId, int newId) public void rewriteClientbound(ByteBuf packet, int oldId, int newId)

View File

@ -12,6 +12,8 @@ import java.util.UUID;
class EntityMap_1_8 extends EntityMap class EntityMap_1_8 extends EntityMap
{ {
static final EntityMap_1_8 INSTANCE = new EntityMap_1_8();
EntityMap_1_8() EntityMap_1_8()
{ {
addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Equipment addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Equipment
@ -161,7 +163,7 @@ class EntityMap_1_8 extends EntityMap
int packetId = DefinedPacket.readVarInt( packet ); int packetId = DefinedPacket.readVarInt( packet );
int packetIdLength = packet.readerIndex() - readerIndex; int packetIdLength = packet.readerIndex() - readerIndex;
if ( packetId == 0x18 /* Spectate */ && !BungeeCord.getInstance().getConfig().isIpForward()) if ( packetId == 0x18 /* Spectate */ && !BungeeCord.getInstance().getConfig().isIpForward() )
{ {
UUID uuid = DefinedPacket.readUUID( packet ); UUID uuid = DefinedPacket.readUUID( packet );
ProxiedPlayer player; ProxiedPlayer player;