From 197bf13a287a20910ddb24310c0675f1a7abade9 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 25 Nov 2023 17:02:40 +1100 Subject: [PATCH] Minecraft 1.20.3-pre2 support --- .../protocol/AbstractPacketHandler.java | 5 ++ .../md_5/bungee/protocol/DefinedPacket.java | 51 ++++++++++++++++ .../md_5/bungee/protocol/NumberFormat.java | 18 ++++++ .../net/md_5/bungee/protocol/Protocol.java | 45 ++++++++++---- .../bungee/protocol/ProtocolConstants.java | 2 +- .../md_5/bungee/protocol/packet/Commands.java | 60 ++++++++++++++++++- .../protocol/packet/ScoreboardObjective.java | 10 ++++ .../protocol/packet/ScoreboardScore.java | 28 ++++++++- .../protocol/packet/ScoreboardScoreReset.java | 41 +++++++++++++ .../java/net/md_5/bungee/ServerConnector.java | 11 +++- .../bungee/connection/DownstreamBridge.java | 13 ++++ .../net/md_5/bungee/netty/HandlerBoss.java | 5 +- 12 files changed, 266 insertions(+), 23 deletions(-) create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/NumberFormat.java create mode 100644 protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScoreReset.java diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java index 0f8f5885..4383dbb5 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java @@ -34,6 +34,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.ScoreboardScoreReset; import net.md_5.bungee.protocol.packet.ServerData; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.StartConfiguration; @@ -143,6 +144,10 @@ public abstract class AbstractPacketHandler { } + public void handle(ScoreboardScoreReset scoreboardScoreReset) throws Exception + { + } + public void handle(EncryptionRequest encryptionRequest) throws Exception { } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java index d7d5d849..94613a0a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -1,5 +1,6 @@ package net.md_5.bungee.protocol; +import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.gson.JsonElement; import io.netty.buffer.ByteBuf; @@ -15,6 +16,7 @@ import java.util.BitSet; import java.util.EnumSet; import java.util.List; import java.util.UUID; +import java.util.function.BiConsumer; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; @@ -27,6 +29,23 @@ import se.llbit.nbt.Tag; public abstract class DefinedPacket { + public T readNullable(Function reader, ByteBuf buf) + { + return buf.readBoolean() ? reader.apply( buf ) : null; + } + + public void writeNullable(T t0, BiConsumer writer, ByteBuf buf) + { + if ( t0 != null ) + { + buf.writeBoolean( true ); + writer.accept( t0, buf ); + } else + { + buf.writeBoolean( false ); + } + } + public static void writeString(String s, ByteBuf buf) { writeString( s, buf, Short.MAX_VALUE ); @@ -351,6 +370,38 @@ public abstract class DefinedPacket return null; } + public static void writeNumberFormat(NumberFormat format, ByteBuf buf, int protocolVersion) + { + writeVarInt( format.getType().ordinal(), buf ); + switch ( format.getType() ) + { + case BLANK: + break; + case STYLED: + writeBaseComponent( (BaseComponent) format.getValue(), buf, protocolVersion ); // TODO: style + break; + case FIXED: + writeBaseComponent( (BaseComponent) format.getValue(), buf, protocolVersion ); + break; + } + } + + public static NumberFormat readNumberFormat(ByteBuf buf, int protocolVersion) + { + int format = readVarInt( buf ); + switch ( format ) + { + case 0: + return new NumberFormat( NumberFormat.Type.BLANK, null ); + case 1: + return new NumberFormat( NumberFormat.Type.STYLED, readBaseComponent( buf, protocolVersion ) ); // TODO: style + case 2: + return new NumberFormat( NumberFormat.Type.FIXED, readBaseComponent( buf, protocolVersion ) ); + default: + throw new IllegalArgumentException( "Unknown number format " + format ); + } + } + public static Tag readTag(ByteBuf input, int protocolVersion) { DataInputStream in = new DataInputStream( new ByteBufInputStream( input ) ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/NumberFormat.java b/protocol/src/main/java/net/md_5/bungee/protocol/NumberFormat.java new file mode 100644 index 00000000..d1cefe3b --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/NumberFormat.java @@ -0,0 +1,18 @@ +package net.md_5.bungee.protocol; + +import lombok.Data; + +@Data +public class NumberFormat +{ + + private final Type type; + private final Object value; + + public enum Type + { + BLANK, + STYLED, + FIXED; + } +} 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 2eeca50b..cc08447c 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 @@ -40,6 +40,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.ScoreboardScoreReset; import net.md_5.bungee.protocol.packet.ServerData; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.StartConfiguration; @@ -134,7 +135,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x3E ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x3D ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x41 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x43 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x43 ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x45 ) ); TO_CLIENT.registerPacket( BossBar.class, @@ -192,7 +194,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x56 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x54 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x58 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x5A ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x5A ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x5C ) ); TO_CLIENT.registerPacket( ScoreboardScore.class, @@ -208,7 +211,13 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x59 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x57 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x5B ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x5D ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x5D ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x5F ) + ); + TO_CLIENT.registerPacket( + ScoreboardScoreReset.class, + ScoreboardScoreReset::new, + map( ProtocolConstants.MINECRAFT_1_20_3, 0x42 ) ); TO_CLIENT.registerPacket( ScoreboardDisplay.class, @@ -224,7 +233,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x4F ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x4D ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x51 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x53 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x53 ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x55 ) ); TO_CLIENT.registerPacket( Team.class, @@ -240,7 +250,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x58 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x56 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x5A ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x5C ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x5C ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x5E ) ); TO_CLIENT.registerPacket( PluginMessage.class, @@ -291,7 +302,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x5D ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x5B ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x5F ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x61 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x61 ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x63 ) ); TO_CLIENT.registerPacket( ClearTitles.class, @@ -310,7 +322,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x5B ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x59 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x5D ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x5F ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x5F ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x61 ) ); TO_CLIENT.registerPacket( TitleTimes.class, @@ -320,7 +333,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x5E ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x5C ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x60 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x62 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x62 ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x64 ) ); TO_CLIENT.registerPacket( SystemChat.class, @@ -329,7 +343,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x62 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x60 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x64 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x67 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x67 ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x69 ) ); TO_CLIENT.registerPacket( PlayerListHeaderFooter.class, @@ -349,7 +364,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x63 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x61 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x65 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x68 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x68 ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x6A ) ); TO_CLIENT.registerPacket( EntityStatus.class, @@ -405,7 +421,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x4C ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x4B ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x4F ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x51 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x51 ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x53 ) ); TO_CLIENT.registerPacket( ServerData.class, @@ -414,7 +431,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_19_1, 0x42 ), map( ProtocolConstants.MINECRAFT_1_19_3, 0x41 ), map( ProtocolConstants.MINECRAFT_1_19_4, 0x45 ), - map( ProtocolConstants.MINECRAFT_1_20_2, 0x47 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x47 ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x49 ) ); TO_CLIENT.registerPacket( PlayerListItemRemove.class, @@ -433,7 +451,8 @@ public enum Protocol TO_CLIENT.registerPacket( StartConfiguration.class, StartConfiguration::new, - map( ProtocolConstants.MINECRAFT_1_20_2, 0x65 ) + map( ProtocolConstants.MINECRAFT_1_20_2, 0x65 ), + map( ProtocolConstants.MINECRAFT_1_20_3, 0x67 ) ); TO_SERVER.registerPacket( 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 ab2e9193..97da6190 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 @@ -44,7 +44,7 @@ public class ProtocolConstants public static final int MINECRAFT_1_19_4 = 762; public static final int MINECRAFT_1_20 = 763; public static final int MINECRAFT_1_20_2 = 764; - public static final int MINECRAFT_1_20_3 = 1073741986; + public static final int MINECRAFT_1_20_3 = 1073741989; public static final List SUPPORTED_VERSIONS; public static final List SUPPORTED_VERSION_IDS; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Commands.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Commands.java index 05761bf5..069bb52b 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Commands.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Commands.java @@ -310,6 +310,7 @@ public class Commands extends DefinedPacket private static final ArgumentSerializer[] IDS_1_19; private static final ArgumentSerializer[] IDS_1_19_3; private static final ArgumentSerializer[] IDS_1_19_4; + private static final ArgumentSerializer[] IDS_1_20_3; private static final Map, ProperArgumentSerializer> PROPER_PROVIDERS = new HashMap<>(); // private static final ArgumentSerializer VOID = new ArgumentSerializer() @@ -744,6 +745,60 @@ public class Commands extends DefinedPacket get( "minecraft:uuid", VOID ), get( "minecraft:heightmap", VOID ) }; + + IDS_1_20_3 = new ArgumentSerializer[] + { + get( "brigadier:bool", VOID ), + get( "brigadier:float", FLOAT_RANGE ), + get( "brigadier:double", DOUBLE_RANGE ), + get( "brigadier:integer", INTEGER_RANGE ), + get( "brigadier:long", LONG_RANGE ), + get( "brigadier:string", STRING ), + get( "minecraft:entity", BYTE ), + get( "minecraft:game_profile", VOID ), + get( "minecraft:block_pos", VOID ), + get( "minecraft:column_pos", VOID ), + get( "minecraft:vec3", VOID ), + get( "minecraft:vec2", VOID ), + get( "minecraft:block_state", VOID ), + get( "minecraft:block_predicate", VOID ), + get( "minecraft:item_stack", VOID ), + get( "minecraft:item_predicate", VOID ), + get( "minecraft:color", VOID ), + get( "minecraft:component", VOID ), + get( "minecraft:style", VOID ), + get( "minecraft:message", VOID ), + get( "minecraft:nbt_compound_tag", VOID ), + get( "minecraft:nbt_tag", VOID ), + get( "minecraft:nbt_path", VOID ), + get( "minecraft:objective", VOID ), + get( "minecraft:objective_criteria", VOID ), + get( "minecraft:operation", VOID ), + get( "minecraft:particle", VOID ), + get( "minecraft:angle", VOID ), + get( "minecraft:rotation", VOID ), + get( "minecraft:scoreboard_slot", VOID ), + get( "minecraft:score_holder", BYTE ), + get( "minecraft:swizzle", VOID ), + get( "minecraft:team", VOID ), + get( "minecraft:item_slot", VOID ), + get( "minecraft:resource_location", VOID ), + get( "minecraft:function", VOID ), + get( "minecraft:entity_anchor", VOID ), + get( "minecraft:int_range", VOID ), + get( "minecraft:float_range", VOID ), + get( "minecraft:dimension", VOID ), + get( "minecraft:gamemode", VOID ), + get( "minecraft:time", INTEGER ), + get( "minecraft:resource_or_tag", RAW_STRING ), + get( "minecraft:resource_or_tag_key", RAW_STRING ), + get( "minecraft:resource", RAW_STRING ), + get( "minecraft:resource_key", RAW_STRING ), + get( "minecraft:template_mirror", VOID ), + get( "minecraft:template_rotation", VOID ), + get( "minecraft:uuid", VOID ), + get( "minecraft:heightmap", VOID ) + }; } private static void register(String name, ArgumentSerializer serializer) @@ -765,7 +820,10 @@ public class Commands extends DefinedPacket { key = readVarInt( buf ); - if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_4 ) + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 ) + { + reader = IDS_1_20_3[(Integer) key]; + } else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_4 ) { reader = IDS_1_19_4[(Integer) key]; } else if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_19_3 ) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java index 5ed8216c..a37617fd 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java @@ -10,6 +10,7 @@ import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.protocol.AbstractPacketHandler; import net.md_5.bungee.protocol.DefinedPacket; import net.md_5.bungee.protocol.Either; +import net.md_5.bungee.protocol.NumberFormat; import net.md_5.bungee.protocol.ProtocolConstants; @Data @@ -26,6 +27,7 @@ public class ScoreboardObjective extends DefinedPacket * 0 to create, 1 to remove, 2 to update display text. */ private byte action; + private NumberFormat numberFormat; @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) @@ -43,6 +45,10 @@ public class ScoreboardObjective extends DefinedPacket value = readEitherBaseComponent( buf, protocolVersion, true ); type = HealthDisplay.fromString( readString( buf ) ); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 ) + { + numberFormat = readNullable( (b) -> readNumberFormat( b, protocolVersion ), buf ); + } } } @@ -61,6 +67,10 @@ public class ScoreboardObjective extends DefinedPacket { writeString( type.toString(), buf ); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 ) + { + writeNullable( numberFormat, (s, b) -> DefinedPacket.writeNumberFormat( s, b, protocolVersion ), buf ); + } } } diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java index 0b27fc86..d718d902 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScore.java @@ -5,8 +5,10 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.protocol.AbstractPacketHandler; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.NumberFormat; import net.md_5.bungee.protocol.ProtocolConstants; @Data @@ -23,29 +25,51 @@ public class ScoreboardScore extends DefinedPacket private byte action; private String scoreName; private int value; + private BaseComponent displayName; + private NumberFormat numberFormat; @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { itemName = readString( buf ); - action = buf.readByte(); + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 ) + { + action = 0; + } else + { + action = buf.readByte(); + } scoreName = readString( buf ); if ( action != 1 ) { value = readVarInt( buf ); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 ) + { + displayName = readNullable( (b) -> readBaseComponent( b, protocolVersion ), buf ); + numberFormat = readNullable( (b) -> readNumberFormat( b, protocolVersion ), buf ); + } } @Override public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { writeString( itemName, buf ); + if ( protocolVersion < ProtocolConstants.MINECRAFT_1_20_3 ) + { + buf.writeByte( action ); + } buf.writeByte( action ); writeString( scoreName, buf ); - if ( action != 1 ) + if ( action != 1 || protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 ) { writeVarInt( value, buf ); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_20_3 ) + { + writeNullable( displayName, (s, b) -> DefinedPacket.writeBaseComponent( s, b, protocolVersion ), buf ); + writeNullable( numberFormat, (s, b) -> DefinedPacket.writeNumberFormat( s, b, protocolVersion ), buf ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScoreReset.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScoreReset.java new file mode 100644 index 00000000..4ba7f9a7 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardScoreReset.java @@ -0,0 +1,41 @@ +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 ScoreboardScoreReset extends DefinedPacket +{ + + private String itemName; + private String scoreName; + + @Override + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + itemName = readString( buf ); + scoreName = readNullable( DefinedPacket::readString, buf ); + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + writeString( itemName, buf ); + writeNullable( scoreName, DefinedPacket::writeString, buf ); + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 6d660bab..dc6a5a8f 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -53,6 +53,7 @@ import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.Respawn; import net.md_5.bungee.protocol.packet.ScoreboardObjective; import net.md_5.bungee.protocol.packet.ScoreboardScore; +import net.md_5.bungee.protocol.packet.ScoreboardScoreReset; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.StartConfiguration; import net.md_5.bungee.protocol.packet.ViewDistance; @@ -284,12 +285,18 @@ public class ServerConnector extends PacketHandler objective.getName(), ( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ) ? Either.right( ComponentSerializer.deserialize( objective.getValue() ) ) : Either.left( objective.getValue() ), ScoreboardObjective.HealthDisplay.fromString( objective.getType() ), - (byte) 1 ) + (byte) 1, null ) ); } for ( Score score : serverScoreboard.getScores() ) { - user.unsafe().sendPacket( new ScoreboardScore( score.getItemName(), (byte) 1, score.getScoreName(), score.getValue() ) ); + if ( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_20_3 ) + { + user.unsafe().sendPacket( new ScoreboardScoreReset( score.getItemName(), null ) ); + } else + { + user.unsafe().sendPacket( new ScoreboardScore( score.getItemName(), (byte) 1, score.getScoreName(), score.getValue(), null, null ) ); + } } for ( Team team : serverScoreboard.getTeams() ) { diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 172cc8e5..27737d1b 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -67,6 +67,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.ScoreboardScoreReset; import net.md_5.bungee.protocol.packet.ServerData; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.TabCompleteResponse; @@ -220,6 +221,18 @@ public class DownstreamBridge extends PacketHandler } } + @Override + public void handle(ScoreboardScoreReset scoreboardScoreReset) throws Exception + { + Scoreboard serverScoreboard = con.getServerSentScoreboard(); + + // TODO: Expand score API to handle objective values. Shouldn't matter currently as only used for removing score entries. + if ( scoreboardScoreReset.getScoreName() == null ) + { + serverScoreboard.removeScore( scoreboardScoreReset.getItemName() ); + } + } + @Override public void handle(ScoreboardDisplay displayScoreboard) throws Exception { diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java index 9d28d813..206f4227 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java @@ -172,10 +172,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter } ); } else { - ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} - could not decode packet! {1}", new Object[] - { - handler, cause - } ); + ProxyServer.getInstance().getLogger().log( Level.WARNING, handler + " - could not decode packet!", cause ); } } else if ( cause instanceof IOException || ( cause instanceof IllegalStateException && handler instanceof InitialHandler ) ) {