From b930d28588d46dfc068860ef4c980375e47739aa Mon Sep 17 00:00:00 2001 From: Travis Watkins Date: Sat, 12 Apr 2014 11:13:14 -0500 Subject: Add methods to use arbitrary entries in scoreboards. Adds BUKKIT-3977 --- .../bukkit/command/defaults/ScoreboardCommand.java | 22 +++++++------- src/main/java/org/bukkit/scoreboard/Objective.java | 15 +++++++++- src/main/java/org/bukkit/scoreboard/Score.java | 12 +++++++- .../java/org/bukkit/scoreboard/Scoreboard.java | 35 +++++++++++++++++++++- 4 files changed, 70 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/bukkit/command/defaults/ScoreboardCommand.java b/src/main/java/org/bukkit/command/defaults/ScoreboardCommand.java index a805f7c2..f0490cfa 100644 --- a/src/main/java/org/bukkit/command/defaults/ScoreboardCommand.java +++ b/src/main/java/org/bukkit/command/defaults/ScoreboardCommand.java @@ -209,7 +209,7 @@ public class ScoreboardCommand extends VanillaCommand { sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name"); return false; } - Score score = objective.getScore(Bukkit.getOfflinePlayer(playerName)); + Score score = objective.getScore(playerName); int newScore; if (args[1].equalsIgnoreCase("set")) { newScore = value; @@ -230,7 +230,7 @@ public class ScoreboardCommand extends VanillaCommand { sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name"); return false; } - mainScoreboard.resetScores(Bukkit.getOfflinePlayer(playerName)); + mainScoreboard.resetScores(playerName); sender.sendMessage("Reset all scores of player " + playerName); } else if (args[1].equalsIgnoreCase("list")) { if (args.length > 3) { @@ -238,12 +238,12 @@ public class ScoreboardCommand extends VanillaCommand { return false; } if (args.length == 2) { - Set players = mainScoreboard.getPlayers(); - if (players.isEmpty()) { + Set entries = mainScoreboard.getEntries(); + if (entries.isEmpty()) { sender.sendMessage(ChatColor.RED + "There are no tracked players on the scoreboard"); } else { - sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + players.size() + " tracked players on the scoreboard"); - sender.sendMessage(offlinePlayerSetToString(players)); + sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + entries.size() + " tracked players on the scoreboard"); + sender.sendMessage(stringCollectionToString(entries)); } } else { String playerName = args[2]; @@ -251,7 +251,7 @@ public class ScoreboardCommand extends VanillaCommand { sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name"); return false; } - Set scores = mainScoreboard.getScores(Bukkit.getOfflinePlayer(playerName)); + Set scores = mainScoreboard.getScores(playerName); if (scores.isEmpty()) { sender.sendMessage(ChatColor.RED + "Player " + playerName + " has no scores recorded"); } else { @@ -520,7 +520,7 @@ public class ScoreboardCommand extends VanillaCommand { } } else { if (args.length == 3) { - return StringUtil.copyPartialMatches(args[2], this.getCurrentPlayers(), new ArrayList()); + return StringUtil.copyPartialMatches(args[2], this.getCurrentEntries(), new ArrayList()); } } } else if (args[0].equalsIgnoreCase("teams")) { @@ -597,10 +597,10 @@ public class ScoreboardCommand extends VanillaCommand { return list; } - private List getCurrentPlayers() { + private List getCurrentEntries() { List list = new ArrayList(); - for (OfflinePlayer player : Bukkit.getScoreboardManager().getMainScoreboard().getPlayers()) { - list.add(player.getName()); + for (String entry : Bukkit.getScoreboardManager().getMainScoreboard().getEntries()) { + list.add(entry); } Collections.sort(list, String.CASE_INSENSITIVE_ORDER); return list; diff --git a/src/main/java/org/bukkit/scoreboard/Objective.java b/src/main/java/org/bukkit/scoreboard/Objective.java index fd307ebc..321aac79 100644 --- a/src/main/java/org/bukkit/scoreboard/Objective.java +++ b/src/main/java/org/bukkit/scoreboard/Objective.java @@ -3,7 +3,7 @@ package org.bukkit.scoreboard; import org.bukkit.OfflinePlayer; /** - * An objective on a scoreboard that can show scores specific to players. This + * An objective on a scoreboard that can show scores specific to entries. This * objective is only relevant to the display of the associated {@link * #getScoreboard() scoreboard}. */ @@ -92,6 +92,19 @@ public interface Objective { * @return Score tracking the Objective and player specified * @throws IllegalArgumentException if player is null * @throws IllegalStateException if this objective has been unregistered + * @deprecated Scoreboards can contain entries that aren't players + * @see #getScore(String) */ + @Deprecated Score getScore(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException; + + /** + * Gets an entry's Score for an Objective on this Scoreboard. + * + * @param entry Entry for the Score + * @return Score tracking the Objective and entry specified + * @throws IllegalArgumentException if entry is null + * @throws IllegalStateException if this objective has been unregistered + */ + Score getScore(String entry) throws IllegalArgumentException, IllegalStateException; } diff --git a/src/main/java/org/bukkit/scoreboard/Score.java b/src/main/java/org/bukkit/scoreboard/Score.java index c8c34edb..4c103468 100644 --- a/src/main/java/org/bukkit/scoreboard/Score.java +++ b/src/main/java/org/bukkit/scoreboard/Score.java @@ -3,7 +3,7 @@ package org.bukkit.scoreboard; import org.bukkit.OfflinePlayer; /** - * A score entry for a {@link #getPlayer() player} on an {@link + * A score entry for an {@link #getEntry() entry} on an {@link * #getObjective() objective}. Changing this will not affect any other * objective or scoreboard. */ @@ -13,9 +13,19 @@ public interface Score { * Gets the OfflinePlayer being tracked by this Score * * @return this Score's tracked player + * @deprecated Scoreboards can contain entries that aren't players + * @see #getEntry() */ + @Deprecated OfflinePlayer getPlayer(); + /** + * Gets the entry being tracked by this Score + * + * @return this Score's tracked entry + */ + String getEntry(); + /** * Gets the Objective being tracked by this Score * diff --git a/src/main/java/org/bukkit/scoreboard/Scoreboard.java b/src/main/java/org/bukkit/scoreboard/Scoreboard.java index e9b0abdc..d244a7f4 100644 --- a/src/main/java/org/bukkit/scoreboard/Scoreboard.java +++ b/src/main/java/org/bukkit/scoreboard/Scoreboard.java @@ -63,17 +63,40 @@ public interface Scoreboard { * @param player the player whose scores are being retrieved * @return immutable set of all scores tracked for the player * @throws IllegalArgumentException if player is null + * @deprecated Scoreboards can contain entries that aren't players + * @see #getScores(String) */ + @Deprecated Set getScores(OfflinePlayer player) throws IllegalArgumentException; + /** + * Gets all scores for an entry on this Scoreboard + * + * @param entry the entry whose scores are being retrieved + * @return immutable set of all scores tracked for the entry + * @throws IllegalArgumentException if entry is null + */ + Set getScores(String entry) throws IllegalArgumentException; + /** * Removes all scores for a player on this Scoreboard * - * @param player the player to drop all current scores + * @param player the player to drop all current scores for * @throws IllegalArgumentException if player is null + * @deprecated Scoreboards can contain entries that aren't players + * @see #resetScores(String) */ + @Deprecated void resetScores(OfflinePlayer player) throws IllegalArgumentException; + /** + * Removes all scores for an entry on this Scoreboard + * + * @param entry the entry to drop all current scores for + * @throws IllegalArgumentException if entry is null + */ + void resetScores(String entry) throws IllegalArgumentException; + /** * Gets a player's Team on this Scoreboard * @@ -113,9 +136,19 @@ public interface Scoreboard { * Gets all players tracked by this Scoreboard * * @return immutable set of all tracked players + * @deprecated Scoreboards can contain entries that aren't players + * @see #getEntries() */ + @Deprecated Set getPlayers(); + /** + * Gets all entries tracked by this Scoreboard + * + * @return immutable set of all tracked entries + */ + Set getEntries(); + /** * Clears any objective in the specified slot. * -- cgit v1.2.3