Add methods to use arbitrary entries in scoreboards. Adds BUKKIT-3977

By: Travis Watkins <amaranth@ubuntu.com>
This commit is contained in:
Bukkit/Spigot 2014-04-12 11:13:14 -05:00
parent 07c1670354
commit 0ebd864e63
4 changed files with 70 additions and 14 deletions

View file

@ -209,7 +209,7 @@ public class ScoreboardCommand extends VanillaCommand {
sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name"); sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
return false; return false;
} }
Score score = objective.getScore(Bukkit.getOfflinePlayer(playerName)); Score score = objective.getScore(playerName);
int newScore; int newScore;
if (args[1].equalsIgnoreCase("set")) { if (args[1].equalsIgnoreCase("set")) {
newScore = value; newScore = value;
@ -230,7 +230,7 @@ public class ScoreboardCommand extends VanillaCommand {
sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name"); sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
return false; return false;
} }
mainScoreboard.resetScores(Bukkit.getOfflinePlayer(playerName)); mainScoreboard.resetScores(playerName);
sender.sendMessage("Reset all scores of player " + playerName); sender.sendMessage("Reset all scores of player " + playerName);
} else if (args[1].equalsIgnoreCase("list")) { } else if (args[1].equalsIgnoreCase("list")) {
if (args.length > 3) { if (args.length > 3) {
@ -238,12 +238,12 @@ public class ScoreboardCommand extends VanillaCommand {
return false; return false;
} }
if (args.length == 2) { if (args.length == 2) {
Set<OfflinePlayer> players = mainScoreboard.getPlayers(); Set<String> entries = mainScoreboard.getEntries();
if (players.isEmpty()) { if (entries.isEmpty()) {
sender.sendMessage(ChatColor.RED + "There are no tracked players on the scoreboard"); sender.sendMessage(ChatColor.RED + "There are no tracked players on the scoreboard");
} else { } else {
sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + players.size() + " tracked players on the scoreboard"); sender.sendMessage(ChatColor.DARK_GREEN + "Showing " + entries.size() + " tracked players on the scoreboard");
sender.sendMessage(offlinePlayerSetToString(players)); sender.sendMessage(stringCollectionToString(entries));
} }
} else { } else {
String playerName = args[2]; 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"); sender.sendMessage(ChatColor.RED + "'" + playerName + "' is too long for a player name");
return false; return false;
} }
Set<Score> scores = mainScoreboard.getScores(Bukkit.getOfflinePlayer(playerName)); Set<Score> scores = mainScoreboard.getScores(playerName);
if (scores.isEmpty()) { if (scores.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Player " + playerName + " has no scores recorded"); sender.sendMessage(ChatColor.RED + "Player " + playerName + " has no scores recorded");
} else { } else {
@ -520,7 +520,7 @@ public class ScoreboardCommand extends VanillaCommand {
} }
} else { } else {
if (args.length == 3) { 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")) { } else if (args[0].equalsIgnoreCase("teams")) {
@ -597,10 +597,10 @@ public class ScoreboardCommand extends VanillaCommand {
return list; return list;
} }
private List<String> getCurrentPlayers() { private List<String> getCurrentEntries() {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for (OfflinePlayer player : Bukkit.getScoreboardManager().getMainScoreboard().getPlayers()) { for (String entry : Bukkit.getScoreboardManager().getMainScoreboard().getEntries()) {
list.add(player.getName()); list.add(entry);
} }
Collections.sort(list, String.CASE_INSENSITIVE_ORDER); Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
return list; return list;

View file

@ -3,7 +3,7 @@ package org.bukkit.scoreboard;
import org.bukkit.OfflinePlayer; 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 * objective is only relevant to the display of the associated {@link
* #getScoreboard() scoreboard}. * #getScoreboard() scoreboard}.
*/ */
@ -92,6 +92,19 @@ public interface Objective {
* @return Score tracking the Objective and player specified * @return Score tracking the Objective and player specified
* @throws IllegalArgumentException if player is null * @throws IllegalArgumentException if player is null
* @throws IllegalStateException if this objective has been unregistered * @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; 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;
} }

View file

@ -3,7 +3,7 @@ package org.bukkit.scoreboard;
import org.bukkit.OfflinePlayer; 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 * #getObjective() objective}. Changing this will not affect any other
* objective or scoreboard. * objective or scoreboard.
*/ */
@ -13,9 +13,19 @@ public interface Score {
* Gets the OfflinePlayer being tracked by this Score * Gets the OfflinePlayer being tracked by this Score
* *
* @return this Score's tracked player * @return this Score's tracked player
* @deprecated Scoreboards can contain entries that aren't players
* @see #getEntry()
*/ */
@Deprecated
OfflinePlayer getPlayer(); 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 * Gets the Objective being tracked by this Score
* *

View file

@ -63,17 +63,40 @@ public interface Scoreboard {
* @param player the player whose scores are being retrieved * @param player the player whose scores are being retrieved
* @return immutable set of all scores tracked for the player * @return immutable set of all scores tracked for the player
* @throws IllegalArgumentException if player is null * @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; 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 * 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 * @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; 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 * Gets a player's Team on this Scoreboard
* *
@ -113,9 +136,19 @@ public interface Scoreboard {
* Gets all players tracked by this Scoreboard * Gets all players tracked by this Scoreboard
* *
* @return immutable set of all tracked players * @return immutable set of all tracked players
* @deprecated Scoreboards can contain entries that aren't players
* @see #getEntries()
*/ */
@Deprecated
Set<OfflinePlayer> getPlayers(); 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. * Clears any objective in the specified slot.
* *