Minecraft 1.16.2 support

This commit is contained in:
md_5 2020-08-12 07:14:42 +10:00
parent 15b514130e
commit aa22fe68e5
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
11 changed files with 120 additions and 227 deletions

View File

@ -1,11 +1,19 @@
package net.md_5.bungee.protocol;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import se.llbit.nbt.NamedTag;
import se.llbit.nbt.Tag;
@RequiredArgsConstructor
public abstract class DefinedPacket
@ -195,6 +203,24 @@ public abstract class DefinedPacket
return new UUID( input.readLong(), input.readLong() );
}
public static Tag readTag(ByteBuf input)
{
Tag tag = NamedTag.read( new DataInputStream( new ByteBufInputStream( input ) ) );
Preconditions.checkArgument( !tag.isError(), "Error reading tag: %s", tag.error() );
return tag;
}
public static void writeTag(Tag tag, ByteBuf output)
{
try
{
tag.write( new DataOutputStream( new ByteBufOutputStream( output ) ) );
} catch ( IOException ex )
{
throw new RuntimeException( "Exception writing tag", ex );
}
}
public void read(ByteBuf buf)
{
throw new UnsupportedOperationException( "Packet must implement read method" );

View File

@ -68,7 +68,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_13, 0x21 ),
map( ProtocolConstants.MINECRAFT_1_14, 0x20 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x21 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x20 )
map( ProtocolConstants.MINECRAFT_1_16, 0x20 ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x1F )
);
TO_CLIENT.registerPacket(
Login.class,
@ -76,7 +77,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_9, 0x23 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x25 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x26 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x25 )
map( ProtocolConstants.MINECRAFT_1_16, 0x25 ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x24 )
);
TO_CLIENT.registerPacket(
Chat.class,
@ -95,7 +97,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_13, 0x38 ),
map( ProtocolConstants.MINECRAFT_1_14, 0x3A ),
map( ProtocolConstants.MINECRAFT_1_15, 0x3B ),
map( ProtocolConstants.MINECRAFT_1_16, 0x3A )
map( ProtocolConstants.MINECRAFT_1_16, 0x3A ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x39 )
);
TO_CLIENT.registerPacket(
BossBar.class,
@ -111,7 +114,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_13, 0x30 ),
map( ProtocolConstants.MINECRAFT_1_14, 0x33 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x34 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x33 )
map( ProtocolConstants.MINECRAFT_1_16, 0x33 ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x32 )
);
TO_CLIENT.registerPacket(
TabCompleteResponse.class,
@ -119,7 +123,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_9, 0x0E ),
map( ProtocolConstants.MINECRAFT_1_13, 0x10 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x11 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x10 )
map( ProtocolConstants.MINECRAFT_1_16, 0x10 ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x0F )
);
TO_CLIENT.registerPacket(
ScoreboardObjective.class,
@ -168,7 +173,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_13, 0x19 ),
map( ProtocolConstants.MINECRAFT_1_14, 0x18 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x19 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x18 )
map( ProtocolConstants.MINECRAFT_1_16, 0x18 ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x17 )
);
TO_CLIENT.registerPacket(
Kick.class,
@ -177,7 +183,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_13, 0x1B ),
map( ProtocolConstants.MINECRAFT_1_14, 0x1A ),
map( ProtocolConstants.MINECRAFT_1_15, 0x1B ),
map( ProtocolConstants.MINECRAFT_1_16, 0x1A )
map( ProtocolConstants.MINECRAFT_1_16, 0x1A ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x19 )
);
TO_CLIENT.registerPacket(
Title.class,
@ -208,18 +215,21 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_13, 0x1C ),
map( ProtocolConstants.MINECRAFT_1_14, 0x1B ),
map( ProtocolConstants.MINECRAFT_1_15, 0x1C ),
map( ProtocolConstants.MINECRAFT_1_16, 0x1B )
map( ProtocolConstants.MINECRAFT_1_16, 0x1B ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x1A )
);
TO_CLIENT.registerPacket(
Commands.class,
map( ProtocolConstants.MINECRAFT_1_13, 0x11 ),
map( ProtocolConstants.MINECRAFT_1_15, 0x12 ),
map( ProtocolConstants.MINECRAFT_1_16, 0x11 )
map( ProtocolConstants.MINECRAFT_1_16, 0x11 ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x10 )
);
TO_CLIENT.registerPacket(
GameState.class,
map( ProtocolConstants.MINECRAFT_1_15, 0x1F ),
map( ProtocolConstants.MINECRAFT_1_16, 0x1E )
map( ProtocolConstants.MINECRAFT_1_16, 0x1E ),
map( ProtocolConstants.MINECRAFT_1_16_2, 0x1D )
);
TO_CLIENT.registerPacket(
ViewDistance.class,

View File

@ -30,6 +30,7 @@ public class ProtocolConstants
public static final int MINECRAFT_1_15_2 = 578;
public static final int MINECRAFT_1_16 = 735;
public static final int MINECRAFT_1_16_1 = 736;
public static final int MINECRAFT_1_16_2 = 751;
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
"1.8.x",
"1.9.x",
@ -65,7 +66,8 @@ public class ProtocolConstants
ProtocolConstants.MINECRAFT_1_15_1,
ProtocolConstants.MINECRAFT_1_15_2,
ProtocolConstants.MINECRAFT_1_16,
ProtocolConstants.MINECRAFT_1_16_1
ProtocolConstants.MINECRAFT_1_16_1,
ProtocolConstants.MINECRAFT_1_16_2
);
public enum Direction

View File

@ -550,6 +550,7 @@ public class Commands extends DefinedPacket
PROVIDERS.put( "minecraft:uuid", VOID ); // 1.16
PROVIDERS.put( "minecraft:test_argument", VOID ); // 1.16, debug
PROVIDERS.put( "minecraft:test_class", VOID ); // 1.16, debug
PROVIDERS.put( "minecraft:angle", VOID ); // 1.16.2
}
private static ArgumentType<?> read(String key, ByteBuf buf)

View File

@ -2,11 +2,6 @@ package net.md_5.bungee.protocol.packet;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import lombok.AllArgsConstructor;
@ -16,7 +11,6 @@ import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
import se.llbit.nbt.NamedTag;
import se.llbit.nbt.Tag;
@Data
@ -27,6 +21,7 @@ public class Login extends DefinedPacket
{
private int entityId;
private boolean hardcore;
private short gameMode;
private short previousGameMode;
private Set<String> worldNames;
@ -35,7 +30,7 @@ public class Login extends DefinedPacket
private String worldName;
private long seed;
private short difficulty;
private short maxPlayers;
private int maxPlayers;
private String levelType;
private int viewDistance;
private boolean reducedDebugInfo;
@ -47,6 +42,10 @@ public class Login extends DefinedPacket
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
entityId = buf.readInt();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16_2 )
{
hardcore = buf.readBoolean();
}
gameMode = buf.readUnsignedByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
@ -61,13 +60,18 @@ public class Login extends DefinedPacket
worldNames.add( readString( buf ) );
}
dimensions = NamedTag.read( new DataInputStream( new ByteBufInputStream( buf ) ) );
Preconditions.checkArgument( !dimensions.isError(), "Error reading dimensions: %s", dimensions.error() );
dimensions = readTag( buf );
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
dimension = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16_2 )
{
dimension = readTag( buf );
} else
{
dimension = readString( buf );
}
worldName = readString( buf );
} else if ( protocolVersion > ProtocolConstants.MINECRAFT_1_9 )
{
@ -84,7 +88,13 @@ public class Login extends DefinedPacket
{
difficulty = buf.readUnsignedByte();
}
maxPlayers = buf.readUnsignedByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16_2 )
{
maxPlayers = readVarInt( buf );
} else
{
maxPlayers = buf.readUnsignedByte();
}
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_16 )
{
levelType = readString( buf );
@ -112,6 +122,10 @@ public class Login extends DefinedPacket
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
buf.writeInt( entityId );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16_2 )
{
buf.writeBoolean( hardcore );
}
buf.writeByte( gameMode );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
@ -123,18 +137,18 @@ public class Login extends DefinedPacket
writeString( world, buf );
}
try
{
dimensions.write( new DataOutputStream( new ByteBufOutputStream( buf ) ) );
} catch ( IOException ex )
{
throw new RuntimeException( "Exception writing dimensions", ex );
}
writeTag( dimensions, buf );
}
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
writeString( (String) dimension, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16_2 )
{
writeTag( (Tag) dimension, buf );
} else
{
writeString( (String) dimension, buf );
}
writeString( worldName, buf );
} else if ( protocolVersion > ProtocolConstants.MINECRAFT_1_9 )
{
@ -151,7 +165,13 @@ public class Login extends DefinedPacket
{
buf.writeByte( difficulty );
}
buf.writeByte( maxPlayers );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16_2 )
{
writeVarInt( maxPlayers, buf );
} else
{
buf.writeByte( maxPlayers );
}
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_16 )
{
writeString( levelType, buf );

View File

@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
import net.md_5.bungee.protocol.AbstractPacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
import net.md_5.bungee.protocol.ProtocolConstants;
import se.llbit.nbt.Tag;
@Data
@NoArgsConstructor
@ -32,7 +33,13 @@ public class Respawn extends DefinedPacket
{
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
dimension = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16_2 )
{
dimension = readTag( buf );
} else
{
dimension = readString( buf );
}
worldName = readString( buf );
} else
{
@ -64,7 +71,13 @@ public class Respawn extends DefinedPacket
{
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16 )
{
writeString( (String) dimension, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_16_2 )
{
writeTag( (Tag) dimension, buf );
} else
{
writeString( (String) dimension, buf );
}
writeString( worldName, buf );
} else
{

View File

@ -212,7 +212,7 @@ public class ServerConnector extends PacketHandler
user.setServerEntityId( login.getEntityId() );
// Set tab list size, TODO: what shall we do about packet mutability
Login modLogin = new Login( login.getEntityId(), login.getGameMode(), login.getPreviousGameMode(), login.getWorldNames(), login.getDimensions(), login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(),
Login modLogin = new Login( login.getEntityId(), login.isHardcore(), login.getGameMode(), login.getPreviousGameMode(), login.getWorldNames(), login.getDimensions(), login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(),
(byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.isReducedDebugInfo(), login.isNormalRespawn(), login.isDebug(), login.isFlat() );
user.unsafe().sendPacket( modLogin );

View File

@ -43,6 +43,7 @@ import net.md_5.bungee.api.score.Score;
import net.md_5.bungee.api.score.Scoreboard;
import net.md_5.bungee.api.score.Team;
import net.md_5.bungee.chat.ComponentSerializer;
import net.md_5.bungee.entitymap.EntityMap;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler;
import net.md_5.bungee.protocol.DefinedPacket;
@ -119,7 +120,11 @@ public class DownstreamBridge extends PacketHandler
@Override
public void handle(PacketWrapper packet) throws Exception
{
con.getEntityRewrite().rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId(), con.getPendingConnection().getVersion() );
EntityMap rewrite = con.getEntityRewrite();
if ( rewrite != null )
{
rewrite.rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId(), con.getPendingConnection().getVersion() );
}
con.sendPacket( packet );
}

View File

@ -19,6 +19,7 @@ import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.event.SettingsChangedEvent;
import net.md_5.bungee.api.event.TabCompleteEvent;
import net.md_5.bungee.entitymap.EntityMap;
import net.md_5.bungee.forge.ForgeConstants;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler;
@ -114,7 +115,11 @@ public class UpstreamBridge extends PacketHandler
{
if ( con.getServer() != null )
{
con.getEntityRewrite().rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId(), con.getPendingConnection().getVersion() );
EntityMap rewrite = con.getEntityRewrite();
if ( rewrite != null )
{
rewrite.rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId(), con.getPendingConnection().getVersion() );
}
con.getServer().getCh().write( packet );
}
}

View File

@ -61,11 +61,9 @@ public abstract class EntityMap
case ProtocolConstants.MINECRAFT_1_15_1:
case ProtocolConstants.MINECRAFT_1_15_2:
return EntityMap_1_15.INSTANCE;
case ProtocolConstants.MINECRAFT_1_16:
case ProtocolConstants.MINECRAFT_1_16_1:
return EntityMap_1_16.INSTANCE;
default:
return null;
}
throw new RuntimeException( "Version " + version + " has no entity map" );
}
protected void addRewrite(int id, ProtocolConstants.Direction direction, boolean varint)

View File

@ -1,187 +0,0 @@
package net.md_5.bungee.entitymap;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
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;
class EntityMap_1_16 extends EntityMap
{
static final EntityMap_1_16 INSTANCE = new EntityMap_1_16();
EntityMap_1_16()
{
addRewrite( 0x00, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Object : PacketPlayOutSpawnEntity
addRewrite( 0x01, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Experience Orb : PacketPlayOutSpawnEntityExperienceOrb
addRewrite( 0x02, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Mob : PacketPlayOutSpawnEntityLiving
addRewrite( 0x03, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Painting : PacketPlayOutSpawnEntityPainting
addRewrite( 0x04, ProtocolConstants.Direction.TO_CLIENT, true ); // Spawn Player : PacketPlayOutNamedEntitySpawn
addRewrite( 0x05, ProtocolConstants.Direction.TO_CLIENT, true ); // Animation : PacketPlayOutAnimation
addRewrite( 0x08, ProtocolConstants.Direction.TO_CLIENT, true ); // Block Break Animation : PacketPlayOutBlockBreakAnimation
addRewrite( 0x1B, ProtocolConstants.Direction.TO_CLIENT, false ); // Entity Status : PacketPlayOutEntityStatus
addRewrite( 0x28, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Relative Move : PacketPlayOutRelEntityMove
addRewrite( 0x29, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look and Relative Move : PacketPlayOutRelEntityMoveLook
addRewrite( 0x2A, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Look : PacketPlayOutEntityLook
addRewrite( 0x2B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity : PacketPlayOutEntity
addRewrite( 0x38, ProtocolConstants.Direction.TO_CLIENT, true ); // Remove Entity Effect : PacketPlayOutRemoveEntityEffect
addRewrite( 0x3B, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Head Look : PacketPlayOutEntityHeadRotation
addRewrite( 0x3E, ProtocolConstants.Direction.TO_CLIENT, true ); // Camera : PacketPlayOutCamera
addRewrite( 0x44, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Metadata : PacketPlayOutEntityMetadata
addRewrite( 0x45, ProtocolConstants.Direction.TO_CLIENT, false ); // Attach Entity : PacketPlayOutAttachEntity
addRewrite( 0x46, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Velocity : PacketPlayOutEntityVelocity
addRewrite( 0x47, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Equipment : PacketPlayOutEntityEquipment
addRewrite( 0x4B, ProtocolConstants.Direction.TO_CLIENT, true ); // Set Passengers : PacketPlayOutMount
addRewrite( 0x55, ProtocolConstants.Direction.TO_CLIENT, true ); // Collect Item : PacketPlayOutCollect
addRewrite( 0x56, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Teleport : PacketPlayOutEntityTeleport
addRewrite( 0x58, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Properties : PacketPlayOutUpdateAttributes
addRewrite( 0x59, ProtocolConstants.Direction.TO_CLIENT, true ); // Entity Effect : PacketPlayOutEntityEffect
addRewrite( 0x0E, ProtocolConstants.Direction.TO_SERVER, true ); // Use Entity : PacketPlayInUseEntity
addRewrite( 0x1C, ProtocolConstants.Direction.TO_SERVER, true ); // Entity Action : PacketPlayInEntityAction
}
@Override
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
public void rewriteClientbound(ByteBuf packet, int oldId, int newId, int protocolVersion)
{
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 0x45 /* Attach Entity : PacketPlayOutAttachEntity */:
rewriteInt( packet, oldId, newId, readerIndex + packetIdLength + 4 );
break;
case 0x55 /* Collect Item : PacketPlayOutCollect */:
DefinedPacket.readVarInt( packet );
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
break;
case 0x4B /* Set Passengers : PacketPlayOutMount */:
DefinedPacket.readVarInt( packet );
jumpIndex = packet.readerIndex();
// Fall through on purpose to int array of IDs
case 0x37 /* 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 = DefinedPacket.readVarInt( packet );
if ( type == 2 || type == 102 || type == 72 ) // arrow, fishing_bobber or spectral_arrow
{
if ( type == 2 || type == 72 ) // arrow or spectral_arrow
{
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 0x04 /* 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 0x32 /* 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 0x44 /* EntityMetadata : PacketPlayOutEntityMetadata */:
DefinedPacket.readVarInt( packet ); // Entity ID
rewriteMetaVarInt( packet, oldId + 1, newId + 1, 7, protocolVersion ); // fishing hook
rewriteMetaVarInt( packet, oldId, newId, 8, protocolVersion ); // fireworks (et al)
rewriteMetaVarInt( packet, oldId, newId, 16, protocolVersion ); // guardian beam
break;
case 0x50 /* Entity Sound Effect : PacketPlayOutEntitySound */:
DefinedPacket.readVarInt( packet );
DefinedPacket.readVarInt( packet );
rewriteVarInt( packet, oldId, newId, packet.readerIndex() );
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 == 0x2C /* 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 );
}
}