Skip to content

Commit

Permalink
#3780: Allow empty scoreboard nametag visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
md-5 committed Feb 8, 2025
1 parent 05bdf5d commit cceebda
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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<String, NameTagVisibility> BY_NAME;
private static final NameTagVisibility[] BY_ID;

static
{
Expand All @@ -173,6 +178,7 @@ public enum NameTagVisibility
}

BY_NAME = builder.build();
BY_ID = Arrays.copyOf( values, values.length - 1 ); // Ignore dummy UNKNOWN value
}
}

Expand All @@ -189,10 +195,11 @@ public enum CollisionRule
private final String key;
//
private static final Map<String, CollisionRule> BY_NAME;
private static final CollisionRule[] BY_ID;

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

for ( CollisionRule e : values )
Expand Down

0 comments on commit cceebda

Please sign in to comment.