From 2394e204fa023333fd8deb8d96d3f2225ba98241 Mon Sep 17 00:00:00 2001 From: Janmm14 Date: Mon, 11 Mar 2024 03:22:19 +0000 Subject: [PATCH] #3629: Fix scoreboard team data reading --- .../java/net/md_5/bungee/protocol/Either.java | 23 +++++++++++++++++++ .../bungee/connection/DownstreamBridge.java | 6 ++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Either.java b/protocol/src/main/java/net/md_5/bungee/protocol/Either.java index 42d174e0..c994c134 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Either.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Either.java @@ -1,5 +1,6 @@ package net.md_5.bungee.protocol; +import java.util.function.Function; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; @@ -31,4 +32,26 @@ public final class Either { return new Either<>( null, right ); } + + public L getLeftOrCompute(Function function) + { + if ( isLeft() ) + { + return left; + } else + { + return function.apply( right ); + } + } + + public R getRightOrCompute(Function function) + { + if ( isRight() ) + { + return right; + } else + { + return function.apply( left ); + } + } } 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 27737d1b..4684bfd8 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 @@ -267,9 +267,9 @@ public class DownstreamBridge extends PacketHandler { if ( team.getMode() == 0 || team.getMode() == 2 ) { - t.setDisplayName( ComponentSerializer.toString( team.getDisplayName() ) ); - t.setPrefix( ComponentSerializer.toString( team.getPrefix() ) ); - t.setSuffix( ComponentSerializer.toString( team.getSuffix() ) ); + t.setDisplayName( team.getDisplayName().getLeftOrCompute( ComponentSerializer::toString ) ); + 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() );