summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorTravis Watkins <amaranth@ubuntu.com>2014-04-12 11:13:14 -0500
committerTravis Watkins <amaranth@ubuntu.com>2014-04-13 23:09:40 -0500
commitb930d28588d46dfc068860ef4c980375e47739aa (patch)
tree478c72bbae936056908ac30928a250245b429b2f /src/main
parent126cab926ac23825a2817012da61b8eadaca2380 (diff)
downloadbukkit-b930d28588d46dfc068860ef4c980375e47739aa.tar
bukkit-b930d28588d46dfc068860ef4c980375e47739aa.tar.gz
bukkit-b930d28588d46dfc068860ef4c980375e47739aa.tar.lz
bukkit-b930d28588d46dfc068860ef4c980375e47739aa.tar.xz
bukkit-b930d28588d46dfc068860ef4c980375e47739aa.zip
Add methods to use arbitrary entries in scoreboards. Adds BUKKIT-3977
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/bukkit/command/defaults/ScoreboardCommand.java22
-rw-r--r--src/main/java/org/bukkit/scoreboard/Objective.java15
-rw-r--r--src/main/java/org/bukkit/scoreboard/Score.java12
-rw-r--r--src/main/java/org/bukkit/scoreboard/Scoreboard.java35
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<OfflinePlayer> players = mainScoreboard.getPlayers();
- if (players.isEmpty()) {
+ Set<String> 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<Score> scores = mainScoreboard.getScores(Bukkit.getOfflinePlayer(playerName));
+ Set<Score> 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<String>());
+ return StringUtil.copyPartialMatches(args[2], this.getCurrentEntries(), new ArrayList<String>());
}
}
} else if (args[0].equalsIgnoreCase("teams")) {
@@ -597,10 +597,10 @@ public class ScoreboardCommand extends VanillaCommand {
return list;
}
- private List<String> getCurrentPlayers() {
+ private List<String> getCurrentEntries() {
List<String> list = new ArrayList<String>();
- 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,10 +13,20 @@ 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
*
* @return this Score's tracked objective
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,18 +63,41 @@ 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<Score> 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<Score> 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
*
* @param player the player to search for
@@ -113,10 +136,20 @@ 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<OfflinePlayer> getPlayers();
/**
+ * Gets all entries tracked by this Scoreboard
+ *
+ * @return immutable set of all tracked entries
+ */
+ Set<String> getEntries();
+
+ /**
* Clears any objective in the specified slot.
*
* @param slot the slot to remove objectives