From 55202e1f991a2c3c2cb3dff6604bf85ae812ab60 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 12 May 2015 22:42:47 -0400 Subject: [PATCH] Add ability to add a string to a scoreboard instead of a player --- .../scoreboard/CraftScoreboard.java | 7 ++++ .../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 9767147480..00b30f8c80 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 ce42b30758..f5ff0f712e 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 getPlayers() throws IllegalStateException { CraftScoreboard scoreboard = checkState(); ImmutableSet.Builder 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 getEntries() throws IllegalStateException { + CraftScoreboard scoreboard = checkState(); + + ImmutableSet.Builder 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))); } - }