diff options
author | Matt <mattbdev@outlook.com> | 2015-05-12 22:42:47 -0400 |
---|---|---|
committer | md_5 <git@md-5.net> | 2015-05-29 19:36:14 +1000 |
commit | 55202e1f991a2c3c2cb3dff6604bf85ae812ab60 (patch) | |
tree | f288379d4eaf8be07a30c5c46a4d6fea397fc8d9 /src/main/java/org | |
parent | e9980aa94fe4791ba8ec88560282a0bec5cf9cd5 (diff) | |
download | craftbukkit-55202e1f991a2c3c2cb3dff6604bf85ae812ab60.tar craftbukkit-55202e1f991a2c3c2cb3dff6604bf85ae812ab60.tar.gz craftbukkit-55202e1f991a2c3c2cb3dff6604bf85ae812ab60.tar.lz craftbukkit-55202e1f991a2c3c2cb3dff6604bf85ae812ab60.tar.xz craftbukkit-55202e1f991a2c3c2cb3dff6604bf85ae812ab60.zip |
Add ability to add a string to a scoreboard instead of a player
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java | 7 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java | 42 |
2 files changed, 41 insertions, 8 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java index 97671474..00b30f8c 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java @@ -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"); diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java index ce42b307..f5ff0f71 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java @@ -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))); } - } |