From cceebdad2acbd474094c09527b3248c5be04b8df Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 8 Feb 2025 17:55:18 +1100 Subject: [PATCH] #3780: Allow empty scoreboard nametag visibility --- .../net/md_5/bungee/protocol/packet/Team.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 51b136c463..7cd5202893 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 @@ -2,6 +2,7 @@ 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; @@ -66,8 +67,8 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco friendlyFire = buf.readByte(); if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_21_5 ) { - nameTagVisibility = NameTagVisibility.values()[readVarInt( buf )]; - collisionRule = CollisionRule.values()[readVarInt( buf )]; + nameTagVisibility = NameTagVisibility.BY_ID[readVarInt( buf )]; + collisionRule = CollisionRule.BY_ID[readVarInt( buf )]; } else { nameTagVisibility = readStringMapKey( buf, NameTagVisibility.BY_NAME ); @@ -156,11 +157,15 @@ public enum NameTagVisibility ALWAYS( "always" ), NEVER( "never" ), HIDE_FOR_OTHER_TEAMS( "hideForOtherTeams" ), - HIDE_FOR_OWN_TEAM( "hideForOwnTeam" ); + 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( "" ); // private final String key; // private static final Map BY_NAME; + private static final NameTagVisibility[] BY_ID; static { @@ -173,6 +178,7 @@ public enum NameTagVisibility } BY_NAME = builder.build(); + BY_ID = Arrays.copyOf( values, values.length - 1 ); // Ignore dummy UNKNOWN value } } @@ -189,10 +195,11 @@ public enum CollisionRule private final String key; // private static final Map BY_NAME; + private static final CollisionRule[] BY_ID; static { - CollisionRule[] values = CollisionRule.values(); + CollisionRule[] values = BY_ID = CollisionRule.values(); ImmutableMap.Builder builder = ImmutableMap.builderWithExpectedSize( values.length ); for ( CollisionRule e : values )