Minecraft 1.13-pre7 support

This commit is contained in:
md_5
2018-07-15 10:00:00 +10:00
parent ceb9ea1e52
commit b1cc72e212
45 changed files with 798 additions and 137 deletions

View File

@@ -22,6 +22,8 @@ import net.md_5.bungee.protocol.packet.Handshake;
import net.md_5.bungee.protocol.packet.EncryptionResponse;
import net.md_5.bungee.protocol.packet.LegacyHandshake;
import net.md_5.bungee.protocol.packet.LegacyPing;
import net.md_5.bungee.protocol.packet.LoginPayloadRequest;
import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
import net.md_5.bungee.protocol.packet.LoginRequest;
import net.md_5.bungee.protocol.packet.LoginSuccess;
import net.md_5.bungee.protocol.packet.PingPacket;
@@ -148,4 +150,12 @@ public abstract class AbstractPacketHandler
public void handle(BossBar bossBar) throws Exception
{
}
public void handle(LoginPayloadRequest request) throws Exception
{
}
public void handle(LoginPayloadResponse response) throws Exception
{
}
}

View File

@@ -20,6 +20,8 @@ import net.md_5.bungee.protocol.packet.Handshake;
import net.md_5.bungee.protocol.packet.KeepAlive;
import net.md_5.bungee.protocol.packet.Kick;
import net.md_5.bungee.protocol.packet.Login;
import net.md_5.bungee.protocol.packet.LoginPayloadRequest;
import net.md_5.bungee.protocol.packet.LoginPayloadResponse;
import net.md_5.bungee.protocol.packet.LoginRequest;
import net.md_5.bungee.protocol.packet.LoginSuccess;
import net.md_5.bungee.protocol.packet.PingPacket;
@@ -61,90 +63,104 @@ public enum Protocol
KeepAlive.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x00 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x1F ),
map( ProtocolConstants.MINECRAFT_1_12, 0x1F )
map( ProtocolConstants.MINECRAFT_1_12, 0x1F ),
map( ProtocolConstants.MINECRAFT_1_13, 0x21 )
);
TO_CLIENT.registerPacket(
Login.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x23 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x23 )
map( ProtocolConstants.MINECRAFT_1_12, 0x23 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x25 )
);
TO_CLIENT.registerPacket(
Chat.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x02 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x0F ),
map( ProtocolConstants.MINECRAFT_1_12, 0x0F )
map( ProtocolConstants.MINECRAFT_1_12, 0x0F ),
map( ProtocolConstants.MINECRAFT_1_13, 0x0E )
);
TO_CLIENT.registerPacket(
Respawn.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x07 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x33 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x34 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x35 )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x35 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x38 )
);
TO_CLIENT.registerPacket(
BossBar.class,
map( ProtocolConstants.MINECRAFT_1_9, 0x0C ),
map( ProtocolConstants.MINECRAFT_1_12, 0x0C )
map( ProtocolConstants.MINECRAFT_1_12, 0x0C ),
map( ProtocolConstants.MINECRAFT_1_13, 0x0C )
);
TO_CLIENT.registerPacket(
PlayerListItem.class, // PlayerInfo
map( ProtocolConstants.MINECRAFT_1_8, 0x38 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x2D ),
map( ProtocolConstants.MINECRAFT_1_12, 0x2D ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x2E )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x2E ),
map( ProtocolConstants.MINECRAFT_1_13, 0x30 )
);
TO_CLIENT.registerPacket(
TabCompleteResponse.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x3A ),
map( ProtocolConstants.MINECRAFT_1_9, 0x0E ),
map( ProtocolConstants.MINECRAFT_1_12, 0x0E )
map( ProtocolConstants.MINECRAFT_1_12, 0x0E ),
map( ProtocolConstants.MINECRAFT_1_13, 0x10 )
);
TO_CLIENT.registerPacket(
ScoreboardObjective.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x3B ),
map( ProtocolConstants.MINECRAFT_1_9, 0x3F ),
map( ProtocolConstants.MINECRAFT_1_12, 0x41 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x42 )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x42 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x45 )
);
TO_CLIENT.registerPacket(
ScoreboardScore.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x3C ),
map( ProtocolConstants.MINECRAFT_1_9, 0x42 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x44 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x45 )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x45 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x48 )
);
TO_CLIENT.registerPacket(
ScoreboardDisplay.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x3D ),
map( ProtocolConstants.MINECRAFT_1_9, 0x38 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x3A ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x3B )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x3B ),
map( ProtocolConstants.MINECRAFT_1_13, 0x3E )
);
TO_CLIENT.registerPacket(
Team.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x3E ),
map( ProtocolConstants.MINECRAFT_1_9, 0x41 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x43 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x44 )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x44 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x47 )
);
TO_CLIENT.registerPacket(
PluginMessage.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x3F ),
map( ProtocolConstants.MINECRAFT_1_9, 0x18 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x18 )
map( ProtocolConstants.MINECRAFT_1_12, 0x18 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x19 )
);
TO_CLIENT.registerPacket(
Kick.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x40 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x1A ),
map( ProtocolConstants.MINECRAFT_1_12, 0x1A )
map( ProtocolConstants.MINECRAFT_1_12, 0x1A ),
map( ProtocolConstants.MINECRAFT_1_13, 0x1B )
);
TO_CLIENT.registerPacket(
Title.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x45 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x47 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x48 )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x48 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x4B )
);
TO_CLIENT.registerPacket(
PlayerListHeaderFooter.class,
@@ -152,7 +168,8 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_9, 0x48 ),
map( ProtocolConstants.MINECRAFT_1_9_4, 0x47 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x49 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x4A )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x4A ),
map( ProtocolConstants.MINECRAFT_1_13, 0x4E )
);
TO_SERVER.registerPacket(
@@ -160,35 +177,40 @@ public enum Protocol
map( ProtocolConstants.MINECRAFT_1_8, 0x00 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x0B ),
map( ProtocolConstants.MINECRAFT_1_12, 0x0C ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x0B )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x0B ),
map( ProtocolConstants.MINECRAFT_1_13, 0x0E )
);
TO_SERVER.registerPacket(
Chat.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x02 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x03 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x02 )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x02 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x02 )
);
TO_SERVER.registerPacket(
TabCompleteRequest.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x14 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x02 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x01 )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x05 )
);
TO_SERVER.registerPacket(
ClientSettings.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x15 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x04 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x05 ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x04 )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x04 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x04 )
);
TO_SERVER.registerPacket(
PluginMessage.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x17 ),
map( ProtocolConstants.MINECRAFT_1_9, 0x09 ),
map( ProtocolConstants.MINECRAFT_1_12, 0x0A ),
map( ProtocolConstants.MINECRAFT_1_12_1, 0x09 )
map( ProtocolConstants.MINECRAFT_1_12_1, 0x09 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x0A )
);
}
},
@@ -221,30 +243,44 @@ public enum Protocol
{
{
TO_CLIENT.registerPacket(
LoginPayloadRequest.class,
map( ProtocolConstants.MINECRAFT_1_13, 0x00 )
);
TO_CLIENT.registerPacket(
Kick.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
map( ProtocolConstants.MINECRAFT_1_8, 0x00 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x01 )
);
TO_CLIENT.registerPacket(
EncryptionRequest.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
map( ProtocolConstants.MINECRAFT_1_8, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x02 )
);
TO_CLIENT.registerPacket(
LoginSuccess.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x02 )
map( ProtocolConstants.MINECRAFT_1_8, 0x02 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x03 )
);
TO_CLIENT.registerPacket(
SetCompression.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x03 )
map( ProtocolConstants.MINECRAFT_1_8, 0x03 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x04 )
);
TO_SERVER.registerPacket(
LoginPayloadResponse.class,
map( ProtocolConstants.MINECRAFT_1_13, 0x00 )
);
TO_SERVER.registerPacket(
LoginRequest.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x00 )
map( ProtocolConstants.MINECRAFT_1_8, 0x00 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x01 )
);
TO_SERVER.registerPacket(
EncryptionResponse.class,
map( ProtocolConstants.MINECRAFT_1_8, 0x01 )
map( ProtocolConstants.MINECRAFT_1_8, 0x01 ),
map( ProtocolConstants.MINECRAFT_1_13, 0x02 )
);
}
};
@@ -327,7 +363,8 @@ public enum Protocol
{
linkedProtocols.put( ProtocolConstants.MINECRAFT_1_8, Arrays.asList(
ProtocolConstants.MINECRAFT_1_9,
ProtocolConstants.MINECRAFT_1_12
ProtocolConstants.MINECRAFT_1_12,
ProtocolConstants.MINECRAFT_1_13
) );
linkedProtocols.put( ProtocolConstants.MINECRAFT_1_9, Arrays.asList(
ProtocolConstants.MINECRAFT_1_9_1,

View File

@@ -17,12 +17,14 @@ public class ProtocolConstants
public static final int MINECRAFT_1_12 = 335;
public static final int MINECRAFT_1_12_1 = 338;
public static final int MINECRAFT_1_12_2 = 340;
public static final int MINECRAFT_1_13 = 389;
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
"1.8.x",
"1.9.x",
"1.10.x",
"1.11.x",
"1.12.x"
"1.12.x",
"1.13.x"
);
public static final List<Integer> SUPPORTED_VERSION_IDS = Arrays.asList( ProtocolConstants.MINECRAFT_1_8,
ProtocolConstants.MINECRAFT_1_9,
@@ -34,7 +36,8 @@ public class ProtocolConstants
ProtocolConstants.MINECRAFT_1_11_1,
ProtocolConstants.MINECRAFT_1_12,
ProtocolConstants.MINECRAFT_1_12_1,
ProtocolConstants.MINECRAFT_1_12_2
ProtocolConstants.MINECRAFT_1_12_2,
ProtocolConstants.MINECRAFT_1_13
);
public enum Direction

View File

@@ -0,0 +1,51 @@
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.OverflowPacketException;
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class LoginPayloadRequest extends DefinedPacket
{
private int id;
private String channel;
private byte[] data;
@Override
public void read(ByteBuf buf)
{
id = readVarInt( buf );
channel = readString( buf );
int len = buf.readableBytes();
if ( len > 1048576 )
{
throw new OverflowPacketException( "Payload may not be larger than 1048576 bytes" );
}
data = new byte[ len ];
buf.readBytes( data );
}
@Override
public void write(ByteBuf buf)
{
writeVarInt( id, buf );
writeString( channel, buf );
buf.writeBytes( data );
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@@ -0,0 +1,58 @@
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.OverflowPacketException;
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class LoginPayloadResponse extends DefinedPacket
{
private int id;
private byte[] data;
@Override
public void read(ByteBuf buf)
{
id = readVarInt( buf );
if ( buf.readBoolean() )
{
int len = buf.readableBytes();
if ( len > 1048576 )
{
throw new OverflowPacketException( "Payload may not be larger than 1048576 bytes" );
}
data = new byte[ len ];
buf.readBytes( data );
}
}
@Override
public void write(ByteBuf buf)
{
writeVarInt( id, buf );
if ( data != null )
{
buf.writeBoolean( true );
buf.writeBytes( data );
} else
{
buf.writeBoolean( false );
}
}
@Override
public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}
}

View File

@@ -1,5 +1,6 @@
package net.md_5.bungee.protocol.packet;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import net.md_5.bungee.protocol.DefinedPacket;
@@ -7,6 +8,7 @@ import io.netty.buffer.ByteBuf;
import java.io.ByteArrayInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.util.Locale;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -21,12 +23,37 @@ import net.md_5.bungee.protocol.ProtocolConstants;
public class PluginMessage extends DefinedPacket
{
public static final Function<String, String> MODERNISE = new Function<String, String>()
{
@Override
public String apply(String tag)
{
// Transform as per Bukkit
if ( tag.equals( "BungeeCord" ) )
{
return "bungeecord:main";
}
if ( tag.equals( "bungeecord:main" ) )
{
return "BungeeCord";
}
// Code that gets to here is UNLIKELY to be viable on the Bukkit side of side things,
// but we keep it anyway. It will eventually be enforced API side.
if ( tag.indexOf( ':' ) != -1 )
{
return tag;
}
return "bungeecord:legacy/" + tag.toLowerCase( Locale.ROOT );
}
};
public static final Predicate<PluginMessage> SHOULD_RELAY = new Predicate<PluginMessage>()
{
@Override
public boolean apply(PluginMessage input)
{
return ( input.getTag().equals( "REGISTER" ) || input.getTag().equals( "MC|Brand" ) ) && input.getData().length < Byte.MAX_VALUE;
return ( input.getTag().equals( "REGISTER" ) || input.getTag().equals( "minecraft:register" ) || input.getTag().equals( "MC|Brand" ) || input.getTag().equals( "minecraft:brand" ) ) && input.getData().length < Byte.MAX_VALUE;
}
};
//
@@ -41,7 +68,7 @@ public class PluginMessage extends DefinedPacket
@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
tag = readString( buf );
tag = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( readString( buf ) ) : readString( buf );
int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000;
Preconditions.checkArgument( buf.readableBytes() < maxSize );
data = new byte[ buf.readableBytes() ];
@@ -51,7 +78,7 @@ public class PluginMessage extends DefinedPacket
@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
writeString( tag, buf );
writeString( ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( tag ) : tag, buf );
buf.writeBytes( data );
}

View File

@@ -2,6 +2,7 @@ package net.md_5.bungee.protocol.packet;
import net.md_5.bungee.protocol.DefinedPacket;
import io.netty.buffer.ByteBuf;
import java.util.Locale;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -18,7 +19,7 @@ public class ScoreboardObjective extends DefinedPacket
private String name;
private String value;
private String type;
private HealthDisplay type;
/**
* 0 to create, 1 to remove, 2 to update display text.
*/
@@ -32,7 +33,13 @@ public class ScoreboardObjective extends DefinedPacket
if ( action == 0 || action == 2 )
{
value = readString( buf );
type = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
type = HealthDisplay.values()[readVarInt( buf )];
} else
{
type = HealthDisplay.fromString( readString( buf ) );
}
}
}
@@ -44,7 +51,13 @@ public class ScoreboardObjective extends DefinedPacket
if ( action == 0 || action == 2 )
{
writeString( value, buf );
writeString( type, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
writeVarInt( type.ordinal(), buf );
} else
{
writeString( type.toString(), buf );
}
}
}
@@ -53,4 +66,21 @@ public class ScoreboardObjective extends DefinedPacket
{
handler.handle( this );
}
public enum HealthDisplay
{
INTEGER, HEARTS;
@Override
public String toString()
{
return super.toString().toLowerCase( Locale.ROOT );
}
public static HealthDisplay fromString(String s)
{
return valueOf( s.toUpperCase( Locale.ROOT ) );
}
}
}

View File

@@ -2,7 +2,6 @@ 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;
@@ -11,44 +10,74 @@ import net.md_5.bungee.protocol.ProtocolConstants;
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class TabCompleteRequest extends DefinedPacket
{
private int transactionId;
private String cursor;
private boolean assumeCommand;
private boolean hasPositon;
private long position;
public TabCompleteRequest(int transactionId, String cursor)
{
this.transactionId = transactionId;
this.cursor = cursor;
}
public TabCompleteRequest(String cursor, boolean assumeCommand, boolean hasPosition, long position)
{
this.cursor = cursor;
this.assumeCommand = assumeCommand;
this.hasPositon = hasPosition;
this.position = position;
}
@Override
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
cursor = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
assumeCommand = buf.readBoolean();
transactionId = readVarInt( buf );
}
cursor = readString( buf );
if ( hasPositon = buf.readBoolean() )
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
{
position = buf.readLong();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
{
assumeCommand = buf.readBoolean();
}
if ( hasPositon = buf.readBoolean() )
{
position = buf.readLong();
}
}
}
@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
writeString( cursor, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
buf.writeBoolean( assumeCommand );
writeVarInt( transactionId, buf );
}
writeString( cursor, buf );
buf.writeBoolean( hasPositon );
if ( hasPositon )
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
{
buf.writeLong( position );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
{
buf.writeBoolean( assumeCommand );
}
buf.writeBoolean( hasPositon );
if ( hasPositon )
{
buf.writeLong( position );
}
}
}

View File

@@ -2,32 +2,88 @@ package net.md_5.bungee.protocol.packet;
import net.md_5.bungee.protocol.DefinedPacket;
import io.netty.buffer.ByteBuf;
import java.util.LinkedList;
import java.util.List;
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;
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class TabCompleteResponse extends DefinedPacket
{
private int transactionId;
private int start;
private int length;
private List<CommandMatch> matches;
private List<String> commands;
@Override
public void read(ByteBuf buf)
public TabCompleteResponse(int transactionId, int start, int length, List<CommandMatch> matches)
{
commands = readStringArray( buf );
this.transactionId = transactionId;
this.start = start;
this.length = length;
this.matches = matches;
}
public TabCompleteResponse(List<String> commands)
{
this.commands = commands;
}
@Override
public void write(ByteBuf buf)
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
writeStringArray( commands, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
transactionId = readVarInt( buf );
start = readVarInt( buf );
length = readVarInt( buf );
int cnt = readVarInt( buf );
matches = new LinkedList<>();
for ( int i = 0; i < cnt; i++ )
{
String match = readString( buf );
String tooltip = buf.readBoolean() ? readString( buf ) : null;
matches.add( new CommandMatch( match, tooltip ) );
}
}
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
{
commands = readStringArray( buf );
}
}
@Override
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
{
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
writeVarInt( transactionId, buf );
writeVarInt( start, buf );
writeVarInt( length, buf );
writeVarInt( matches.size(), buf );
for ( CommandMatch match : matches )
{
writeString( match.match, buf );
buf.writeBoolean( match.tooltip != null );
writeString( match.tooltip, buf );
}
}
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
{
writeStringArray( commands, buf );
}
}
@Override
@@ -35,4 +91,14 @@ public class TabCompleteResponse extends DefinedPacket
{
handler.handle( this );
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class CommandMatch
{
private String match;
private String tooltip;
}
}

View File

@@ -26,7 +26,7 @@ public class Team extends DefinedPacket
private String suffix;
private String nameTagVisibility;
private String collisionRule;
private byte color;
private int color;
private byte friendlyFire;
private String[] players;
@@ -47,15 +47,23 @@ public class Team extends DefinedPacket
if ( mode == 0 || mode == 2 )
{
displayName = readString( buf );
prefix = readString( buf );
suffix = readString( buf );
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
{
prefix = readString( buf );
suffix = readString( buf );
}
friendlyFire = buf.readByte();
nameTagVisibility = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
{
collisionRule = readString( buf );
}
color = buf.readByte();
color = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? readVarInt( buf ) : buf.readByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
prefix = readString( buf );
suffix = readString( buf );
}
}
if ( mode == 0 || mode == 3 || mode == 4 )
{
@@ -76,15 +84,27 @@ public class Team extends DefinedPacket
if ( mode == 0 || mode == 2 )
{
writeString( displayName, buf );
writeString( prefix, buf );
writeString( suffix, buf );
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
{
writeString( prefix, buf );
writeString( suffix, buf );
}
buf.writeByte( friendlyFire );
writeString( nameTagVisibility, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
{
writeString( collisionRule, buf );
}
buf.writeByte( color );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
writeVarInt( color, buf );
writeString( prefix, buf );
writeString( suffix, buf );
} else
{
buf.writeByte( color );
}
}
if ( mode == 0 || mode == 3 || mode == 4 )
{

View File

@@ -0,0 +1,17 @@
package net.md_5.bungee.protocol.packet;
import org.junit.Assert;
import org.junit.Test;
public class PluginMessageTest
{
@Test
public void testModerniseChannel()
{
Assert.assertEquals( "bungeecord:main", PluginMessage.MODERNISE.apply( "BungeeCord" ) );
Assert.assertEquals( "BungeeCord", PluginMessage.MODERNISE.apply( "bungeecord:main" ) );
Assert.assertEquals( "bungeecord:legacy/foo", PluginMessage.MODERNISE.apply( "FoO" ) );
Assert.assertEquals( "foo:bar", PluginMessage.MODERNISE.apply( "foo:bar" ) );
}
}