diff --git a/src/main/java/com/gmail/nossr50/commands/McabilityCommand.java b/src/main/java/com/gmail/nossr50/commands/McabilityCommand.java index 67e3ffbc7..35d86956e 100644 --- a/src/main/java/com/gmail/nossr50/commands/McabilityCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McabilityCommand.java @@ -1,74 +1,29 @@ package com.gmail.nossr50.commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.commands.CommandUtils; -import com.gmail.nossr50.util.player.UserManager; -public class McabilityCommand implements CommandExecutor { - private McMMOPlayer mcMMOPlayer; - private Player player; +public class McabilityCommand extends ToggleCommand { + @Override + protected boolean hasOtherPermission(CommandSender sender) { + return Permissions.mcabilityOthers(sender); + } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - switch (args.length) { - case 0: - if (CommandUtils.noConsoleUsage(sender)) { - return true; - } - - if (!Permissions.mcability(sender)) { - sender.sendMessage(command.getPermissionMessage()); - return true; - } - - mcMMOPlayer = UserManager.getPlayer(sender.getName()); - player = mcMMOPlayer.getPlayer(); - - toggleAbilityUse(); - return true; - - case 1: - if (!Permissions.mcabilityOthers(sender)) { - sender.sendMessage(command.getPermissionMessage()); - return true; - } - - mcMMOPlayer = UserManager.getPlayer(args[0]); - - if (!CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) { - return true; - } - - player = mcMMOPlayer.getPlayer(); - - if (CommandUtils.isOffline(sender, player)) { - return true; - } - - toggleAbilityUse(); - sender.sendMessage("Ability use has been toggled for " + player.getName()); // TODO: Localize - return true; - - default: - return false; - } + protected boolean hasSelfPermission(CommandSender sender) { + return Permissions.mcability(sender); } - private void toggleAbilityUse() { - if (mcMMOPlayer.getAbilityUse()) { - player.sendMessage(LocaleLoader.getString("Commands.Ability.Off")); - } - else { - player.sendMessage(LocaleLoader.getString("Commands.Ability.On")); - } - + @Override + protected void applyCommandAction() { + player.sendMessage(LocaleLoader.getString("Commands.Ability." + (mcMMOPlayer.getAbilityUse() ? "Off" : "On"))); mcMMOPlayer.toggleAbilityUse(); } + + @Override + protected void sendSuccessMessage(CommandSender sender) { + sender.sendMessage("Ability use has been toggled for " + player.getName()); // TODO: Localize + } } diff --git a/src/main/java/com/gmail/nossr50/commands/McgodCommand.java b/src/main/java/com/gmail/nossr50/commands/McgodCommand.java index 976340d67..246f00c7d 100644 --- a/src/main/java/com/gmail/nossr50/commands/McgodCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McgodCommand.java @@ -1,74 +1,29 @@ package com.gmail.nossr50.commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.commands.CommandUtils; -import com.gmail.nossr50.util.player.UserManager; -public class McgodCommand implements CommandExecutor { - private McMMOPlayer mcMMOPlayer; - private Player player; +public class McgodCommand extends ToggleCommand { + @Override + protected boolean hasOtherPermission(CommandSender sender) { + return Permissions.mcgodOthers(sender); + } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - switch (args.length) { - case 0: - if (CommandUtils.noConsoleUsage(sender)) { - return true; - } - - if (!Permissions.mcgod(sender)) { - sender.sendMessage(command.getPermissionMessage()); - return true; - } - - mcMMOPlayer = UserManager.getPlayer(sender.getName()); - player = mcMMOPlayer.getPlayer(); - - toggleGodMode(); - return true; - - case 1: - if (!Permissions.mcgodOthers(sender)) { - sender.sendMessage(command.getPermissionMessage()); - return true; - } - - mcMMOPlayer = UserManager.getPlayer(args[0]); - - if (!CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) { - return true; - } - - player = mcMMOPlayer.getPlayer(); - - if (CommandUtils.isOffline(sender, player)) { - return true; - } - - toggleGodMode(); - sender.sendMessage("God mode has been toggled for " + player.getName()); // TODO: Localize - return true; - - default: - return false; - } + protected boolean hasSelfPermission(CommandSender sender) { + return Permissions.mcgod(sender); } - private void toggleGodMode() { - if (mcMMOPlayer.getGodMode()) { - player.sendMessage(LocaleLoader.getString("Commands.GodMode.Disabled")); - } - else { - player.sendMessage(LocaleLoader.getString("Commands.GodMode.Enabled")); - } - + @Override + protected void applyCommandAction() { + player.sendMessage(LocaleLoader.getString("Commands.GodMode." + (mcMMOPlayer.getGodMode() ? "Disabled" : "Enabled"))); mcMMOPlayer.toggleGodMode(); } + + @Override + protected void sendSuccessMessage(CommandSender sender) { + sender.sendMessage("God mode has been toggled for " + player.getName()); // TODO: Localize + } } diff --git a/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java b/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java index 51fe1447b..e930e63b7 100644 --- a/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McnotifyCommand.java @@ -1,27 +1,25 @@ package com.gmail.nossr50.commands; +import java.util.List; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.player.UserManager; -public class McnotifyCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class McnotifyCommand implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { switch (args.length) { case 0: McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName()); - if (mcMMOPlayer.useChatNotifications()) { - sender.sendMessage(LocaleLoader.getString("Commands.Notifications.Off")); - } - else { - sender.sendMessage(LocaleLoader.getString("Commands.Notifications.On")); - } - + sender.sendMessage(LocaleLoader.getString("Commands.Notifications." + (mcMMOPlayer.useChatNotifications() ? "Off" : "On"))); mcMMOPlayer.toggleChatNotifications(); return true; @@ -29,4 +27,9 @@ public class McnotifyCommand implements CommandExecutor { return false; } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return ImmutableList.of(); + } } diff --git a/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java b/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java index 7811b7c42..f743c5f9b 100644 --- a/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java @@ -1,74 +1,34 @@ package com.gmail.nossr50.commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.commands.CommandUtils; -import com.gmail.nossr50.util.player.UserManager; - -public class McrefreshCommand implements CommandExecutor { - private McMMOPlayer mcMMOPlayer; - private Player player; +public class McrefreshCommand extends ToggleCommand { @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - switch (args.length) { - case 0: - if (CommandUtils.noConsoleUsage(sender)) { - return true; - } - - if (!Permissions.mcrefresh(sender)) { - sender.sendMessage(command.getPermissionMessage()); - return true; - } - - mcMMOPlayer = UserManager.getPlayer(sender.getName()); - player = mcMMOPlayer.getPlayer(); - - refreshPlayer(); - return true; - - case 1: - if (!Permissions.mcrefreshOthers(sender)) { - sender.sendMessage(command.getPermissionMessage()); - return true; - } - - mcMMOPlayer = UserManager.getPlayer(args[0]); - - if (!CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) { - return true; - } - - Player player = mcMMOPlayer.getPlayer(); - - if (CommandUtils.isOffline(sender, player)) { - return true; - } - - refreshPlayer(); - sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", player.getName())); - return true; - - default: - return false; - } + protected boolean hasOtherPermission(CommandSender sender) { + return Permissions.mcrefreshOthers(sender); } - private void refreshPlayer() { + @Override + protected boolean hasSelfPermission(CommandSender sender) { + return Permissions.mcrefresh(sender); + } + + @Override + protected void applyCommandAction() { mcMMOPlayer.setRecentlyHurt(0); mcMMOPlayer.getProfile().resetCooldowns(); mcMMOPlayer.resetToolPrepMode(); mcMMOPlayer.resetAbilityMode(); player.setCanPickupItems(true); - player = mcMMOPlayer.getPlayer(); player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh")); } + + @Override + protected void sendSuccessMessage(CommandSender sender) { + sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", player.getName())); + } } diff --git a/src/main/java/com/gmail/nossr50/commands/MobhealthCommand.java b/src/main/java/com/gmail/nossr50/commands/MobhealthCommand.java index d6313d3ad..08eb6daa2 100644 --- a/src/main/java/com/gmail/nossr50/commands/MobhealthCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/MobhealthCommand.java @@ -1,15 +1,34 @@ package com.gmail.nossr50.commands; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.datatypes.MobHealthbarType; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; -public class MobhealthCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class MobhealthCommand implements TabExecutor { + private static final List MOB_HEALTHBAR_TYPES; + + static { + ArrayList types = new ArrayList(); + + for (MobHealthbarType type : MobHealthbarType.values()) { + types.add(type.toString()); + } + + Collections.sort(types); + MOB_HEALTHBAR_TYPES = ImmutableList.copyOf(types); + } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { @@ -36,4 +55,14 @@ public class MobhealthCommand implements CommandExecutor { return false; } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + return StringUtil.copyPartialMatches(args[0], MOB_HEALTHBAR_TYPES, new ArrayList(MOB_HEALTHBAR_TYPES.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 new file mode 100644 index 000000000..885807638 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java @@ -0,0 +1,84 @@ +package com.gmail.nossr50.commands; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; + +import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.util.commands.CommandUtils; +import com.gmail.nossr50.util.player.UserManager; + +import com.google.common.collect.ImmutableList; + +public abstract class ToggleCommand implements TabExecutor { + protected McMMOPlayer mcMMOPlayer; + protected Player player; + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + switch (args.length) { + case 0: + if (CommandUtils.noConsoleUsage(sender)) { + return true; + } + + if (!hasSelfPermission(sender)) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + mcMMOPlayer = UserManager.getPlayer(sender.getName()); + player = mcMMOPlayer.getPlayer(); + + applyCommandAction(); + return true; + + case 1: + if (!hasOtherPermission(sender)) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } + + mcMMOPlayer = UserManager.getPlayer(args[0]); + + if (!CommandUtils.checkPlayerExistence(sender, args[0], mcMMOPlayer)) { + return true; + } + + player = mcMMOPlayer.getPlayer(); + + if (CommandUtils.isOffline(sender, player)) { + return true; + } + + applyCommandAction(); + sendSuccessMessage(sender); + return true; + + default: + return false; + } + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + Set playerNames = UserManager.getPlayers().keySet(); + return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); + default: + return ImmutableList.of(); + } + } + + protected abstract boolean hasOtherPermission(CommandSender sender); + protected abstract boolean hasSelfPermission(CommandSender sender); + protected abstract void applyCommandAction(); + protected abstract void sendSuccessMessage(CommandSender sender); +} diff --git a/src/main/java/com/gmail/nossr50/commands/XprateCommand.java b/src/main/java/com/gmail/nossr50/commands/XprateCommand.java index 5b9214244..84193834d 100644 --- a/src/main/java/com/gmail/nossr50/commands/XprateCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/XprateCommand.java @@ -1,16 +1,23 @@ package com.gmail.nossr50.commands; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.commands.CommandUtils; -public class XprateCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class XprateCommand implements TabExecutor { private double originalRate; public XprateCommand() { @@ -75,4 +82,20 @@ public class XprateCommand implements CommandExecutor { return false; } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + if (StringUtils.isInt(args[0])) { + return ImmutableList.of(); + } + + return StringUtil.copyPartialMatches(args[0], CommandUtils.RESET_OPTIONS, new ArrayList(CommandUtils.RESET_OPTIONS.size())); + case 2: + return StringUtil.copyPartialMatches(args[1], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList(CommandUtils.TRUE_FALSE_OPTIONS.size())); + default: + return ImmutableList.of(); + } + } } diff --git a/src/main/java/com/gmail/nossr50/commands/chat/ChatCommand.java b/src/main/java/com/gmail/nossr50/commands/chat/ChatCommand.java index d6291b0bd..09641aa4c 100644 --- a/src/main/java/com/gmail/nossr50/commands/chat/ChatCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/chat/ChatCommand.java @@ -1,8 +1,12 @@ package com.gmail.nossr50.commands.chat; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.chat.ChatMode; import com.gmail.nossr50.datatypes.player.McMMOPlayer; @@ -10,7 +14,9 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; -public abstract class ChatCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public abstract class ChatCommand implements TabExecutor { protected ChatMode chatMode; private McMMOPlayer mcMMOPlayer; @@ -68,6 +74,16 @@ public abstract class ChatCommand implements CommandExecutor { } } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + return StringUtil.copyPartialMatches(args[0], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList(CommandUtils.TRUE_FALSE_OPTIONS.size())); + default: + return ImmutableList.of(); + } + } + protected String buildChatMessage(String[] args, int index) { StringBuilder builder = new StringBuilder(); builder.append(args[index]); diff --git a/src/main/java/com/gmail/nossr50/commands/database/McpurgeCommand.java b/src/main/java/com/gmail/nossr50/commands/database/McpurgeCommand.java index 09005c306..3f9fe2029 100644 --- a/src/main/java/com/gmail/nossr50/commands/database/McpurgeCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/database/McpurgeCommand.java @@ -1,8 +1,10 @@ package com.gmail.nossr50.commands.database; +import java.util.List; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.DatabaseManager; @@ -10,7 +12,9 @@ import com.gmail.nossr50.database.LeaderboardManager; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; -public class McpurgeCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class McpurgeCommand implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!Permissions.mcpurge(sender)) { @@ -42,4 +46,9 @@ public class McpurgeCommand implements CommandExecutor { return false; } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + 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 0c5cbf64a..941beb4f7 100644 --- a/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/database/McremoveCommand.java @@ -1,17 +1,27 @@ package com.gmail.nossr50.commands.database; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.LeaderboardManager; +import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.commands.CommandUtils; +import com.gmail.nossr50.util.player.UserManager; -public class McremoveCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class McremoveCommand implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!Permissions.mcremove(sender)) { @@ -21,6 +31,10 @@ public class McremoveCommand implements CommandExecutor { switch (args.length) { case 1: + if (UserManager.getPlayer(args[0]) == null && CommandUtils.unloadedProfile(sender, new PlayerProfile(args[0], false))) { + return true; + } + /* MySQL */ if (Config.getInstance().getUseMySQL()) { String tablePrefix = Config.getInstance().getMySQLTablePrefix(); @@ -29,18 +43,12 @@ public class McremoveCommand implements CommandExecutor { Misc.profileCleanup(args[0]); sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0])); } - else { - sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); - } } else { if (LeaderboardManager.removeFlatFileUser(args[0])) { Misc.profileCleanup(args[0]); sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", args[0])); } - else { - sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); - } } return true; @@ -49,4 +57,15 @@ public class McremoveCommand implements CommandExecutor { return false; } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + Set playerNames = UserManager.getPlayers().keySet(); + 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/MmoupdateCommand.java b/src/main/java/com/gmail/nossr50/commands/database/MmoupdateCommand.java index 743b4b6b6..03bc6665e 100644 --- a/src/main/java/com/gmail/nossr50/commands/database/MmoupdateCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/database/MmoupdateCommand.java @@ -1,8 +1,10 @@ package com.gmail.nossr50.commands.database; +import java.util.List; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; @@ -12,7 +14,9 @@ import com.gmail.nossr50.runnables.database.SQLConversionTask; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.UserManager; -public class MmoupdateCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class MmoupdateCommand implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!Permissions.mmoupdate(sender)) { @@ -20,12 +24,17 @@ public class MmoupdateCommand implements CommandExecutor { return true; } + if (!Config.getInstance().getUseMySQL()) { + sender.sendMessage("SQL Mode is not enabled."); // TODO: Localize + return true; + } + switch (args.length) { case 0: sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start")); UserManager.saveAll(); UserManager.clearAll(); - convertToMySQL(); + new SQLConversionTask().runTaskLaterAsynchronously(mcMMO.p, 1); for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { UserManager.addUser(player); @@ -39,14 +48,8 @@ public class MmoupdateCommand implements CommandExecutor { } } - /** - * Convert FlatFile data to MySQL data. - */ - private void convertToMySQL() { - if (!Config.getInstance().getUseMySQL()) { - return; - } - - new SQLConversionTask().runTaskLaterAsynchronously(mcMMO.p, 1); + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return ImmutableList.of(); } } diff --git a/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java index cf21761a7..bab887488 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java @@ -31,6 +31,5 @@ public class AddlevelsCommand extends ExperienceCommand { @Override protected void handlePlayerMessageSkill() { player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value, SkillUtils.getSkillName(skill))); - } } 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 b0d686c9e..acd0b06de 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/ExperienceCommand.java @@ -1,9 +1,14 @@ package com.gmail.nossr50.commands.experience; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; @@ -13,8 +18,9 @@ import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils; +import com.google.common.collect.ImmutableList; -public abstract class ExperienceCommand implements CommandExecutor { +public abstract class ExperienceCommand implements TabExecutor { protected McMMOPlayer mcMMOPlayer; protected Player player; protected PlayerProfile profile; @@ -84,6 +90,19 @@ public abstract class ExperienceCommand implements CommandExecutor { } } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + Set playerNames = UserManager.getPlayers().keySet(); + 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())); + default: + return ImmutableList.of(); + } + } + protected abstract boolean permissionsCheckSelf(CommandSender sender); protected abstract boolean permissionsCheckOthers(CommandSender sender); protected abstract void handleCommand(SkillType skill); diff --git a/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java b/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java index f0e7c024c..f564ca6c8 100644 --- a/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/hardcore/HardcoreModeCommand.java @@ -1,15 +1,21 @@ package com.gmail.nossr50.commands.hardcore; import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.commands.CommandUtils; -public abstract class HardcoreModeCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public abstract class HardcoreModeCommand implements TabExecutor { protected CommandSender sender; protected double newPercent; protected DecimalFormat percent; @@ -76,6 +82,20 @@ public abstract class HardcoreModeCommand implements CommandExecutor { } } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + if (StringUtils.isDouble(args[0])) { + return ImmutableList.of(); + } + + return StringUtil.copyPartialMatches(args[0], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList(CommandUtils.TRUE_FALSE_OPTIONS.size())); + default: + return ImmutableList.of(); + } + } + protected abstract boolean checkTogglePermissions(); protected abstract boolean checkModifyPermissions(); protected abstract boolean checkEnabled(); 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 93732cf0a..5693693fc 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyCommand.java @@ -1,22 +1,46 @@ package com.gmail.nossr50.commands.party; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.commands.chat.PartyChatCommand; +import com.gmail.nossr50.commands.party.teleport.PtpCommand; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; +import com.google.common.collect.ImmutableList; -public class PartyCommand implements CommandExecutor { +public class PartyCommand implements TabExecutor { private McMMOPlayer mcMMOPlayer; private Player player; + private static final List PARTY_SUBCOMMANDS; + private static final List EXPSHARE_COMPLETIONS = ImmutableList.of("none", "equal"); + private static final List ITEMSHARE_COMPLETIONS = ImmutableList.of("none", "equal", "random", "loot", "mining", "herbalism", "woodcutting"); + + static { + ArrayList subcommands = new ArrayList(); + + for (PartySubcommandType subcommand : PartySubcommandType.values()) { + subcommands.add(subcommand.toString()); + } + + Collections.sort(subcommands); + PARTY_SUBCOMMANDS = ImmutableList.copyOf(subcommands); + } + private CommandExecutor partyJoinCommand = new PartyJoinCommand(); private CommandExecutor partyAcceptCommand = new PartyAcceptCommand(); private CommandExecutor partyCreateCommand = new PartyCreateCommand(); @@ -135,6 +159,57 @@ public class PartyCommand implements CommandExecutor { return true; } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + return StringUtil.copyPartialMatches(args[0], PARTY_SUBCOMMANDS, new ArrayList(PARTY_SUBCOMMANDS.size())); + case 2: + PartySubcommandType subcommand = PartySubcommandType.getSubcommand(args[0]); + + if (subcommand == null) { + return ImmutableList.of(); + } + + switch (PartySubcommandType.valueOf(args[0].toUpperCase())) { + case JOIN: + case INVITE: + case KICK: + case OWNER: + Set playerNames = UserManager.getPlayers().keySet(); + return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList(playerNames.size())); + case EXPSHARE: + return StringUtil.copyPartialMatches(args[1], EXPSHARE_COMPLETIONS, new ArrayList(EXPSHARE_COMPLETIONS.size())); + case ITEMSHARE: + return StringUtil.copyPartialMatches(args[1], ITEMSHARE_COMPLETIONS, new ArrayList(ITEMSHARE_COMPLETIONS.size())); + case LOCK: + case CHAT: + return StringUtil.copyPartialMatches(args[1], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList(CommandUtils.TRUE_FALSE_OPTIONS.size())); + case PASSWORD: + return StringUtil.copyPartialMatches(args[1], CommandUtils.RESET_OPTIONS, new ArrayList(CommandUtils.RESET_OPTIONS.size())); + case TELEPORT: + List matches = StringUtil.copyPartialMatches(args[1], PtpCommand.TELEPORT_SUBCOMMANDS, new ArrayList(PtpCommand.TELEPORT_SUBCOMMANDS.size())); + + if (matches.size() == 0) { + playerNames = UserManager.getPlayers().keySet(); + return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList(playerNames.size())); + } + + return matches; + default: + return ImmutableList.of(); + } + case 3: + if (PartySubcommandType.getSubcommand(args[0]) == PartySubcommandType.ITEMSHARE && isItemShareCategory(args[1])) { + return StringUtil.copyPartialMatches(args[2], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList(CommandUtils.TRUE_FALSE_OPTIONS.size())); + } + + return ImmutableList.of(); + default: + return ImmutableList.of(); + } + } + private boolean printUsage() { player.sendMessage(LocaleLoader.getString("Party.Help.0", "/party join")); player.sendMessage(LocaleLoader.getString("Party.Help.1", "/party create")); @@ -151,4 +226,9 @@ public class PartyCommand implements CommandExecutor { return newArgs; } + + private boolean isItemShareCategory(String category) { + return category.equalsIgnoreCase("loot") || category.equalsIgnoreCase("mining") || category.equalsIgnoreCase("herbalism") || category.equalsIgnoreCase("woodcutting"); + } } + diff --git a/src/main/java/com/gmail/nossr50/commands/party/PartyExpShareCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PartyExpShareCommand.java index 8641bc8e3..bfaf26e7c 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyExpShareCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyExpShareCommand.java @@ -35,7 +35,7 @@ public class PartyExpShareCommand implements CommandExecutor { handleChangingShareMode(ShareMode.EQUAL); } else { - sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "[NONE | EQUAL]")); + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "expshare", "")); } return true; diff --git a/src/main/java/com/gmail/nossr50/commands/party/PartyInfoCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PartyInfoCommand.java index ab1e30028..70dce3e96 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PartyInfoCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PartyInfoCommand.java @@ -21,14 +21,21 @@ public class PartyInfoCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName()); - player = mcMMOPlayer.getPlayer(); - playerParty = mcMMOPlayer.getParty(); + switch (args.length) { + case 0: + case 1: + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName()); + player = mcMMOPlayer.getPlayer(); + playerParty = mcMMOPlayer.getParty(); - displayPartyHeader(); - displayShareModeInfo(); - displayMemberInfo(); - return true; + displayPartyHeader(); + displayShareModeInfo(); + displayMemberInfo(); + return true; + default: + sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "info")); + return true; + } } private String createMembersList() { 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 69cf7596b..bb43311ab 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 @@ -1,9 +1,15 @@ package com.gmail.nossr50.commands.party.teleport; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; @@ -15,11 +21,14 @@ import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; +import com.google.common.collect.ImmutableList; -public class PtpCommand implements CommandExecutor { +public class PtpCommand implements TabExecutor { private static Player target; private static McMMOPlayer mcMMOTarget; + public static final List TELEPORT_SUBCOMMANDS = ImmutableList.of("toggle", "accept", "acceptany", "acceptall"); + private CommandExecutor ptpToggleCommand = new PtpToggleCommand(); private CommandExecutor ptpAcceptAnyCommand = new PtpAcceptAnyCommand(); private CommandExecutor ptpAcceptCommand = new PtpAcceptCommand(); @@ -68,6 +77,23 @@ public class PtpCommand implements CommandExecutor { } } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + List matches = StringUtil.copyPartialMatches(args[0], TELEPORT_SUBCOMMANDS, new ArrayList(TELEPORT_SUBCOMMANDS.size())); + + if (matches.size() == 0) { + Set playerNames = UserManager.getPlayers().keySet(); + return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); + } + + return matches; + default: + return ImmutableList.of(); + } + } + private void sendTeleportRequest(CommandSender sender, Player player, String targetName) { if (!canTeleport(sender, player, targetName)) { return; 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 452e7254b..cfd78c4e5 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java @@ -1,9 +1,14 @@ package com.gmail.nossr50.commands.player; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.PlayerProfile; @@ -13,7 +18,9 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; -public class InspectCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class InspectCommand implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { switch (args.length) { @@ -68,4 +75,15 @@ public class InspectCommand implements CommandExecutor { return false; } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + Set playerNames = UserManager.getPlayers().keySet(); + 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 eced770a1..f22b31a91 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java @@ -1,8 +1,13 @@ package com.gmail.nossr50.commands.player; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; @@ -17,7 +22,9 @@ import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils; -public class McrankCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class McrankCommand implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { switch (args.length) { @@ -74,6 +81,17 @@ public class McrankCommand implements CommandExecutor { } } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + Set playerNames = UserManager.getPlayers().keySet(); + return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList(playerNames.size())); + default: + return ImmutableList.of(); + } + } + private void flatfileDisplay(CommandSender sender, String playerName) { LeaderboardManager.updateLeaderboards(); // Make sure the information is up to date diff --git a/src/main/java/com/gmail/nossr50/commands/player/McstatsCommand.java b/src/main/java/com/gmail/nossr50/commands/player/McstatsCommand.java index 1b83c69a3..eccca9189 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/McstatsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/McstatsCommand.java @@ -1,8 +1,10 @@ package com.gmail.nossr50.commands.player; +import java.util.List; + import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import com.gmail.nossr50.config.Config; @@ -11,7 +13,9 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; -public class McstatsCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class McstatsCommand implements TabExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (CommandUtils.noConsoleUsage(sender)) { @@ -45,4 +49,9 @@ public class McstatsCommand implements CommandExecutor { return false; } } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return ImmutableList.of(); + } } diff --git a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java index d6ca6c721..21be181af 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java @@ -1,9 +1,13 @@ package com.gmail.nossr50.commands.player; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.ChatColor; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; @@ -15,7 +19,9 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.commands.CommandUtils; -public class MctopCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public class MctopCommand implements TabExecutor { private SkillType skill; @Override @@ -58,6 +64,16 @@ public class MctopCommand implements CommandExecutor { } } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + return StringUtil.copyPartialMatches(args[1], SkillType.SKILL_NAMES, new ArrayList(SkillType.SKILL_NAMES.size())); + default: + return ImmutableList.of(); + } + } + private void display(int page, String skill, CommandSender sender, boolean sql, Command command) { if (!skill.equalsIgnoreCase("all") && !Permissions.mctop(sender, this.skill)) { sender.sendMessage(command.getPermissionMessage()); diff --git a/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java index c3661163b..6635d68fb 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/SkillCommand.java @@ -1,11 +1,13 @@ package com.gmail.nossr50.commands.skills; import java.text.DecimalFormat; +import java.util.List; import java.util.Set; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; import com.gmail.nossr50.config.AdvancedConfig; @@ -21,7 +23,9 @@ import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.PerksUtils; import com.gmail.nossr50.util.skills.SkillUtils; -public abstract class SkillCommand implements CommandExecutor { +import com.google.common.collect.ImmutableList; + +public abstract class SkillCommand implements TabExecutor { protected SkillType skill; protected String skillName; @@ -102,6 +106,16 @@ public abstract class SkillCommand implements CommandExecutor { } } + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + return ImmutableList.of("?"); + default: + return ImmutableList.of(); + } + } + protected int calculateRank(int maxLevel, int rankChangeLevel) { return Math.min((int) skillValue, maxLevel) / rankChangeLevel; } diff --git a/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java b/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java index 772744aa4..19ce4b43e 100644 --- a/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/spout/MchudCommand.java @@ -1,12 +1,41 @@ package com.gmail.nossr50.commands.spout; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.datatypes.spout.huds.HudType; import com.gmail.nossr50.locale.LocaleLoader; +import com.google.common.collect.ImmutableList; public class MchudCommand extends SpoutCommand { + private static final List HUD_TYPES; + + static { + ArrayList types = new ArrayList(); + + for (HudType type : HudType.values()) { + types.add(type.toString()); + } + + Collections.sort(types); + HUD_TYPES = ImmutableList.copyOf(types); + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + return StringUtil.copyPartialMatches(args[0], HUD_TYPES, new ArrayList(HUD_TYPES.size())); + default: + return ImmutableList.of(); + } + } + @Override protected boolean noArguments(Command command, CommandSender sender, String[] args) { return false; diff --git a/src/main/java/com/gmail/nossr50/commands/spout/SpoutCommand.java b/src/main/java/com/gmail/nossr50/commands/spout/SpoutCommand.java index 5e7f8a907..b8bb4d5c2 100644 --- a/src/main/java/com/gmail/nossr50/commands/spout/SpoutCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/spout/SpoutCommand.java @@ -1,8 +1,8 @@ package com.gmail.nossr50.commands.spout; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.spout.SpoutConfig; @@ -12,7 +12,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; -public abstract class SpoutCommand implements CommandExecutor { +public abstract class SpoutCommand implements TabExecutor { protected PlayerProfile playerProfile; protected McMMOHud spoutHud; diff --git a/src/main/java/com/gmail/nossr50/commands/spout/XplockCommand.java b/src/main/java/com/gmail/nossr50/commands/spout/XplockCommand.java index 3daf03598..9f5770545 100644 --- a/src/main/java/com/gmail/nossr50/commands/spout/XplockCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/spout/XplockCommand.java @@ -1,15 +1,36 @@ package com.gmail.nossr50.commands.spout; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.util.StringUtil; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.skills.SkillUtils; +import com.google.common.collect.ImmutableList; public class XplockCommand extends SpoutCommand { + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + switch (args.length) { + case 1: + List matches = StringUtil.copyPartialMatches(args[0], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList(CommandUtils.TRUE_FALSE_OPTIONS.size())); + + if (matches.size() == 0) { + return StringUtil.copyPartialMatches(args[0], SkillType.SKILL_NAMES, new ArrayList(SkillType.SKILL_NAMES.size())); + } + + return matches; + default: + return ImmutableList.of(); + } + } + @Override protected boolean noArguments(Command command, CommandSender sender, String[] args) { if (spoutHud.getXpBarLocked()) { diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java index 36f458ca9..ac291a8e9 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java @@ -1,5 +1,9 @@ package com.gmail.nossr50.datatypes.skills; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.bukkit.Color; import com.gmail.nossr50.mcMMO; @@ -20,6 +24,8 @@ import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager; import com.gmail.nossr50.util.StringUtils; +import com.gmail.nossr50.util.skills.SkillUtils; +import com.google.common.collect.ImmutableList; public enum SkillType { ACROBATICS(AcrobaticsManager.class, Color.WHITE), @@ -41,6 +47,19 @@ public enum SkillType { private AbilityType ability; private ToolType tool; + public static final List SKILL_NAMES; + + static { + ArrayList names = new ArrayList(); + + for (SkillType skill : values()) { + names.add(SkillUtils.getSkillName(skill)); + } + + Collections.sort(names); + SKILL_NAMES = ImmutableList.copyOf(names); + } + private SkillType(Class managerClass, Color runescapeColor) { this.managerClass = managerClass; this.runescapeColor = runescapeColor; diff --git a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java index ed559efd4..9984c7945 100644 --- a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java +++ b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java @@ -1,5 +1,7 @@ package com.gmail.nossr50.util.commands; +import java.util.List; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -13,7 +15,12 @@ import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils; +import com.google.common.collect.ImmutableList; + public final class CommandUtils { + public static final List TRUE_FALSE_OPTIONS = ImmutableList.of("on", "off", "true", "false", "enabled", "disabled"); + public static final List RESET_OPTIONS = ImmutableList.of("clear", "reset"); + private CommandUtils() {} public static boolean isChildSkill(CommandSender sender, SkillType skill) {