diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java index 7cd52028..96f10fb9 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java @@ -1,9 +1,6 @@ package net.md_5.bungee.protocol.packet; -import com.google.common.collect.ImmutableMap; import io.netty.buffer.ByteBuf; -import java.util.Arrays; -import java.util.Map; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -31,8 +28,10 @@ public class Team extends DefinedPacket private Either displayName; private Either prefix; private Either suffix; - private NameTagVisibility nameTagVisibility; - private CollisionRule collisionRule; + // + private Either nameTagVisibility; + private Either collisionRule; + // private int color; private byte friendlyFire; private String[] players; @@ -67,15 +66,14 @@ public class Team extends DefinedPacket friendlyFire = buf.readByte(); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 ) { - nameTagVisibility = NameTagVisibility.BY_ID[readVarInt( buf )]; - collisionRule = CollisionRule.BY_ID[readVarInt( buf )]; + nameTagVisibility = Either.right( NameTagVisibility.BY_ID[readVarInt( buf )] ); + collisionRule = Either.right( CollisionRule.BY_ID[readVarInt( buf )] ); } else { - nameTagVisibility = readStringMapKey( buf, NameTagVisibility.BY_NAME ); - + nameTagVisibility = Either.left( readString( buf ) ); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) { - collisionRule = readStringMapKey( buf, CollisionRule.BY_NAME ); + collisionRule = Either.left( readString( buf ) ); } } color = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? readVarInt( buf ) : buf.readByte(); @@ -112,14 +110,14 @@ public class Team extends DefinedPacket buf.writeByte( friendlyFire ); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 ) { - writeVarInt( nameTagVisibility.ordinal(), buf ); - writeVarInt( collisionRule.ordinal(), buf ); + writeVarInt( nameTagVisibility.getRight().ordinal(), buf ); + writeVarInt( collisionRule.getRight().ordinal(), buf ); } else { - writeString( nameTagVisibility.getKey(), buf ); + writeString( nameTagVisibility.getLeft(), buf ); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_9 ) { - writeString( collisionRule.getKey(), buf ); + writeString( collisionRule.getLeft(), buf ); } } @@ -157,29 +155,11 @@ public class Team extends DefinedPacket ALWAYS( "always" ), NEVER( "never" ), HIDE_FOR_OTHER_TEAMS( "hideForOtherTeams" ), - HIDE_FOR_OWN_TEAM( "hideForOwnTeam" ), - // 1.9 (and possibly other versions) appear to treat unknown values differently (always render rather than subject to spectator mode, friendly invisibles, etc). - // we allow the empty value to achieve this in case it is potentially useful even though this is unsupported and its usage may be a bug (#3780). - UNKNOWN( "" ); + HIDE_FOR_OWN_TEAM( "hideForOwnTeam" ); // private final String key; // - private static final Map BY_NAME; - private static final NameTagVisibility[] BY_ID; - - static - { - NameTagVisibility[] values = NameTagVisibility.values(); - ImmutableMap.Builder builder = ImmutableMap.builderWithExpectedSize( values.length ); - - for ( NameTagVisibility e : values ) - { - builder.put( e.key, e ); - } - - BY_NAME = builder.build(); - BY_ID = Arrays.copyOf( values, values.length - 1 ); // Ignore dummy UNKNOWN value - } + private static final NameTagVisibility[] BY_ID = values(); } @Getter @@ -194,20 +174,6 @@ public class Team extends DefinedPacket // private final String key; // - private static final Map BY_NAME; - private static final CollisionRule[] BY_ID; - - static - { - CollisionRule[] values = BY_ID = CollisionRule.values(); - ImmutableMap.Builder builder = ImmutableMap.builderWithExpectedSize( values.length ); - - for ( CollisionRule e : values ) - { - builder.put( e.key, e ); - } - - BY_NAME = builder.build(); - } + private static final CollisionRule[] BY_ID = CollisionRule.values(); } } 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 aa5b5bc6..fdb5cd46 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 @@ -284,11 +284,11 @@ public class DownstreamBridge extends PacketHandler t.setPrefix( team.getPrefix().getLeftOrCompute( (component) -> con.getChatSerializer().toString( component ) ) ); t.setSuffix( team.getSuffix().getLeftOrCompute( (component) -> con.getChatSerializer().toString( component ) ) ); t.setFriendlyFire( team.getFriendlyFire() ); - t.setNameTagVisibility( team.getNameTagVisibility().getKey() ); + t.setNameTagVisibility( team.getNameTagVisibility().isLeft() ? team.getNameTagVisibility().getLeft() : team.getNameTagVisibility().getRight().getKey() ); t.setColor( team.getColor() ); if ( team.getCollisionRule() != null ) { - t.setCollisionRule( team.getCollisionRule().getKey() ); + t.setCollisionRule( team.getCollisionRule().isLeft() ? team.getCollisionRule().getLeft() : team.getCollisionRule().getRight().getKey() ); } } if ( team.getPlayers() != null )