Skip to content

Commit

Permalink
SpigotMC#3629: Fix scoreboard team data reading
Browse files Browse the repository at this point in the history
  • Loading branch information
Janmm14 authored and thxrben committed Jun 16, 2024
1 parent 9b5f9e0 commit ec28ec4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
23 changes: 23 additions & 0 deletions protocol/src/main/java/net/md_5/bungee/protocol/Either.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.md_5.bungee.protocol;

import java.util.function.Function;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down Expand Up @@ -31,4 +32,26 @@ public static <L, R> Either<L, R> right(R right)
{
return new Either<>( null, right );
}

public L getLeftOrCompute(Function<R, L> function)
{
if ( isLeft() )
{
return left;
} else
{
return function.apply( right );
}
}

public R getRightOrCompute(Function<L, R> function)
{
if ( isRight() )
{
return right;
} else
{
return function.apply( left );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ public void handle(net.md_5.bungee.protocol.packet.Team team) throws Exception
{
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() );
Expand Down

0 comments on commit ec28ec4

Please sign in to comment.