13
0
geforkt von Mirrors/Paper

Add ability to add a string to a scoreboard instead of a player

Dieser Commit ist enthalten in:
Matt 2015-05-12 22:42:47 -04:00 committet von md_5
Ursprung e9980aa94f
Commit 55202e1f99
2 geänderte Dateien mit 41 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -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");

Datei anzeigen

@ -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)));
}
}