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 422cba541..8d91211b4 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 @@ -10,6 +10,7 @@ import net.md_5.bungee.protocol.packet.ClientStatus; import net.md_5.bungee.protocol.packet.Commands; import net.md_5.bungee.protocol.packet.CookieRequest; import net.md_5.bungee.protocol.packet.CookieResponse; +import net.md_5.bungee.protocol.packet.DisconnectReportDetails; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.EntityStatus; @@ -38,6 +39,7 @@ 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.ServerLinks; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.StartConfiguration; import net.md_5.bungee.protocol.packet.StatusRequest; @@ -268,4 +270,12 @@ public abstract class AbstractPacketHandler public void handle(CookieResponse cookieResponse) throws Exception { } + + public void handle(DisconnectReportDetails disconnectReportDetails) throws Exception + { + } + + public void handle(ServerLinks serverLinks) throws Exception + { + } } 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 2271a2e51..317fb2d45 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 @@ -18,6 +18,7 @@ import net.md_5.bungee.protocol.packet.ClientSettings; import net.md_5.bungee.protocol.packet.Commands; import net.md_5.bungee.protocol.packet.CookieRequest; import net.md_5.bungee.protocol.packet.CookieResponse; +import net.md_5.bungee.protocol.packet.DisconnectReportDetails; import net.md_5.bungee.protocol.packet.EncryptionRequest; import net.md_5.bungee.protocol.packet.EncryptionResponse; import net.md_5.bungee.protocol.packet.EntityStatus; @@ -44,6 +45,7 @@ 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.ServerLinks; import net.md_5.bungee.protocol.packet.SetCompression; import net.md_5.bungee.protocol.packet.StartConfiguration; import net.md_5.bungee.protocol.packet.StatusRequest; @@ -496,6 +498,16 @@ public enum Protocol Transfer::new, map( ProtocolConstants.MINECRAFT_1_20_5, 0x73 ) ); + TO_CLIENT.registerPacket( + DisconnectReportDetails.class, + DisconnectReportDetails::new, + map( ProtocolConstants.MINECRAFT_1_21, 0x7A ) + ); + TO_CLIENT.registerPacket( + ServerLinks.class, + ServerLinks::new, + map( ProtocolConstants.MINECRAFT_1_21, 0x7B ) + ); TO_SERVER.registerPacket( KeepAlive.class, @@ -742,6 +754,16 @@ public enum Protocol Transfer::new, map( ProtocolConstants.MINECRAFT_1_20_5, 0x0B ) ); + TO_CLIENT.registerPacket( + DisconnectReportDetails.class, + DisconnectReportDetails::new, + map( ProtocolConstants.MINECRAFT_1_21, 0x0F ) + ); + TO_CLIENT.registerPacket( + ServerLinks.class, + ServerLinks::new, + map( ProtocolConstants.MINECRAFT_1_21, 0x10 ) + ); TO_SERVER.registerPacket( ClientSettings.class, 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 40045b770..2b1487e05 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 @@ -46,6 +46,7 @@ public class ProtocolConstants public static final int MINECRAFT_1_20_2 = 764; public static final int MINECRAFT_1_20_3 = 765; public static final int MINECRAFT_1_20_5 = 766; + public static final int MINECRAFT_1_21 = 1073742022; public static final List SUPPORTED_VERSIONS; public static final List SUPPORTED_VERSION_IDS; @@ -110,8 +111,8 @@ public class ProtocolConstants if ( SNAPSHOT_SUPPORT ) { - // supportedVersions.add( "1.20.x" ); - // supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_20_5 ); + supportedVersions.add( "1.21.x" ); + supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_21 ); } SUPPORTED_VERSIONS = supportedVersions.build(); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/DisconnectReportDetails.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/DisconnectReportDetails.java new file mode 100644 index 000000000..a84144610 --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/DisconnectReportDetails.java @@ -0,0 +1,55 @@ +package net.md_5.bungee.protocol.packet; + +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; +import java.util.HashMap; +import java.util.Map; +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 DisconnectReportDetails extends DefinedPacket +{ + + private Map details; + + @Override + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + int len = readVarInt( buf ); + Preconditions.checkArgument( len <= 32, "Too many details" ); + + details = new HashMap<>(); + for ( int i = 0; i < len; i++ ) + { + details.put( readString( buf, 128 ), readString( buf, 4096 ) ); + } + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + Preconditions.checkArgument( details.size() <= 32, "Too many details" ); + writeVarInt( details.size(), buf ); + + for ( Map.Entry detail : details.entrySet() ) + { + writeString( detail.getKey(), buf, 128 ); + writeString( detail.getValue(), buf, 4096 ); + } + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } +} diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ServerLinks.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ServerLinks.java new file mode 100644 index 000000000..24225a81b --- /dev/null +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ServerLinks.java @@ -0,0 +1,82 @@ +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.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.ProtocolConstants; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class ServerLinks extends DefinedPacket +{ + + private Link[] links; + + @Override + public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + int len = readVarInt( buf ); + links = new Link[ len ]; + for ( int i = 0; i < len; i++ ) + { + Either type; + if ( buf.readBoolean() ) + { + type = Either.left( LinkType.values()[readVarInt( buf )] ); + } else + { + type = Either.right( readBaseComponent( buf, protocolVersion ) ); + } + String url = readString( buf ); + + links[i] = new Link( type, url ); + } + } + + @Override + public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) + { + writeVarInt( links.length, buf ); + for ( Link link : links ) + { + Either type = link.getType(); + if ( type.isLeft() ) + { + buf.writeBoolean( true ); + writeVarInt( type.getLeft().ordinal(), buf ); + } else + { + buf.writeBoolean( false ); + writeBaseComponent( type.getRight(), buf, protocolVersion ); + } + writeString( link.getUrl(), buf ); + } + } + + @Override + public void handle(AbstractPacketHandler handler) throws Exception + { + handler.handle( this ); + } + + public enum LinkType + { + REPORT_BUG; + } + + @Data + public static class Link + { + + private final Either type; + private final String url; + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java index 2bf92a03a..70b58fab2 100644 --- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java @@ -87,6 +87,7 @@ public abstract class EntityMap case ProtocolConstants.MINECRAFT_1_20_3: return EntityMap_1_16_2.INSTANCE_1_20_3; case ProtocolConstants.MINECRAFT_1_20_5: + case ProtocolConstants.MINECRAFT_1_21: return EntityMap_1_16_2.INSTANCE_1_20_5; } throw new RuntimeException( "Version " + version + " has no entity map" );