Add support for Minecraft 1.8.x
This commit allows BungeeCord to support Minecraft clients both of versions 1.7.x and of 1.8.x. There should be no breakages to any other support, however following their deprecation and uselessness within 1.8, the Tab list APIs have been removed. Please report any issues to GitHub and be sure to mention client, server and BungeeCord versions. When used with an appropriate server jar (such as multi protocol Spigot), this will allow clients of many versions to concurrently be connected to the same set of servers.
This commit is contained in:
@@ -7,6 +7,7 @@ import net.md_5.bungee.protocol.packet.Login;
|
||||
import net.md_5.bungee.protocol.packet.Chat;
|
||||
import net.md_5.bungee.protocol.packet.EncryptionRequest;
|
||||
import net.md_5.bungee.protocol.packet.PlayerListItem;
|
||||
import net.md_5.bungee.protocol.packet.SetCompression;
|
||||
import net.md_5.bungee.protocol.packet.TabCompleteRequest;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardScore;
|
||||
@@ -128,4 +129,8 @@ public abstract class AbstractPacketHandler
|
||||
public void handle(LegacyHandshake legacyHandshake) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(SetCompression setCompression) throws Exception
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@ import com.google.common.base.Preconditions;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class DefinedPacket
|
||||
{
|
||||
@@ -29,7 +31,7 @@ public abstract class DefinedPacket
|
||||
return new String( b, Charsets.UTF_8 );
|
||||
}
|
||||
|
||||
public static void writeArray(byte[] b, ByteBuf buf)
|
||||
public static void writeArrayLegacy(byte[] b, ByteBuf buf)
|
||||
{
|
||||
Preconditions.checkArgument( b.length <= Short.MAX_VALUE, "Cannot send array longer than Short.MAX_VALUE (got %s bytes)", b.length );
|
||||
|
||||
@@ -37,7 +39,7 @@ public abstract class DefinedPacket
|
||||
buf.writeBytes( b );
|
||||
}
|
||||
|
||||
public static byte[] readArray(ByteBuf buf)
|
||||
public static byte[] readArrayLegacy(ByteBuf buf)
|
||||
{
|
||||
short len = buf.readShort();
|
||||
Preconditions.checkArgument( len <= Short.MAX_VALUE, "Cannot receive array longer than Short.MAX_VALUE (got %s bytes)", len );
|
||||
@@ -47,6 +49,19 @@ public abstract class DefinedPacket
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void writeArray(byte[] b, ByteBuf buf)
|
||||
{
|
||||
writeVarInt( b.length, buf );
|
||||
buf.writeBytes( b );
|
||||
}
|
||||
|
||||
public static byte[] readArray(ByteBuf buf)
|
||||
{
|
||||
byte[] ret = new byte[ readVarInt( buf ) ];
|
||||
buf.readBytes( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void writeStringArray(String[] s, ByteBuf buf)
|
||||
{
|
||||
writeVarInt( s.length, buf );
|
||||
@@ -114,6 +129,17 @@ public abstract class DefinedPacket
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeUUID(UUID value, ByteBuf output)
|
||||
{
|
||||
output.writeLong( value.getMostSignificantBits() );
|
||||
output.writeLong( value.getLeastSignificantBits() );
|
||||
}
|
||||
|
||||
public static UUID readUUID(ByteBuf input)
|
||||
{
|
||||
return new UUID( input.readLong(), input.readLong() );
|
||||
}
|
||||
|
||||
public void read(ByteBuf buf)
|
||||
{
|
||||
throw new UnsupportedOperationException( "Packet must implement read method" );
|
||||
|
@@ -0,0 +1,43 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.zip.Deflater;
|
||||
|
||||
public class PacketCompressor extends MessageToByteEncoder<ByteBuf>
|
||||
{
|
||||
|
||||
private final byte[] buffer = new byte[ 8192 ];
|
||||
private final Deflater deflater = new Deflater();
|
||||
@Setter
|
||||
private int threshold = 256;
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception
|
||||
{
|
||||
int origSize = msg.readableBytes();
|
||||
if ( origSize < threshold )
|
||||
{
|
||||
DefinedPacket.writeVarInt( 0, out );
|
||||
out.writeBytes( msg );
|
||||
} else
|
||||
{
|
||||
byte[] data = new byte[ origSize ];
|
||||
msg.readBytes( data );
|
||||
|
||||
DefinedPacket.writeVarInt( data.length, out );
|
||||
|
||||
deflater.setInput( data );
|
||||
deflater.finish();
|
||||
while ( !deflater.finished() )
|
||||
{
|
||||
int count = deflater.deflate( buffer );
|
||||
out.writeBytes( buffer, 0, count );
|
||||
}
|
||||
deflater.reset();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package net.md_5.bungee.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
public class PacketDecompressor extends ByteToMessageDecoder
|
||||
{
|
||||
|
||||
private final Inflater inflater = new Inflater();
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
|
||||
{
|
||||
if ( in.readableBytes() == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int size = DefinedPacket.readVarInt( in );
|
||||
if ( size == 0 )
|
||||
{
|
||||
out.add( in.readBytes( in.readableBytes() ) );
|
||||
} else
|
||||
{
|
||||
byte[] compressedData = new byte[ in.readableBytes() ];
|
||||
in.readBytes( compressedData );
|
||||
inflater.setInput( compressedData );
|
||||
|
||||
byte[] data = new byte[ size ];
|
||||
inflater.inflate( data );
|
||||
out.add( Unpooled.wrappedBuffer( data ) );
|
||||
inflater.reset();
|
||||
}
|
||||
}
|
||||
}
|
@@ -25,6 +25,7 @@ import net.md_5.bungee.protocol.packet.Respawn;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardDisplay;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardScore;
|
||||
import net.md_5.bungee.protocol.packet.SetCompression;
|
||||
import net.md_5.bungee.protocol.packet.StatusRequest;
|
||||
import net.md_5.bungee.protocol.packet.StatusResponse;
|
||||
import net.md_5.bungee.protocol.packet.TabCompleteRequest;
|
||||
@@ -59,6 +60,7 @@ public enum Protocol
|
||||
TO_CLIENT.registerPacket( 0x3E, Team.class );
|
||||
TO_CLIENT.registerPacket( 0x3F, PluginMessage.class );
|
||||
TO_CLIENT.registerPacket( 0x40, Kick.class );
|
||||
TO_CLIENT.registerPacket( 0x46, SetCompression.class );
|
||||
|
||||
TO_SERVER.registerPacket( 0x00, KeepAlive.class );
|
||||
TO_SERVER.registerPacket( 0x01, Chat.class );
|
||||
@@ -87,6 +89,7 @@ public enum Protocol
|
||||
TO_CLIENT.registerPacket( 0x00, Kick.class );
|
||||
TO_CLIENT.registerPacket( 0x01, EncryptionRequest.class );
|
||||
TO_CLIENT.registerPacket( 0x02, LoginSuccess.class );
|
||||
TO_CLIENT.registerPacket( 0x03, SetCompression.class );
|
||||
|
||||
TO_SERVER.registerPacket( 0x00, LoginRequest.class );
|
||||
TO_SERVER.registerPacket( 0x01, EncryptionResponse.class );
|
||||
@@ -94,7 +97,11 @@ public enum Protocol
|
||||
};
|
||||
/*========================================================================*/
|
||||
public static final int MAX_PACKET_ID = 0xFF;
|
||||
public static List<Integer> supportedVersions = Arrays.asList( ProtocolConstants.MINECRAFT_1_7_2, ProtocolConstants.MINECRAFT_1_7_6, ProtocolConstants.MINECRAFT_14_11_a );
|
||||
public static List<Integer> supportedVersions = Arrays.asList(
|
||||
ProtocolConstants.MINECRAFT_1_7_2,
|
||||
ProtocolConstants.MINECRAFT_1_7_6,
|
||||
ProtocolConstants.MINECRAFT_SNAPSHOT
|
||||
);
|
||||
/*========================================================================*/
|
||||
public final DirectionData TO_SERVER = new DirectionData( ProtocolConstants.Direction.TO_SERVER );
|
||||
public final DirectionData TO_CLIENT = new DirectionData( ProtocolConstants.Direction.TO_CLIENT );
|
||||
|
@@ -5,7 +5,7 @@ public class ProtocolConstants
|
||||
|
||||
public static final int MINECRAFT_1_7_2 = 4;
|
||||
public static final int MINECRAFT_1_7_6 = 5;
|
||||
public static final int MINECRAFT_14_11_a = 14;
|
||||
public static final int MINECRAFT_SNAPSHOT = 46;
|
||||
|
||||
public enum Direction
|
||||
{
|
||||
|
@@ -28,7 +28,7 @@ public class Chat extends DefinedPacket
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
message = readString( buf );
|
||||
if ( direction == ProtocolConstants.Direction.TO_CLIENT && protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( direction == ProtocolConstants.Direction.TO_CLIENT && protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
position = buf.readByte();
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class Chat extends DefinedPacket
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeString( message, buf );
|
||||
if ( direction == ProtocolConstants.Direction.TO_CLIENT && protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( direction == ProtocolConstants.Direction.TO_CLIENT && protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
buf.writeByte( position );
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@@ -20,19 +21,33 @@ public class EncryptionRequest extends DefinedPacket
|
||||
private byte[] verifyToken;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
serverId = readString( buf );
|
||||
publicKey = readArray( buf );
|
||||
verifyToken = readArray( buf );
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
publicKey = readArrayLegacy( buf );
|
||||
verifyToken = readArrayLegacy( buf );
|
||||
} else
|
||||
{
|
||||
publicKey = readArray( buf );
|
||||
verifyToken = readArray( buf );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeString( serverId, buf );
|
||||
writeArray( publicKey, buf );
|
||||
writeArray( verifyToken, buf );
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
writeArrayLegacy( publicKey, buf );
|
||||
writeArrayLegacy( verifyToken, buf );
|
||||
} else
|
||||
{
|
||||
writeArray( publicKey, buf );
|
||||
writeArray( verifyToken, buf );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -7,6 +7,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@@ -19,17 +20,31 @@ public class EncryptionResponse extends DefinedPacket
|
||||
private byte[] verifyToken;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
sharedSecret = readArray( buf );
|
||||
verifyToken = readArray( buf );
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
sharedSecret = readArrayLegacy( buf );
|
||||
verifyToken = readArrayLegacy( buf );
|
||||
} else
|
||||
{
|
||||
sharedSecret = readArray( buf );
|
||||
verifyToken = readArray( buf );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeArray( sharedSecret, buf );
|
||||
writeArray( verifyToken, buf );
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
writeArrayLegacy( sharedSecret, buf );
|
||||
writeArrayLegacy( verifyToken, buf );
|
||||
} else
|
||||
{
|
||||
writeArray( sharedSecret, buf );
|
||||
writeArray( verifyToken, buf );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -21,7 +21,7 @@ public class KeepAlive extends DefinedPacket
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
if ( direction == ProtocolConstants.Direction.TO_SERVER && protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
randomId = readVarInt( buf );
|
||||
} else
|
||||
@@ -33,7 +33,7 @@ public class KeepAlive extends DefinedPacket
|
||||
@Override
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
if ( direction == ProtocolConstants.Direction.TO_SERVER && protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
writeVarInt( randomId, buf );
|
||||
} else
|
||||
|
@@ -7,6 +7,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@@ -21,9 +22,10 @@ public class Login extends DefinedPacket
|
||||
private short difficulty;
|
||||
private short maxPlayers;
|
||||
private String levelType;
|
||||
private boolean reducedDebugInfo;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
entityId = buf.readInt();
|
||||
gameMode = buf.readUnsignedByte();
|
||||
@@ -31,10 +33,14 @@ public class Login extends DefinedPacket
|
||||
difficulty = buf.readUnsignedByte();
|
||||
maxPlayers = buf.readUnsignedByte();
|
||||
levelType = readString( buf );
|
||||
if ( protocolVersion >= 29 )
|
||||
{
|
||||
reducedDebugInfo = buf.readBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
buf.writeInt( entityId );
|
||||
buf.writeByte( gameMode );
|
||||
@@ -42,6 +48,10 @@ public class Login extends DefinedPacket
|
||||
buf.writeByte( difficulty );
|
||||
buf.writeByte( maxPlayers );
|
||||
writeString( levelType, buf );
|
||||
if ( protocolVersion >= 29 )
|
||||
{
|
||||
buf.writeBoolean( reducedDebugInfo );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -2,49 +2,144 @@ package net.md_5.bungee.protocol.packet;
|
||||
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PlayerListItem extends DefinedPacket
|
||||
{
|
||||
|
||||
private String username;
|
||||
private boolean online;
|
||||
private int ping;
|
||||
private Action action;
|
||||
private Item[] items;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
username = readString( buf );
|
||||
online = buf.readBoolean();
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
ping = readVarInt( buf );
|
||||
items = new Item[ 1 ];
|
||||
Item item = items[ 0 ] = new Item();
|
||||
item.displayName = item.username = readString( buf );
|
||||
action = !buf.readBoolean() ? Action.REMOVE_PLAYER : Action.ADD_PLAYER;
|
||||
item.ping = buf.readShort();
|
||||
} else
|
||||
{
|
||||
ping = buf.readShort();
|
||||
action = Action.values()[ DefinedPacket.readVarInt( buf )];
|
||||
items = new Item[ DefinedPacket.readVarInt( buf ) ];
|
||||
for ( int i = 0; i < items.length; i++ )
|
||||
{
|
||||
Item item = items[ i ] = new Item();
|
||||
item.setUuid( DefinedPacket.readUUID( buf ) );
|
||||
switch ( action )
|
||||
{
|
||||
case ADD_PLAYER:
|
||||
item.username = DefinedPacket.readString( buf );
|
||||
item.properties = new String[ DefinedPacket.readVarInt( buf ) ][];
|
||||
for ( int j = 0; j < item.properties.length; j++ )
|
||||
{
|
||||
String name = DefinedPacket.readString( buf );
|
||||
String value = DefinedPacket.readString( buf );
|
||||
if ( buf.readBoolean() )
|
||||
{
|
||||
item.properties[ j] = new String[]
|
||||
{
|
||||
name, value, DefinedPacket.readString( buf )
|
||||
};
|
||||
} else
|
||||
{
|
||||
item.properties[ j ] = new String[]
|
||||
{
|
||||
name, value
|
||||
};
|
||||
}
|
||||
}
|
||||
item.gamemode = DefinedPacket.readVarInt( buf );
|
||||
item.ping = DefinedPacket.readVarInt( buf );
|
||||
if ( buf.readBoolean() )
|
||||
{
|
||||
item.displayName = DefinedPacket.readString( buf );
|
||||
}
|
||||
break;
|
||||
case UPDATE_GAMEMODE:
|
||||
item.gamemode = DefinedPacket.readVarInt( buf );
|
||||
break;
|
||||
case UPDATE_LATENCY:
|
||||
item.ping = DefinedPacket.readVarInt( buf );
|
||||
break;
|
||||
case UPDATE_DISPLAY_NAME:
|
||||
if ( buf.readBoolean() )
|
||||
{
|
||||
item.displayName = DefinedPacket.readString( buf );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeString( username, buf );
|
||||
buf.writeBoolean( online );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
writeVarInt( ping, buf );
|
||||
Item item = items[0]; // Only one at a time
|
||||
writeString( item.displayName, buf );
|
||||
buf.writeBoolean( action != Action.REMOVE_PLAYER );
|
||||
buf.writeShort( item.ping );
|
||||
} else
|
||||
{
|
||||
buf.writeShort( ping );
|
||||
DefinedPacket.writeVarInt( action.ordinal(), buf );
|
||||
DefinedPacket.writeVarInt( items.length, buf );
|
||||
for ( Item item : items )
|
||||
{
|
||||
DefinedPacket.writeUUID( item.uuid, buf );
|
||||
switch ( action )
|
||||
{
|
||||
case ADD_PLAYER:
|
||||
DefinedPacket.writeString( item.username, buf );
|
||||
DefinedPacket.writeVarInt( item.properties.length, buf );
|
||||
for ( String[] prop : item.properties )
|
||||
{
|
||||
DefinedPacket.writeString( prop[ 0], buf );
|
||||
DefinedPacket.writeString( prop[ 1], buf );
|
||||
if ( prop.length >= 3 )
|
||||
{
|
||||
buf.writeBoolean( true );
|
||||
DefinedPacket.writeString( prop[ 2], buf );
|
||||
} else
|
||||
{
|
||||
buf.writeBoolean( false );
|
||||
}
|
||||
}
|
||||
DefinedPacket.writeVarInt( item.gamemode, buf );
|
||||
DefinedPacket.writeVarInt( item.ping, buf );
|
||||
buf.writeBoolean( item.displayName != null );
|
||||
if ( item.displayName != null )
|
||||
{
|
||||
DefinedPacket.writeString( item.displayName, buf );
|
||||
}
|
||||
break;
|
||||
case UPDATE_GAMEMODE:
|
||||
DefinedPacket.writeVarInt( item.gamemode, buf );
|
||||
break;
|
||||
case UPDATE_LATENCY:
|
||||
DefinedPacket.writeVarInt( item.ping, buf );
|
||||
break;
|
||||
case UPDATE_DISPLAY_NAME:
|
||||
buf.writeBoolean( item.displayName != null );
|
||||
if ( item.displayName != null )
|
||||
{
|
||||
DefinedPacket.writeString( item.displayName, buf );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,4 +148,36 @@ public class PlayerListItem extends DefinedPacket
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
|
||||
public static enum Action
|
||||
{
|
||||
|
||||
ADD_PLAYER,
|
||||
UPDATE_GAMEMODE,
|
||||
UPDATE_LATENCY,
|
||||
UPDATE_DISPLAY_NAME,
|
||||
REMOVE_PLAYER;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Item
|
||||
{
|
||||
|
||||
// ALL
|
||||
private UUID uuid;
|
||||
|
||||
// ADD_PLAYER
|
||||
private String username;
|
||||
private String[][] properties;
|
||||
|
||||
// ADD_PLAYER & UPDATE_GAMEMODE
|
||||
private int gamemode;
|
||||
|
||||
// ADD_PLAYER & UPDATE_LATENCY
|
||||
private int ping;
|
||||
|
||||
// ADD_PLAYER & UPDATE_DISPLAY_NAME
|
||||
private String displayName;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.MinecraftInput;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@@ -24,17 +25,30 @@ public class PluginMessage extends DefinedPacket
|
||||
private byte[] data;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
tag = readString( buf );
|
||||
data = readArray( buf );
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
data = readArrayLegacy( buf );
|
||||
} else
|
||||
{
|
||||
data = new byte[ buf.readableBytes() ];
|
||||
buf.readBytes( data );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeString( tag, buf );
|
||||
writeArray( data, buf );
|
||||
if ( protocolVersion < ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
writeArrayLegacy( data, buf );
|
||||
} else
|
||||
{
|
||||
buf.writeBytes( data );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -33,7 +33,7 @@ public class ScoreboardObjective extends DefinedPacket
|
||||
value = readString( buf );
|
||||
}
|
||||
action = buf.readByte();
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a && ( action == 0 || action == 2 ) )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT && ( action == 0 || action == 2 ) )
|
||||
{
|
||||
value = readString( buf );
|
||||
type = readString( buf );
|
||||
@@ -49,7 +49,7 @@ public class ScoreboardObjective extends DefinedPacket
|
||||
writeString( value, buf );
|
||||
}
|
||||
buf.writeByte( action );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a && ( action == 0 || action == 2 ) )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT && ( action == 0 || action == 2 ) )
|
||||
{
|
||||
writeString( value, buf );
|
||||
writeString( type, buf );
|
||||
|
@@ -29,14 +29,18 @@ public class ScoreboardScore extends DefinedPacket
|
||||
{
|
||||
itemName = readString( buf );
|
||||
action = buf.readByte();
|
||||
if ( action != 1 )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
scoreName = readString( buf );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( action != 1 )
|
||||
{
|
||||
value = readVarInt( buf );
|
||||
} else
|
||||
}
|
||||
} else
|
||||
{
|
||||
if ( action != 1 )
|
||||
{
|
||||
scoreName = readString( buf );
|
||||
value = buf.readInt();
|
||||
}
|
||||
}
|
||||
@@ -47,14 +51,18 @@ public class ScoreboardScore extends DefinedPacket
|
||||
{
|
||||
writeString( itemName, buf );
|
||||
buf.writeByte( action );
|
||||
if ( action != 1 )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
writeString( scoreName, buf );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( action != 1 )
|
||||
{
|
||||
writeVarInt( value, buf );
|
||||
} else
|
||||
}
|
||||
} else
|
||||
{
|
||||
if ( action != 1 )
|
||||
{
|
||||
writeString( scoreName, buf );
|
||||
buf.writeInt( value );
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,38 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SetCompression extends DefinedPacket
|
||||
{
|
||||
|
||||
private int threshold;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
threshold = DefinedPacket.readVarInt( buf );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
DefinedPacket.writeVarInt( threshold, buf );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(AbstractPacketHandler handler) throws Exception
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@@ -16,17 +17,34 @@ public class TabCompleteRequest extends DefinedPacket
|
||||
{
|
||||
|
||||
private String cursor;
|
||||
private boolean hasPositon;
|
||||
private long position;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
cursor = readString( buf );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
if ( hasPositon = buf.readBoolean() )
|
||||
{
|
||||
position = buf.readLong();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf)
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeString( cursor, buf );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
buf.writeBoolean( hasPositon );
|
||||
if ( hasPositon )
|
||||
{
|
||||
buf.writeLong( position );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -50,7 +50,7 @@ public class Team extends DefinedPacket
|
||||
prefix = readString( buf );
|
||||
suffix = readString( buf );
|
||||
friendlyFire = buf.readByte();
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
nameTagVisibility = readString( buf );
|
||||
color = buf.readByte();
|
||||
@@ -58,7 +58,7 @@ public class Team extends DefinedPacket
|
||||
}
|
||||
if ( mode == 0 || mode == 3 || mode == 4 )
|
||||
{
|
||||
int len = ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a ) ? readVarInt( buf ) : buf.readShort();
|
||||
int len = ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT ) ? readVarInt( buf ) : buf.readShort();
|
||||
players = new String[ len ];
|
||||
for ( int i = 0; i < len; i++ )
|
||||
{
|
||||
@@ -78,7 +78,7 @@ public class Team extends DefinedPacket
|
||||
writeString( prefix, buf );
|
||||
writeString( suffix, buf );
|
||||
buf.writeByte( friendlyFire );
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
writeString( nameTagVisibility, buf );
|
||||
buf.writeByte( color );
|
||||
@@ -86,7 +86,7 @@ public class Team extends DefinedPacket
|
||||
}
|
||||
if ( mode == 0 || mode == 3 || mode == 4 )
|
||||
{
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_14_11_a )
|
||||
if ( protocolVersion >= ProtocolConstants.MINECRAFT_SNAPSHOT )
|
||||
{
|
||||
writeVarInt( players.length, buf );
|
||||
} else
|
||||
|
Reference in New Issue
Block a user