Skip to content

Commit

Permalink
Minecraft 25w05a protocol support
Browse files Browse the repository at this point in the history
  • Loading branch information
md-5 committed Feb 1, 2025
1 parent 9dd5fb6 commit 508c2f7
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

<properties>
<build.number>unknown</build.number>
<lombok.version>1.18.32</lombok.version>
<lombok.version>1.18.36</lombok.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
10 changes: 10 additions & 0 deletions protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.BitSet;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.BiConsumer;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -69,6 +70,15 @@ public static void writeString(String s, ByteBuf buf, int maxLength)
buf.writeBytes( b );
}

public static <T> T readStringMapKey(ByteBuf buf, Map<String, T> map)
{
String string = readString( buf );
T result = map.get( string );
Preconditions.checkArgument( result != null, "Unknown string key %s", string );

return result;
}

public static String readString(ByteBuf buf)
{
return readString( buf, Short.MAX_VALUE );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ProtocolConstants
public static final int MINECRAFT_1_21 = 767;
public static final int MINECRAFT_1_21_2 = 768;
public static final int MINECRAFT_1_21_4 = 769;
public static final int MINECRAFT_1_21_5 = 1073742055;
public static final int MINECRAFT_1_21_5 = 1073742056;
public static final List<String> SUPPORTED_VERSIONS;
public static final List<Integer> SUPPORTED_VERSION_IDS;

Expand Down
105 changes: 97 additions & 8 deletions protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.md_5.bungee.protocol.packet;

import com.google.common.collect.ImmutableMap;
import io.netty.buffer.ByteBuf;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -26,8 +28,8 @@ public class Team extends DefinedPacket
private Either<String, BaseComponent> displayName;
private Either<String, BaseComponent> prefix;
private Either<String, BaseComponent> suffix;
private String nameTagVisibility;
private String collisionRule;
private NameTagVisibility nameTagVisibility;
private CollisionRule collisionRule;
private int color;
private byte friendlyFire;
private String[] players;
Expand Down Expand Up @@ -60,10 +62,18 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco
displayName = readEitherBaseComponent( buf, protocolVersion, false );
}
friendlyFire = buf.readByte();
nameTagVisibility = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
{
collisionRule = readString( buf );
nameTagVisibility = NameTagVisibility.values()[readVarInt( buf )];
collisionRule = CollisionRule.values()[readVarInt( buf )];
} else
{
nameTagVisibility = readStringMapKey( buf, NameTagVisibility.BY_NAME );

if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
{
collisionRule = readStringMapKey( buf, CollisionRule.BY_NAME );
}
}
color = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? readVarInt( buf ) : buf.readByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
Expand Down Expand Up @@ -97,10 +107,17 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc
writeEitherBaseComponent( suffix, buf, protocolVersion );
}
buf.writeByte( friendlyFire );
writeString( nameTagVisibility, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 )
{
writeVarInt( nameTagVisibility.ordinal(), buf );
writeVarInt( collisionRule.ordinal(), buf );
} else
{
writeString( collisionRule, buf );
writeString( nameTagVisibility.getKey(), buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 )
{
writeString( collisionRule.getKey(), buf );
}
}

if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
Expand Down Expand Up @@ -128,4 +145,76 @@ public void handle(AbstractPacketHandler handler) throws Exception
{
handler.handle( this );
}

public enum NameTagVisibility
{

ALWAYS( "always" ),
NEVER( "never" ),
HIDE_FOR_OTHER_TEAMS( "hideForOtherTeams" ),
HIDE_FOR_OWN_TEAM( "hideForOwnTeam" );
//
private final String key;
//
private static final Map<String, NameTagVisibility> BY_NAME;

static
{
NameTagVisibility[] values = NameTagVisibility.values();
ImmutableMap.Builder<String, NameTagVisibility> builder = ImmutableMap.builderWithExpectedSize( values.length );

for ( NameTagVisibility e : values )
{
builder.put( e.key, e );
}

BY_NAME = builder.build();
}

private NameTagVisibility(String name)
{
this.key = name;
}

public String getKey()
{
return this.key;

This comment has been minimized.

Copy link
@NEZNAMY

NEZNAMY Feb 1, 2025

Why no lombok here? (Getter, RequiredArgsConstructor / AllArgsConstructor)

}
}

public enum CollisionRule
{

ALWAYS( "always" ),
NEVER( "never" ),
PUSH_OTHER_TEAMS( "pushOtherTeams" ),
PUSH_OWN_TEAM( "pushOwnTeam" );
//
private final String key;
//
private static final Map<String, CollisionRule> BY_NAME;

static
{
CollisionRule[] values = CollisionRule.values();
ImmutableMap.Builder<String, CollisionRule> builder = ImmutableMap.builderWithExpectedSize( values.length );

for ( CollisionRule e : values )
{
builder.put( e.key, e );
}

BY_NAME = builder.build();
}

private CollisionRule(String name)
{
this.key = name;
}

public String getKey()
{
return this.key;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ public void handle(net.md_5.bungee.protocol.packet.Team team) throws Exception
t.setPrefix( team.getPrefix().getLeftOrCompute( ComponentSerializer::toString ) );
t.setSuffix( team.getSuffix().getLeftOrCompute( ComponentSerializer::toString ) );
t.setFriendlyFire( team.getFriendlyFire() );
t.setNameTagVisibility( team.getNameTagVisibility() );
t.setCollisionRule( team.getCollisionRule() );
t.setNameTagVisibility( team.getNameTagVisibility().getKey() );
t.setCollisionRule( team.getCollisionRule().getKey() );
t.setColor( team.getColor() );
}
if ( team.getPlayers() != null )
Expand Down

0 comments on commit 508c2f7

Please sign in to comment.