From 16d261553c1a648ce38101bda19b7166d1ca5a41 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 14 May 2017 12:00:00 +1000 Subject: [PATCH] Minecraft 1.12-pre2 Support --- api/pom.xml | 4 +- bootstrap/pom.xml | 4 +- chat/pom.xml | 4 +- config/pom.xml | 4 +- event/pom.xml | 4 +- log/pom.xml | 4 +- module/cmd-alert/pom.xml | 4 +- module/cmd-find/pom.xml | 4 +- module/cmd-list/pom.xml | 4 +- module/cmd-send/pom.xml | 4 +- module/cmd-server/pom.xml | 4 +- module/pom.xml | 4 +- module/reconnect-yaml/pom.xml | 4 +- native/pom.xml | 4 +- pom.xml | 2 +- protocol/pom.xml | 4 +- .../net/md_5/bungee/protocol/Protocol.java | 108 ++++++++--- .../bungee/protocol/ProtocolConstants.java | 7 +- proxy/pom.xml | 4 +- .../net/md_5/bungee/entitymap/EntityMap.java | 11 ++ .../md_5/bungee/entitymap/EntityMap_1_12.java | 182 ++++++++++++++++++ query/pom.xml | 4 +- 22 files changed, 314 insertions(+), 64 deletions(-) create mode 100644 proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_12.java diff --git a/api/pom.xml b/api/pom.xml index 43a4dd94..96a46738 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-api - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-API diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index 5c42c6fa..8149db1e 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-bootstrap - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-Bootstrap diff --git a/chat/pom.xml b/chat/pom.xml index e8f3fd6c..dc097e11 100644 --- a/chat/pom.xml +++ b/chat/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-chat - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-Chat diff --git a/config/pom.xml b/config/pom.xml index 5d32d0e8..ac980914 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-config - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-Config diff --git a/event/pom.xml b/event/pom.xml index 65a64224..6132e8e9 100644 --- a/event/pom.xml +++ b/event/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-event - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-Event diff --git a/log/pom.xml b/log/pom.xml index 22a933f2..2fcbbad6 100644 --- a/log/pom.xml +++ b/log/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-log - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-Log diff --git a/module/cmd-alert/pom.xml b/module/cmd-alert/pom.xml index 223d0f6f..220f0421 100644 --- a/module/cmd-alert/pom.xml +++ b/module/cmd-alert/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-alert - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar cmd_alert diff --git a/module/cmd-find/pom.xml b/module/cmd-find/pom.xml index 7635889d..928f63a8 100644 --- a/module/cmd-find/pom.xml +++ b/module/cmd-find/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-find - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar cmd_find diff --git a/module/cmd-list/pom.xml b/module/cmd-list/pom.xml index 76158bcb..689b83ee 100644 --- a/module/cmd-list/pom.xml +++ b/module/cmd-list/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-list - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar cmd_list diff --git a/module/cmd-send/pom.xml b/module/cmd-send/pom.xml index 87375419..e50a4bec 100644 --- a/module/cmd-send/pom.xml +++ b/module/cmd-send/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-send - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar cmd_send diff --git a/module/cmd-server/pom.xml b/module/cmd-server/pom.xml index 8a0ed9de..daf146dc 100644 --- a/module/cmd-server/pom.xml +++ b/module/cmd-server/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-server - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar cmd_server diff --git a/module/pom.xml b/module/pom.xml index 2d517465..20728c67 100644 --- a/module/pom.xml +++ b/module/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-module - 1.11-SNAPSHOT + 1.12-SNAPSHOT pom BungeeCord Modules diff --git a/module/reconnect-yaml/pom.xml b/module/reconnect-yaml/pom.xml index c08ad70d..8e82446f 100644 --- a/module/reconnect-yaml/pom.xml +++ b/module/reconnect-yaml/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-reconnect-yaml - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar reconnect_yaml diff --git a/native/pom.xml b/native/pom.xml index 940d257e..082f0908 100644 --- a/native/pom.xml +++ b/native/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-native - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-Native diff --git a/pom.xml b/pom.xml index a8686e1a..c817bcfa 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT pom BungeeCord-Parent diff --git a/protocol/pom.xml b/protocol/pom.xml index 63d04980..bf4b399a 100644 --- a/protocol/pom.xml +++ b/protocol/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-protocol - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-Protocol 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 ac9129c5..57a93c93 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 @@ -60,105 +60,122 @@ public enum Protocol TO_CLIENT.registerPacket( KeepAlive.class, map( ProtocolConstants.MINECRAFT_1_8, 0x00 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x1F ) + map( ProtocolConstants.MINECRAFT_1_9, 0x1F ), + map( ProtocolConstants.MINECRAFT_1_12, 0x20 ) ); TO_CLIENT.registerPacket( Login.class, map( ProtocolConstants.MINECRAFT_1_8, 0x01 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x23 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x23 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x24 ) ); TO_CLIENT.registerPacket( Chat.class, map( ProtocolConstants.MINECRAFT_1_8, 0x02 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x0F ) + map( ProtocolConstants.MINECRAFT_1_9, 0x0F ), + map( ProtocolConstants.MINECRAFT_1_12, 0x10 ) ); TO_CLIENT.registerPacket( Respawn.class, map( ProtocolConstants.MINECRAFT_1_8, 0x07 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x33 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x33 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x35 ) ); TO_CLIENT.registerPacket( BossBar.class, - map( ProtocolConstants.MINECRAFT_1_9, 0x0C ) + map( ProtocolConstants.MINECRAFT_1_9, 0x0C ), + map( ProtocolConstants.MINECRAFT_1_12, 0x0D ) ); TO_CLIENT.registerPacket( PlayerListItem.class, // PlayerInfo map( ProtocolConstants.MINECRAFT_1_8, 0x38 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x2D ) + map( ProtocolConstants.MINECRAFT_1_9, 0x2D ), + map( ProtocolConstants.MINECRAFT_1_12, 0x2E ) ); TO_CLIENT.registerPacket( TabCompleteResponse.class, map( ProtocolConstants.MINECRAFT_1_8, 0x3A ), - map( ProtocolConstants.MINECRAFT_1_9, 0x0E ) + map( ProtocolConstants.MINECRAFT_1_9, 0x0E ), + map( ProtocolConstants.MINECRAFT_1_12, 0x0F ) ); TO_CLIENT.registerPacket( ScoreboardObjective.class, map( ProtocolConstants.MINECRAFT_1_8, 0x3B ), - map( ProtocolConstants.MINECRAFT_1_9, 0x3F ) + map( ProtocolConstants.MINECRAFT_1_9, 0x3F ), + map( ProtocolConstants.MINECRAFT_1_12, 0x41 ) ); TO_CLIENT.registerPacket( ScoreboardScore.class, map( ProtocolConstants.MINECRAFT_1_8, 0x3C ), - map( ProtocolConstants.MINECRAFT_1_9, 0x42 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x42 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x44 ) ); TO_CLIENT.registerPacket( ScoreboardDisplay.class, map( ProtocolConstants.MINECRAFT_1_8, 0x3D ), - map( ProtocolConstants.MINECRAFT_1_9, 0x38 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x38 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x3A ) ); TO_CLIENT.registerPacket( Team.class, map( ProtocolConstants.MINECRAFT_1_8, 0x3E ), - map( ProtocolConstants.MINECRAFT_1_9, 0x41 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x41 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x43 ) ); TO_CLIENT.registerPacket( PluginMessage.class, map( ProtocolConstants.MINECRAFT_1_8, 0x3F ), - map( ProtocolConstants.MINECRAFT_1_9, 0x18 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x18 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x19 ) ); TO_CLIENT.registerPacket( Kick.class, map( ProtocolConstants.MINECRAFT_1_8, 0x40 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x1A ) + map( ProtocolConstants.MINECRAFT_1_9, 0x1A ), + map( ProtocolConstants.MINECRAFT_1_12, 0x1B ) ); TO_CLIENT.registerPacket( Title.class, - map( ProtocolConstants.MINECRAFT_1_8, 0x45 ) + map( ProtocolConstants.MINECRAFT_1_8, 0x45 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x47 ) ); TO_CLIENT.registerPacket( PlayerListHeaderFooter.class, map( ProtocolConstants.MINECRAFT_1_8, 0x47 ), map( ProtocolConstants.MINECRAFT_1_9, 0x48 ), map( ProtocolConstants.MINECRAFT_1_9_4, 0x47 ), - map( ProtocolConstants.MINECRAFT_1_10, 0x47 ), - map( ProtocolConstants.MINECRAFT_1_11, 0x47 ), - map( ProtocolConstants.MINECRAFT_1_11_1, 0x47 ) + map( ProtocolConstants.MINECRAFT_1_12, 0x49 ) ); TO_SERVER.registerPacket( KeepAlive.class, map( ProtocolConstants.MINECRAFT_1_8, 0x00 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x0B ) + map( ProtocolConstants.MINECRAFT_1_9, 0x0B ), + map( ProtocolConstants.MINECRAFT_1_12, 0x0C ) ); TO_SERVER.registerPacket( Chat.class, map( ProtocolConstants.MINECRAFT_1_8, 0x01 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x02 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x02 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x03 ) ); TO_SERVER.registerPacket( TabCompleteRequest.class, map( ProtocolConstants.MINECRAFT_1_8, 0x14 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x01 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x01 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x02 ) ); TO_SERVER.registerPacket( ClientSettings.class, map( ProtocolConstants.MINECRAFT_1_8, 0x15 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x04 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x04 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x05 ) ); TO_SERVER.registerPacket( PluginMessage.class, map( ProtocolConstants.MINECRAFT_1_8, 0x17 ), - map( ProtocolConstants.MINECRAFT_1_9, 0x09 ) + map( ProtocolConstants.MINECRAFT_1_9, 0x09 ), + map( ProtocolConstants.MINECRAFT_1_12, 0x0A ) ); } }, @@ -224,12 +241,46 @@ public enum Protocol public final DirectionData TO_SERVER = new DirectionData(this, ProtocolConstants.Direction.TO_SERVER ); public final DirectionData TO_CLIENT = new DirectionData(this, ProtocolConstants.Direction.TO_CLIENT ); + public static void main(String[] args) + { + for ( int version : ProtocolConstants.SUPPORTED_VERSION_IDS ) + { + dump( version ); + } + } + + private static void dump(int version) + { + for ( Protocol protocol : Protocol.values() ) + { + dump( version, protocol ); + } + } + + private static void dump(int version, Protocol protocol) + { + dump( version, protocol.TO_CLIENT ); + dump( version, protocol.TO_SERVER ); + } + + private static void dump(int version, DirectionData data) + { + for ( int id = 0; id < MAX_PACKET_ID; id++ ) + { + DefinedPacket packet = data.createPacket( id, version ); + if ( packet != null ) + { + System.out.println( version + " " + data.protocolPhase + " " + data.direction + " " + id + " " + packet.getClass().getSimpleName() ); + } + } + } + @RequiredArgsConstructor private static class ProtocolData { private final int protocolVersion; private final TObjectIntMap> packetMap = new TObjectIntHashMap<>( MAX_PACKET_ID ); - private final TIntObjectMap> packetConstructors = new TIntObjectHashMap<>( MAX_PACKET_ID ); + private final Constructor[] packetConstructors = new Constructor[ MAX_PACKET_ID ]; } @RequiredArgsConstructor @@ -257,12 +308,15 @@ public enum Protocol private final TIntObjectMap> linkedProtocols = new TIntObjectHashMap<>(); { linkedProtocols.put( ProtocolConstants.MINECRAFT_1_8, Arrays.asList( - ProtocolConstants.MINECRAFT_1_9 + ProtocolConstants.MINECRAFT_1_9, + ProtocolConstants.MINECRAFT_1_12 ) ); linkedProtocols.put( ProtocolConstants.MINECRAFT_1_9, Arrays.asList( ProtocolConstants.MINECRAFT_1_9_1, ProtocolConstants.MINECRAFT_1_9_2, - ProtocolConstants.MINECRAFT_1_9_4, + ProtocolConstants.MINECRAFT_1_9_4 + ) ); + linkedProtocols.put( ProtocolConstants.MINECRAFT_1_9_4, Arrays.asList( ProtocolConstants.MINECRAFT_1_10, ProtocolConstants.MINECRAFT_1_11, ProtocolConstants.MINECRAFT_1_11_1 @@ -294,7 +348,7 @@ public enum Protocol throw new BadPacketException( "Packet with id " + id + " outside of range " ); } - Constructor constructor = protocolData.packetConstructors.get( id ); + Constructor constructor = protocolData.packetConstructors[id]; try { return ( constructor == null ) ? null : constructor.newInstance(); @@ -313,7 +367,7 @@ public enum Protocol { ProtocolData data = protocols.get( mapping.protocolVersion ); data.packetMap.put( packetClass, mapping.packetID ); - data.packetConstructors.put( mapping.packetID, constructor ); + data.packetConstructors[mapping.packetID] = constructor; List links = linkedProtocols.get( mapping.protocolVersion ); if ( links != null ) 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 index 9929ef47..57b0cd3c 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java @@ -14,11 +14,13 @@ public class ProtocolConstants public static final int MINECRAFT_1_10 = 210; public static final int MINECRAFT_1_11 = 315; public static final int MINECRAFT_1_11_1 = 316; + public static final int MINECRAFT_1_12 = 329; public static final List SUPPORTED_VERSIONS = Arrays.asList( "1.8.x", "1.9.x", "1.10.x", - "1.11.x" + "1.11.x", + "1.12.x" ); public static final List SUPPORTED_VERSION_IDS = Arrays.asList( ProtocolConstants.MINECRAFT_1_8, ProtocolConstants.MINECRAFT_1_9, @@ -27,7 +29,8 @@ public class ProtocolConstants ProtocolConstants.MINECRAFT_1_9_4, ProtocolConstants.MINECRAFT_1_10, ProtocolConstants.MINECRAFT_1_11, - ProtocolConstants.MINECRAFT_1_11_1 + ProtocolConstants.MINECRAFT_1_11_1, + ProtocolConstants.MINECRAFT_1_12 ); public enum Direction diff --git a/proxy/pom.xml b/proxy/pom.xml index 850ab860..d2e864b2 100644 --- a/proxy/pom.xml +++ b/proxy/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-proxy - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-Proxy diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java index e103cc0a..6a794175 100644 --- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java @@ -42,6 +42,8 @@ public abstract class EntityMap case ProtocolConstants.MINECRAFT_1_11: case ProtocolConstants.MINECRAFT_1_11_1: return EntityMap_1_11.INSTANCE; + case ProtocolConstants.MINECRAFT_1_12: + return EntityMap_1_12.INSTANCE; } throw new RuntimeException( "Version " + version + " has no entity map" ); } @@ -182,6 +184,15 @@ public abstract class EntityMap case 12: DefinedPacket.readVarInt( packet ); break; + case 13: + try + { + new NBTInputStream( new ByteBufInputStream( packet ), false ).readTag(); + } catch ( IOException ex ) + { + throw Throwables.propagate( ex ); + } + break; default: throw new IllegalArgumentException( "Unknown meta type " + type ); } diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_12.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_12.java new file mode 100644 index 00000000..3de2dfa9 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_12.java @@ -0,0 +1,182 @@ +package net.md_5.bungee.entitymap; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import io.netty.buffer.ByteBuf; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.UserConnection; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.ProtocolConstants; + +import java.util.UUID; + +class EntityMap_1_12 extends EntityMap +{ + + static final EntityMap_1_12 INSTANCE = new EntityMap_1_12(); + + EntityMap_1_12() + { + addRewrite( 0x00, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Object : PacketPlayOutSpawnEntity + addRewrite( 0x01, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Experience Orb : PacketPlayOutSpawnEntityExperienceOrb + addRewrite( 0x03, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Mob : PacketPlayOutSpawnEntityLiving + addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Painting : PacketPlayOutSpawnEntityPainting + addRewrite( 0x05, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Player : PacketPlayOutNamedEntitySpawn + addRewrite( 0x06, ProtocolConstants.Direction.TO_CLIENT, true ); // Animation : PacketPlayOutAnimation + addRewrite( 0x08, ProtocolConstants.Direction.TO_CLIENT, true ); // Block Break Animation : PacketPlayOutBlockBreakAnimation + addRewrite( 0x1C, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Status : PacketPlayOutEntityStatus + addRewrite( 0x26, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Relative Move : PacketPlayOutRelEntityMove + addRewrite( 0x27, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look and Relative Move : PacketPlayOutRelEntityMoveLook + addRewrite( 0x28, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look : PacketPlayOutEntityLook + addRewrite( 0x29, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity : PacketPlayOutEntity + addRewrite( 0x30, ProtocolConstants.Direction.TO_CLIENT, true ); // Use bed : PacketPlayOutBed + addRewrite( 0x33, ProtocolConstants.Direction.TO_CLIENT, true ); // Remove Entity Effect : PacketPlayOutRemoveEntityEffect + addRewrite( 0x36, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Head Look : PacketPlayOutEntityHeadRotation + addRewrite( 0x38, ProtocolConstants.Direction.TO_CLIENT, true ); // Camera : PacketPlayOutCamera + addRewrite( 0x3B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Metadata : PacketPlayOutEntityMetadata + addRewrite( 0x3C, ProtocolConstants.Direction.TO_CLIENT, false ); // Attach Entity : PacketPlayOutAttachEntity + addRewrite( 0x3D, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Velocity : PacketPlayOutEntityVelocity + addRewrite( 0x3E, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Equipment : PacketPlayOutEntityEquipment + addRewrite( 0x42, ProtocolConstants.Direction.TO_CLIENT, true ); // Set Passengers : PacketPlayOutMount + addRewrite( 0x4A, ProtocolConstants.Direction.TO_CLIENT, true ); // Collect Item : PacketPlayOutCollect + addRewrite( 0x4B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Teleport : PacketPlayOutEntityTeleport + addRewrite( 0x4C, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Properties : PacketPlayOutUpdateAttributes + addRewrite( 0x4D, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Effect : PacketPlayOutEntityEffect + + addRewrite( 0x0B, ProtocolConstants.Direction.TO_SERVER, true ); // Use Entity : PacketPlayInUseEntity + addRewrite( 0x15, ProtocolConstants.Direction.TO_SERVER, true ); // Entity Action : PacketPlayInEntityAction + } + + @Override + @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") + public void rewriteClientbound(ByteBuf packet, int oldId, int newId) + { + super.rewriteClientbound( packet, oldId, newId ); + + // Special cases + int readerIndex = packet.readerIndex(); + int packetId = DefinedPacket.readVarInt( packet ); + int packetIdLength = packet.readerIndex() - readerIndex; + int jumpIndex = packet.readerIndex(); + switch ( packetId ) + { + case 0x3C /* Attach Entity : PacketPlayOutAttachEntity */: + rewriteInt( packet, oldId, newId, readerIndex + packetIdLength + 4 ); + break; + case 0x4A /* Collect Item : PacketPlayOutCollect */: + DefinedPacket.readVarInt( packet ); + rewriteVarInt( packet, oldId, newId, packet.readerIndex() ); + break; + case 0x42 /* Attach Entity : PacketPlayOutMount */: + DefinedPacket.readVarInt( packet ); + jumpIndex = packet.readerIndex(); + // Fall through on purpose to int array of IDs + case 0x32 /* Destroy Entities : PacketPlayOutEntityDestroy */: + int count = DefinedPacket.readVarInt( packet ); + int[] ids = new int[ count ]; + for ( int i = 0; i < count; i++ ) + { + ids[i] = DefinedPacket.readVarInt( packet ); + } + packet.readerIndex( jumpIndex ); + packet.writerIndex( jumpIndex ); + DefinedPacket.writeVarInt( count, packet ); + for ( int id : ids ) + { + if ( id == oldId ) + { + id = newId; + } else if ( id == newId ) + { + id = oldId; + } + DefinedPacket.writeVarInt( id, packet ); + } + break; + case 0x00 /* Spawn Object : PacketPlayOutSpawnEntity */: + DefinedPacket.readVarInt( packet ); + DefinedPacket.readUUID( packet ); + int type = packet.readUnsignedByte(); + + if ( type == 60 || type == 90 || type == 91 ) + { + if ( type == 60 || type == 91 ) + { + oldId = oldId + 1; + newId = newId + 1; + } + + packet.skipBytes( 26 ); // double, double, double, byte, byte + int position = packet.readerIndex(); + int readId = packet.readInt(); + if ( readId == oldId ) + { + packet.setInt( position, newId ); + } else if ( readId == newId ) + { + packet.setInt( position, oldId ); + } + } + break; + case 0x05 /* Spawn Player : PacketPlayOutNamedEntitySpawn */: + DefinedPacket.readVarInt( packet ); // Entity ID + int idLength = packet.readerIndex() - readerIndex - packetIdLength; + UUID uuid = DefinedPacket.readUUID( packet ); + ProxiedPlayer player; + if ( ( player = BungeeCord.getInstance().getPlayerByOfflineUUID( uuid ) ) != null ) + { + int previous = packet.writerIndex(); + packet.readerIndex( readerIndex ); + packet.writerIndex( readerIndex + packetIdLength + idLength ); + DefinedPacket.writeUUID( player.getUniqueId(), packet ); + packet.writerIndex( previous ); + } + break; + case 0x2D /* Combat Event : PacketPlayOutCombatEvent */: + int event = packet.readUnsignedByte(); + if ( event == 1 /* End Combat*/ ) + { + DefinedPacket.readVarInt( packet ); + rewriteInt( packet, oldId, newId, packet.readerIndex() ); + } else if ( event == 2 /* Entity Dead */ ) + { + int position = packet.readerIndex(); + rewriteVarInt( packet, oldId, newId, packet.readerIndex() ); + packet.readerIndex( position ); + DefinedPacket.readVarInt( packet ); + rewriteInt( packet, oldId, newId, packet.readerIndex() ); + } + break; + case 0x3B /* EntityMetadata : PacketPlayOutEntityMetadata */: + DefinedPacket.readVarInt( packet ); // Entity ID + rewriteMetaVarInt( packet, oldId, newId, 7 ); // fireworks (et al) + break; + } + packet.readerIndex( readerIndex ); + } + + @Override + public void rewriteServerbound(ByteBuf packet, int oldId, int newId) + { + super.rewriteServerbound( packet, oldId, newId ); + // Special cases + int readerIndex = packet.readerIndex(); + int packetId = DefinedPacket.readVarInt( packet ); + int packetIdLength = packet.readerIndex() - readerIndex; + + if ( packetId == 0x1D /* Spectate : PacketPlayInSpectate */ && !BungeeCord.getInstance().getConfig().isIpForward() ) + { + UUID uuid = DefinedPacket.readUUID( packet ); + ProxiedPlayer player; + if ( ( player = BungeeCord.getInstance().getPlayer( uuid ) ) != null ) + { + int previous = packet.writerIndex(); + packet.readerIndex( readerIndex ); + packet.writerIndex( readerIndex + packetIdLength ); + DefinedPacket.writeUUID( ( (UserConnection) player ).getPendingConnection().getOfflineId(), packet ); + packet.writerIndex( previous ); + } + } + packet.readerIndex( readerIndex ); + } +} diff --git a/query/pom.xml b/query/pom.xml index fbadb189..9ecb2612 100644 --- a/query/pom.xml +++ b/query/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.11-SNAPSHOT + 1.12-SNAPSHOT ../pom.xml net.md-5 bungeecord-query - 1.11-SNAPSHOT + 1.12-SNAPSHOT jar BungeeCord-Query