Skip to content
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ teamDisplay.displayName(Component.text("Team Display Name"));
teamDisplay.prefix(Component.text("[Prefix] "));
teamDisplay.suffix(Component.text(" [Suffix]"));
teamDisplay.playerColor(NamedTextColor.RED);

// Due to internal Minecraft limitations, a player can only be assigned to one team at a time.
// To prevent client crashes, calling addEntry() will remove the player from any
// other teams they are on.
teamDisplay.addEntry(player.getName());

teamManager.addPlayer(player); // Player will be added to the default TeamDisplay of each ScoreboardTeam
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.megavex.scoreboardlibrary.implementation.packetAdapter.PropertiesPacketType;
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.EntriesPacketType;
import net.megavex.scoreboardlibrary.implementation.packetAdapter.team.TeamDisplayPacketAdapter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -58,13 +59,32 @@ public TeamDisplayImpl(@NotNull ScoreboardTeamImpl team) {

@Override
public boolean addEntry(@NotNull String entry) {
if (!entries.contains(entry)) {
entries.add(entry);
team.teamManager().taskQueue().add(new TeamManagerTask.AddEntries(this, Collections.singleton(entry)));
return true;
for (Player viewer : players) {
for (ScoreboardTeam otherTeam : team.teamManager().teams()) {
if (otherTeam == team) continue;

TeamDisplay otherDisplay = otherTeam.display(viewer);
if (otherDisplay.entries().contains(entry)) {
otherDisplay.removeEntry(entry);
}
}
}

return false;
if (players.isEmpty()) {
for (ScoreboardTeam otherTeam : team.teamManager().teams()) {
if (otherTeam == team) continue;

TeamDisplay defaultDisplay = otherTeam.defaultDisplay();
if (defaultDisplay.entries().contains(entry)) {
defaultDisplay.removeEntry(entry);
}
}
}

entries.add(entry);
team.teamManager().taskQueue().add(new TeamManagerTask.AddEntries(this, Collections.singleton(entry)));
return true;

}

@Override
Expand Down
Loading