diff options
Diffstat (limited to 'src/main/java/org')
3 files changed, 43 insertions, 7 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java index 431807a8..9eaec710 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java @@ -93,6 +93,13 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective return new CraftScore(this, player.getName()); } + public Score getScore(String entry) throws IllegalArgumentException, IllegalStateException { + Validate.notNull(entry, "Entry cannot be null"); + CraftScoreboard scoreboard = checkState(); + + return new CraftScore(this, entry); + } + @Override public void unregister() throws IllegalStateException { CraftScoreboard scoreboard = checkState(); diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScore.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScore.java index 0ffbe9b0..7095f6d8 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScore.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScore.java @@ -17,16 +17,20 @@ import org.bukkit.scoreboard.Score; * Also, as an added perk, a CraftScore will (intentionally) stay a valid reference so long as objective is valid. */ final class CraftScore implements Score { - private final String playerName; + private final String entry; private final CraftObjective objective; - CraftScore(CraftObjective objective, String playerName) { + CraftScore(CraftObjective objective, String entry) { this.objective = objective; - this.playerName = playerName; + this.entry = entry; } public OfflinePlayer getPlayer() { - return Bukkit.getOfflinePlayer(playerName); + return Bukkit.getOfflinePlayer(entry); + } + + public String getEntry() { + return entry; } public Objective getObjective() { @@ -36,18 +40,19 @@ final class CraftScore implements Score { public int getScore() throws IllegalStateException { Scoreboard board = objective.checkState().board; - if (board.getPlayers().contains(playerName)) { // Lazy - Map<String, ScoreboardScore> scores = board.getPlayerObjectives(playerName); + if (board.getPlayers().contains(entry)) { // Lazy + Map<String, ScoreboardScore> scores = board.getPlayerObjectives(entry); ScoreboardScore score = scores.get(objective.getHandle()); if (score != null) { // Lazy return score.getScore(); } } + return 0; // Lazy } public void setScore(int score) throws IllegalStateException { - objective.checkState().board.getPlayerScoreForObjective(playerName, objective.getHandle()).setScore(score); + objective.checkState().board.getPlayerScoreForObjective(entry, objective.getHandle()).setScore(score); } public CraftScoreboard getScoreboard() { diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java index 72b02b07..ad65b3f8 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java @@ -84,12 +84,28 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { return scores.build(); } + public ImmutableSet<Score> getScores(String entry) throws IllegalArgumentException { + Validate.notNull(entry, "Entry cannot be null"); + + ImmutableSet.Builder<Score> scores = ImmutableSet.builder(); + for (CraftObjective objective : objectives.values()) { + scores.add(objective.getScore(entry)); + } + return scores.build(); + } + public void resetScores(OfflinePlayer player) throws IllegalArgumentException { Validate.notNull(player, "OfflinePlayer cannot be null"); board.resetPlayerScores(player.getName()); } + public void resetScores(String entry) throws IllegalArgumentException { + Validate.notNull(entry, "Entry cannot be null"); + + board.resetPlayerScores(entry); + } + public Team getPlayerTeam(OfflinePlayer player) throws IllegalArgumentException { Validate.notNull(player, "OfflinePlayer cannot be null"); @@ -123,6 +139,14 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { return players.build(); } + public ImmutableSet<String> getEntries() { + ImmutableSet.Builder<String> entries = ImmutableSet.builder(); + for (Object entry : board.getPlayers()) { + entries.add(entry.toString()); + } + return entries.build(); + } + public void clearSlot(DisplaySlot slot) throws IllegalArgumentException { Validate.notNull(slot, "Slot cannot be null"); board.setDisplaySlot(CraftScoreboardTranslations.fromBukkitSlot(slot), null); |