Update /mctop to use Bukkit CommandAPI. Addresses #628

This commit is contained in:
GJ 2013-02-05 10:54:53 -05:00
parent aad14169fb
commit 9103914bc9
5 changed files with 47 additions and 75 deletions

View File

@ -18,6 +18,7 @@ import com.gmail.nossr50.commands.player.McabilityCommand;
import com.gmail.nossr50.commands.player.McmmoCommand; import com.gmail.nossr50.commands.player.McmmoCommand;
import com.gmail.nossr50.commands.player.McrankCommand; import com.gmail.nossr50.commands.player.McrankCommand;
import com.gmail.nossr50.commands.player.McstatsCommand; import com.gmail.nossr50.commands.player.McstatsCommand;
import com.gmail.nossr50.commands.player.MctopCommand;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand; import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand;
import com.gmail.nossr50.skills.archery.ArcheryCommand; import com.gmail.nossr50.skills.archery.ArcheryCommand;
@ -242,4 +243,13 @@ public final class CommandRegistrationHelper {
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mcstats")); command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mcstats"));
command.setExecutor(new McstatsCommand()); 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());
}
} }

View File

@ -19,74 +19,22 @@ import com.gmail.nossr50.util.Misc;
public class MctopCommand implements CommandExecutor { public class MctopCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mctop")) { boolean useMySQL = Config.getInstance().getUseMySQL();
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";
switch (args.length) { switch (args.length) {
case 0: case 0:
sqlDisplay(1, powerlevel, sender); display(1, "ALL", sender, useMySQL);
return true; return true;
case 1: case 1:
if (Misc.isInt(args[0])) { 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])) { else if (SkillTools.isSkill(args[0])) {
sqlDisplay(1, args[0].toLowerCase(), sender); display(1, args[0], sender, useMySQL);
} }
else if (SkillTools.isLocalizedSkill(args[0])) { else if (SkillTools.isLocalizedSkill(args[0])) {
sqlDisplay(1, SkillTools.translateLocalizedSkill(args[0]).toLowerCase(), sender); display(1, SkillTools.translateLocalizedSkill(args[0]), sender, useMySQL);
} }
else { else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
@ -95,26 +43,38 @@ public class MctopCommand implements CommandExecutor {
return true; return true;
case 2: case 2:
if (Misc.isInt(args[1])) { if (!Misc.isInt(args[1])) {
if (SkillTools.isSkill(args[0])) { return false;
sqlDisplay(Integer.valueOf(args[1]), args[0].toLowerCase(), sender); }
}
else if (SkillTools.isLocalizedSkill(args[0])) { if (SkillTools.isSkill(args[0])) {
sqlDisplay(Integer.valueOf(args[1]), SkillTools.translateLocalizedSkill(args[0]).toLowerCase(), sender); display(Integer.valueOf(args[1]), args[0], sender, useMySQL);
} }
else { else if (SkillTools.isLocalizedSkill(args[0])) {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); display(Integer.valueOf(args[1]), SkillTools.translateLocalizedSkill(args[0]), sender, useMySQL);
}
} }
else { else {
sender.sendMessage(usage); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
} }
return true; return true;
default: default:
sender.sendMessage(usage); return false;
return true; }
}
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 { else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", Misc.getCapitalized(query))); sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", Misc.getCapitalized(query)));
} }
int place = (page * 10) - 9; int place = (page * 10) - 9;
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {
if(userslist.get(i) == null) { if (userslist.get(i) == null) {
break; 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)); sender.sendMessage(String.valueOf(place) + ". " + ChatColor.GREEN + userslist.get(i).get(1) + " - " + ChatColor.WHITE + userslist.get(i).get(0));
place++; place++;
} }

View File

@ -25,7 +25,6 @@ import com.gmail.nossr50.chat.commands.ACommand;
import com.gmail.nossr50.chat.commands.PCommand; import com.gmail.nossr50.chat.commands.PCommand;
import com.gmail.nossr50.commands.CommandRegistrationHelper; import com.gmail.nossr50.commands.CommandRegistrationHelper;
import com.gmail.nossr50.commands.player.MccCommand; 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.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.HiddenConfig;
@ -285,7 +284,7 @@ public class mcMMO extends JavaPlugin {
CommandRegistrationHelper.registerMcgodCommand(); CommandRegistrationHelper.registerMcgodCommand();
CommandRegistrationHelper.registerMcmmoCommand(); CommandRegistrationHelper.registerMcmmoCommand();
CommandRegistrationHelper.registerMcrefreshCommand(); CommandRegistrationHelper.registerMcrefreshCommand();
getCommand("mctop").setExecutor(new MctopCommand()); CommandRegistrationHelper.registerMctopCommand();
CommandRegistrationHelper.registerMcrankCommand(); CommandRegistrationHelper.registerMcrankCommand();
CommandRegistrationHelper.registerMcstatsCommand(); CommandRegistrationHelper.registerMcstatsCommand();

View File

@ -698,6 +698,7 @@ Commands.Description.mcmmo=Show a brief description of mcMMO
Commands.Description.mcrank=Show mcMMO ranking for a player Commands.Description.mcrank=Show mcMMO ranking for a player
Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO
Commands.Description.mcstats=Show your mcMMO levels and XP 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.mmoedit=Edit mcMMO levels for a user
Commands.Description.Skill=Display detailed mcMMO skill info for {0} Commands.Description.Skill=Display detailed mcMMO skill info for {0}
Commands.Description.skillreset=Reset mcMMO levels for a user Commands.Description.skillreset=Reset mcMMO levels for a user

View File

@ -34,8 +34,7 @@ commands:
mcmmo: mcmmo:
description: Shows a brief mod description description: Shows a brief mod description
mctop: mctop:
aliases: [] description: Show mcMMO leader boards
description: Shows leader boards for mcMMO
mcrank: mcrank:
description: Show mcMMO ranking for a player description: Show mcMMO ranking for a player
addxp: addxp: