mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 13:06:02 +01:00
Add ability to add a string to a scoreboard instead of a player
This commit is contained in:
parent
e9980aa94f
commit
55202e1f99
@ -110,6 +110,13 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
||||
return team == null ? null : new CraftTeam(this, team);
|
||||
}
|
||||
|
||||
public Team getEntryTeam(String entry) throws IllegalArgumentException {
|
||||
Validate.notNull(entry, "Entry cannot be null");
|
||||
|
||||
ScoreboardTeam team = board.getPlayerTeam(entry);
|
||||
return team == null ? null : new CraftTeam(this, team);
|
||||
}
|
||||
|
||||
public Team getTeam(String teamName) throws IllegalArgumentException {
|
||||
Validate.notNull(teamName, "Team name cannot be null");
|
||||
|
||||
|
@ -102,19 +102,30 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
||||
public void setNameTagVisibility(NameTagVisibility visibility) throws IllegalArgumentException {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
|
||||
team.setNameTagVisibility(bukkitToNotch(visibility));
|
||||
team.setNameTagVisibility(bukkitToNotch(visibility));
|
||||
}
|
||||
|
||||
public Set<OfflinePlayer> getPlayers() throws IllegalStateException {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
|
||||
ImmutableSet.Builder<OfflinePlayer> players = ImmutableSet.builder();
|
||||
for (Object o : team.getPlayerNameSet()) {
|
||||
players.add(Bukkit.getOfflinePlayer(o.toString()));
|
||||
for (String playerName : team.getPlayerNameSet()) {
|
||||
players.add(Bukkit.getOfflinePlayer(playerName));
|
||||
}
|
||||
return players.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getEntries() throws IllegalStateException {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
|
||||
ImmutableSet.Builder<String> entries = ImmutableSet.builder();
|
||||
for (String playerName: team.getPlayerNameSet()){
|
||||
entries.add(playerName);
|
||||
}
|
||||
return entries.build();
|
||||
}
|
||||
|
||||
public int getSize() throws IllegalStateException {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
|
||||
@ -123,28 +134,44 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
||||
|
||||
public void addPlayer(OfflinePlayer player) throws IllegalStateException, IllegalArgumentException {
|
||||
Validate.notNull(player, "OfflinePlayer cannot be null");
|
||||
addEntry(player.getName());
|
||||
}
|
||||
|
||||
public void addEntry(String entry) throws IllegalStateException, IllegalArgumentException {
|
||||
Validate.notNull(entry, "Entry cannot be null");
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
|
||||
scoreboard.board.addPlayerToTeam(player.getName(), team.getName());
|
||||
scoreboard.board.addPlayerToTeam(entry, team.getName());
|
||||
}
|
||||
|
||||
public boolean removePlayer(OfflinePlayer player) throws IllegalStateException, IllegalArgumentException {
|
||||
Validate.notNull(player, "OfflinePlayer cannot be null");
|
||||
return removeEntry(player.getName());
|
||||
}
|
||||
|
||||
public boolean removeEntry(String entry) throws IllegalStateException, IllegalArgumentException {
|
||||
Validate.notNull(entry, "Entry cannot be null");
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
|
||||
if (!team.getPlayerNameSet().contains(player.getName())) {
|
||||
if (!team.getPlayerNameSet().contains(entry)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
scoreboard.board.removePlayerFromTeam(player.getName(), team);
|
||||
scoreboard.board.removePlayerFromTeam(entry, team);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasPlayer(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException {
|
||||
Validate.notNull(player, "OfflinePlayer cannot be null");
|
||||
return hasEntry(player.getName());
|
||||
}
|
||||
|
||||
public boolean hasEntry(String entry) throws IllegalArgumentException, IllegalStateException {
|
||||
Validate.notNull("Entry cannot be null");
|
||||
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
|
||||
return team.getPlayerNameSet().contains(player.getName());
|
||||
return team.getPlayerNameSet().contains(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -212,5 +239,4 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
||||
return !(this.team != other.team && (this.team == null || !this.team.equals(other.team)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user