Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix team data reading #3629

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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