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.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());
}
}

View File

@ -19,27 +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;
}
boolean useMySQL = Config.getInstance().getUseMySQL();
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);
display(1, "ALL", sender, useMySQL);
return true;
case 1:
if (Misc.isInt(args[0])) {
flatfileDisplay(Integer.valueOf(args[0]), "ALL", sender);
display(Integer.valueOf(args[0]), "ALL", sender, useMySQL);
}
else if (SkillTools.isSkill(args[0])) {
flatfileDisplay(1, args[0].toUpperCase(), sender);
display(1, args[0], sender, useMySQL);
}
else if (SkillTools.isLocalizedSkill(args[0])) {
flatfileDisplay(1, SkillTools.translateLocalizedSkill(args[0]).toUpperCase(), sender);
display(1, SkillTools.translateLocalizedSkill(args[0]), sender, useMySQL);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
@ -48,73 +43,38 @@ public class MctopCommand implements CommandExecutor {
return true;
case 2:
if (Misc.isInt(args[1])) {
if (!Misc.isInt(args[1])) {
return false;
}
if (SkillTools.isSkill(args[0])) {
flatfileDisplay(Integer.valueOf(args[1]), args[0].toUpperCase(), sender);
display(Integer.valueOf(args[1]), args[0], sender, useMySQL);
}
else if (SkillTools.isLocalizedSkill(args[0])) {
flatfileDisplay(Integer.valueOf(args[1]), SkillTools.translateLocalizedSkill(args[0]).toUpperCase(), sender);
display(Integer.valueOf(args[1]), SkillTools.translateLocalizedSkill(args[0]), sender, useMySQL);
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
}
}
else {
sender.sendMessage(usage);
}
return true;
default:
sender.sendMessage(usage);
return true;
return false;
}
}
String powerlevel = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing";
switch (args.length) {
case 0:
sqlDisplay(1, powerlevel, sender);
return true;
case 1:
if (Misc.isInt(args[0])) {
sqlDisplay(Integer.valueOf(args[0]), powerlevel, sender);
}
else if (SkillTools.isSkill(args[0])) {
sqlDisplay(1, args[0].toLowerCase(), sender);
}
else if (SkillTools.isLocalizedSkill(args[0])) {
sqlDisplay(1, SkillTools.translateLocalizedSkill(args[0]).toLowerCase(), sender);
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 {
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
}
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"));
sqlDisplay(page, skill, sender);
}
}
else {
sender.sendMessage(usage);
}
return true;
default:
sender.sendMessage(usage);
return true;
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++;
}

View File

@ -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();

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.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

View File

@ -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: