diff --git a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java index d53b3e48d..8e25a3ba2 100644 --- a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java +++ b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java @@ -18,6 +18,7 @@ import com.gmail.nossr50.commands.player.McabilityCommand; import com.gmail.nossr50.commands.player.McmmoCommand; import com.gmail.nossr50.commands.player.McrankCommand; import com.gmail.nossr50.commands.player.McstatsCommand; +import com.gmail.nossr50.commands.player.MctopCommand; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand; import com.gmail.nossr50.skills.archery.ArcheryCommand; @@ -242,4 +243,13 @@ public final class CommandRegistrationHelper { command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mcstats")); command.setExecutor(new McstatsCommand()); } + + public static void registerMctopCommand() { + PluginCommand command = mcMMO.p.getCommand("mctop"); + command.setDescription(LocaleLoader.getString("Commands.Description.mctop")); + command.setPermission("mcmmo.commands.mctop"); // Only need the main one, not the individual skill ones + command.setPermissionMessage(permissionsMessage); + command.setUsage(LocaleLoader.getString("Commands.Usage.2", "mctop", "[" + LocaleLoader.getString("Commands.Usage.Skill") + "]", "[" + LocaleLoader.getString("Commands.Usage.Page") + "]")); + command.setExecutor(new MctopCommand()); + } } 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 6af689edc..7e6bf593b 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java @@ -19,74 +19,22 @@ import com.gmail.nossr50.util.Misc; public class MctopCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mctop")) { - return true; - } - - String usage = LocaleLoader.getString("Commands.Usage.2", "mctop", "[" + LocaleLoader.getString("Commands.Usage.Skill") + "]", "[" + LocaleLoader.getString("Commands.Usage.Page") + "]"); - - if (!Config.getInstance().getUseMySQL()) { - switch (args.length) { - case 0: - flatfileDisplay(1, "ALL", sender); - return true; - - case 1: - if (Misc.isInt(args[0])) { - flatfileDisplay(Integer.valueOf(args[0]), "ALL", sender); - } - else if (SkillTools.isSkill(args[0])) { - flatfileDisplay(1, args[0].toUpperCase(), sender); - } - else if (SkillTools.isLocalizedSkill(args[0])) { - flatfileDisplay(1, SkillTools.translateLocalizedSkill(args[0]).toUpperCase(), sender); - } - else { - sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); - } - - return true; - - case 2: - if (Misc.isInt(args[1])) { - if (SkillTools.isSkill(args[0])) { - flatfileDisplay(Integer.valueOf(args[1]), args[0].toUpperCase(), sender); - } - else if (SkillTools.isLocalizedSkill(args[0])) { - flatfileDisplay(Integer.valueOf(args[1]), SkillTools.translateLocalizedSkill(args[0]).toUpperCase(), sender); - } - else { - sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); - } - } - else { - sender.sendMessage(usage); - } - - return true; - - default: - sender.sendMessage(usage); - return true; - } - } - - String powerlevel = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing"; + boolean useMySQL = Config.getInstance().getUseMySQL(); switch (args.length) { case 0: - sqlDisplay(1, powerlevel, sender); + display(1, "ALL", sender, useMySQL); return true; case 1: if (Misc.isInt(args[0])) { - sqlDisplay(Integer.valueOf(args[0]), powerlevel, sender); + display(Integer.valueOf(args[0]), "ALL", sender, useMySQL); } else if (SkillTools.isSkill(args[0])) { - sqlDisplay(1, args[0].toLowerCase(), sender); + display(1, args[0], sender, useMySQL); } else if (SkillTools.isLocalizedSkill(args[0])) { - sqlDisplay(1, SkillTools.translateLocalizedSkill(args[0]).toLowerCase(), sender); + display(1, SkillTools.translateLocalizedSkill(args[0]), sender, useMySQL); } else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); @@ -95,26 +43,38 @@ public class MctopCommand implements CommandExecutor { return true; case 2: - if (Misc.isInt(args[1])) { - if (SkillTools.isSkill(args[0])) { - sqlDisplay(Integer.valueOf(args[1]), args[0].toLowerCase(), sender); - } - else if (SkillTools.isLocalizedSkill(args[0])) { - sqlDisplay(Integer.valueOf(args[1]), SkillTools.translateLocalizedSkill(args[0]).toLowerCase(), sender); - } - else { - sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); - } + if (!Misc.isInt(args[1])) { + return false; + } + + if (SkillTools.isSkill(args[0])) { + display(Integer.valueOf(args[1]), args[0], sender, useMySQL); + } + else if (SkillTools.isLocalizedSkill(args[0])) { + display(Integer.valueOf(args[1]), SkillTools.translateLocalizedSkill(args[0]), sender, useMySQL); } else { - sender.sendMessage(usage); + sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); } return true; default: - sender.sendMessage(usage); - return true; + return false; + } + } + + private void display(int page, String skill, CommandSender sender, boolean sql) { + if (sql) { + if (skill.equalsIgnoreCase("all")) { + sqlDisplay(page, "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing", sender); + } + else { + sqlDisplay(page, skill, sender); + } + } + else { + flatfileDisplay(page, skill, sender); } } @@ -169,11 +129,14 @@ public class MctopCommand implements CommandExecutor { else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", Misc.getCapitalized(query))); } + int place = (page * 10) - 9; for (int i = 1; i <= 10; i++) { - if(userslist.get(i) == null) { + if (userslist.get(i) == null) { break; } + + // Format: 1. Playername - skill value sender.sendMessage(String.valueOf(place) + ". " + ChatColor.GREEN + userslist.get(i).get(1) + " - " + ChatColor.WHITE + userslist.get(i).get(0)); place++; } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 0fc93e06d..a2599825e 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -25,7 +25,6 @@ import com.gmail.nossr50.chat.commands.ACommand; import com.gmail.nossr50.chat.commands.PCommand; import com.gmail.nossr50.commands.CommandRegistrationHelper; import com.gmail.nossr50.commands.player.MccCommand; -import com.gmail.nossr50.commands.player.MctopCommand; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.HiddenConfig; @@ -285,7 +284,7 @@ public class mcMMO extends JavaPlugin { CommandRegistrationHelper.registerMcgodCommand(); CommandRegistrationHelper.registerMcmmoCommand(); CommandRegistrationHelper.registerMcrefreshCommand(); - getCommand("mctop").setExecutor(new MctopCommand()); + CommandRegistrationHelper.registerMctopCommand(); CommandRegistrationHelper.registerMcrankCommand(); CommandRegistrationHelper.registerMcstatsCommand(); diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index 356a0cb2d..446653f12 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -698,6 +698,7 @@ Commands.Description.mcmmo=Show a brief description of mcMMO Commands.Description.mcrank=Show mcMMO ranking for a player Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO Commands.Description.mcstats=Show your mcMMO levels and XP +Commands.Description.mctop=Show mcMMO leader boards Commands.Description.mmoedit=Edit mcMMO levels for a user Commands.Description.Skill=Display detailed mcMMO skill info for {0} Commands.Description.skillreset=Reset mcMMO levels for a user diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e406a1485..f2105c52f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -34,8 +34,7 @@ commands: mcmmo: description: Shows a brief mod description mctop: - aliases: [] - description: Shows leader boards for mcMMO + description: Show mcMMO leader boards mcrank: description: Show mcMMO ranking for a player addxp: