From c9aba059e2052c305bd814b4654b899ce12cec6d Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 15 Jul 2013 09:14:23 -0400 Subject: [PATCH] Don't provide direct access to the players map. --- .../java/com/gmail/nossr50/commands/KrakenCommand.java | 2 +- .../java/com/gmail/nossr50/commands/ToggleCommand.java | 2 +- .../nossr50/commands/database/McremoveCommand.java | 2 +- .../nossr50/commands/experience/ExperienceCommand.java | 2 +- .../com/gmail/nossr50/commands/party/PartyCommand.java | 4 ++-- .../nossr50/commands/party/teleport/PtpCommand.java | 2 +- .../gmail/nossr50/commands/player/InspectCommand.java | 2 +- .../gmail/nossr50/commands/player/McrankCommand.java | 2 +- .../com/gmail/nossr50/runnables/SaveTimerTask.java | 2 +- .../com/gmail/nossr50/util/player/UserManager.java | 10 ++++++++-- 10 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/KrakenCommand.java b/src/main/java/com/gmail/nossr50/commands/KrakenCommand.java index ddcd00e6a..e8c82e576 100644 --- a/src/main/java/com/gmail/nossr50/commands/KrakenCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/KrakenCommand.java @@ -57,7 +57,7 @@ public class KrakenCommand implements TabExecutor { public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { switch (args.length) { case 1: - Set playerNames = UserManager.getPlayers().keySet(); + Set playerNames = UserManager.getPlayerNames(); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); default: return ImmutableList.of(); diff --git a/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java b/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java index 70ce51884..4e1b978f3 100644 --- a/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java @@ -70,7 +70,7 @@ public abstract class ToggleCommand implements TabExecutor { public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { switch (args.length) { case 1: - Set playerNames = UserManager.getPlayers().keySet(); + Set playerNames = UserManager.getPlayerNames(); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); default: return ImmutableList.of(); diff --git a/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java b/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java index 4d3fd3cd3..a9ee2aa76 100644 --- a/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java @@ -43,7 +43,7 @@ public class McremoveCommand implements TabExecutor { public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { switch (args.length) { case 1: - Set playerNames = UserManager.getPlayers().keySet(); + Set playerNames = UserManager.getPlayerNames(); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); default: return ImmutableList.of(); diff --git a/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java index e2c462696..37b31f4be 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java @@ -97,7 +97,7 @@ public abstract class ExperienceCommand implements TabExecutor { public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { switch (args.length) { case 1: - Set playerNames = UserManager.getPlayers().keySet(); + Set playerNames = UserManager.getPlayerNames(); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); case 2: return StringUtil.copyPartialMatches(args[1], SkillType.SKILL_NAMES, new ArrayList(SkillType.SKILL_NAMES.size())); diff --git a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java index 8bc879edc..4b2505fb5 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java @@ -176,7 +176,7 @@ public class PartyCommand implements TabExecutor { case INVITE: case KICK: case OWNER: - Set playerNames = UserManager.getPlayers().keySet(); + Set playerNames = UserManager.getPlayerNames(); return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList(playerNames.size())); case EXPSHARE: return StringUtil.copyPartialMatches(args[1], EXPSHARE_COMPLETIONS, new ArrayList(EXPSHARE_COMPLETIONS.size())); @@ -191,7 +191,7 @@ public class PartyCommand implements TabExecutor { List matches = StringUtil.copyPartialMatches(args[1], PtpCommand.TELEPORT_SUBCOMMANDS, new ArrayList(PtpCommand.TELEPORT_SUBCOMMANDS.size())); if (matches.size() == 0) { - playerNames = UserManager.getPlayers().keySet(); + playerNames = UserManager.getPlayerNames(); return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList(playerNames.size())); } diff --git a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java index 73313fe20..82670388a 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/teleport/PtpCommand.java @@ -102,7 +102,7 @@ public class PtpCommand implements TabExecutor { List matches = StringUtil.copyPartialMatches(args[0], TELEPORT_SUBCOMMANDS, new ArrayList(TELEPORT_SUBCOMMANDS.size())); if (matches.size() == 0) { - Set playerNames = UserManager.getPlayers().keySet(); + Set playerNames = UserManager.getPlayerNames(); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); } diff --git a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java index 6ee00822a..7d4afd7b2 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java @@ -103,7 +103,7 @@ public class InspectCommand implements TabExecutor { public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { switch (args.length) { case 1: - Set playerNames = UserManager.getPlayers().keySet(); + Set playerNames = UserManager.getPlayerNames(); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); default: return ImmutableList.of(); diff --git a/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java b/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java index d69311509..081dc3a6a 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java @@ -82,7 +82,7 @@ public class McrankCommand implements TabExecutor { public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { switch (args.length) { case 1: - Set playerNames = UserManager.getPlayers().keySet(); + Set playerNames = UserManager.getPlayerNames(); return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); default: return ImmutableList.of(); diff --git a/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java b/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java index 10f7160aa..c13aca1e7 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java @@ -14,7 +14,7 @@ public class SaveTimerTask extends BukkitRunnable { // All player data will be saved periodically through this int count = 1; - for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers().values()) { + for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers()) { new PlayerProfileSaveTask(mcMMOPlayer.getProfile()).runTaskLater(mcMMO.p, count); count++; } diff --git a/src/main/java/com/gmail/nossr50/util/player/UserManager.java b/src/main/java/com/gmail/nossr50/util/player/UserManager.java index b547dfa9d..c6b691ecd 100644 --- a/src/main/java/com/gmail/nossr50/util/player/UserManager.java +++ b/src/main/java/com/gmail/nossr50/util/player/UserManager.java @@ -1,8 +1,10 @@ package com.gmail.nossr50.util.player; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -61,8 +63,12 @@ public final class UserManager { } } - public static Map getPlayers() { - return players; + public static Set getPlayerNames() { + return players.keySet(); + } + + public static Collection getPlayers() { + return players.values(); } /**