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 5fa45d22..3ddc082c 100644 --- a/proxy/src/main/java/net/md_5/bungee/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/EntityMap.java @@ -2,7 +2,6 @@ package net.md_5.bungee; import io.netty.buffer.ByteBuf; import net.md_5.bungee.protocol.DefinedPacket; -import net.md_5.bungee.protocol.PacketWrapper; /** * Class to rewrite integers within packets. @@ -10,13 +9,13 @@ import net.md_5.bungee.protocol.PacketWrapper; public class EntityMap { - private final static boolean[] clientboundInts = new boolean[ 256 ]; - private final static boolean[] clientboundVarInts = new boolean[ 256 ]; + private final boolean[] clientboundInts = new boolean[ 256 ]; + private final boolean[] clientboundVarInts = new boolean[ 256 ]; - private final static boolean[] serverboundInts = new boolean[ 256 ]; - private final static boolean[] serverboundVarInts = new boolean[ 256 ]; + private final boolean[] serverboundInts = new boolean[ 256 ]; + private final boolean[] serverboundVarInts = new boolean[ 256 ]; - static + public EntityMap(int version) { clientboundInts[0x04] = true; // Entity Equipment clientboundInts[0x0A] = true; // Use bed @@ -46,14 +45,32 @@ public class EntityMap serverboundInts[0x02] = true; // Use Entity serverboundInts[0x0A] = true; // Animation serverboundInts[0x0B] = true; // Entity Action + + if ( version >= 7 ) + { + migrateIntToVarint( clientboundInts, clientboundVarInts ); + migrateIntToVarint( serverboundInts, serverboundVarInts ); + } } - public static void rewriteServerbound(ByteBuf packet, int serverEntityId, int clientEntityId) + private void migrateIntToVarint(boolean[] ints, boolean[] varints) + { + for ( int i = 0; i < ints.length; i++ ) + { + if ( ints[i] = true ) + { + varints[i] = true; + ints[i] = false; + } + } + } + + public void rewriteServerbound(ByteBuf packet, int serverEntityId, int clientEntityId) { rewrite( packet, serverEntityId, clientEntityId, serverboundInts, serverboundVarInts ); } - public static void rewriteClientbound(ByteBuf packet, int serverEntityId, int clientEntityId) + public void rewriteClientbound(ByteBuf packet, int serverEntityId, int clientEntityId) { rewrite( packet, serverEntityId, clientEntityId, clientboundInts, clientboundVarInts ); diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 59005d05..762c91f2 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -103,6 +103,8 @@ public final class UserConnection implements ProxiedPlayer /*========================================================================*/ @Getter private String displayName; + @Getter + private EntityMap entityRewrite; /*========================================================================*/ private final Unsafe unsafe = new Unsafe() { @@ -115,6 +117,8 @@ public final class UserConnection implements ProxiedPlayer public void init() { + this.entityRewrite = new EntityMap( getPendingConnection().getVersion() ); + this.displayName = name; try { diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index ef930faf..ad334efb 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -79,7 +79,7 @@ public class DownstreamBridge extends PacketHandler { if ( !server.isObsolete() ) { - EntityMap.rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId() ); + con.getEntityRewrite().rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId() ); con.sendPacket( packet ); } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 5bb93f14..674e8e12 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -60,7 +60,7 @@ public class UpstreamBridge extends PacketHandler @Override public void handle(PacketWrapper packet) throws Exception { - EntityMap.rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId() ); + con.getEntityRewrite().rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId() ); if ( con.getServer() != null ) { con.getServer().getCh().write( packet );