From d0ca2b9d4ba19ee2cba1e7427f08608bce0b504d Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 6 Feb 2013 17:10:05 -0500 Subject: [PATCH] Update /mmoupdate to use Bukkit CommandAPI. Addresses #628 --- .../commands/CommandRegistrationHelper.java | 12 +++++++- .../database/commands/MmoupdateCommand.java | 28 +++++++++---------- src/main/java/com/gmail/nossr50/mcMMO.java | 3 +- .../resources/locale/locale_en_US.properties | 1 + src/main/resources/plugin.yml | 1 - 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java index 883d4b0b2..a5d9e7c57 100644 --- a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java +++ b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java @@ -22,6 +22,7 @@ import com.gmail.nossr50.commands.player.MctopCommand; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.commands.McpurgeCommand; import com.gmail.nossr50.database.commands.McremoveCommand; +import com.gmail.nossr50.database.commands.MmoupdateCommand; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand; import com.gmail.nossr50.skills.archery.ArcheryCommand; @@ -250,10 +251,19 @@ public final class CommandRegistrationHelper { public static void registerMcremoveCommand() { PluginCommand command = mcMMO.p.getCommand("mcremove"); - command.setDescription(LocaleLoader.getString("Commands.Description.mcremove", Config.getInstance().getOldUsersCutoff())); + command.setDescription(LocaleLoader.getString("Commands.Description.mcremove")); command.setPermission("mcmmo.commands.mcremove"); command.setPermissionMessage(permissionsMessage); command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcremove", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">")); command.setExecutor(new McremoveCommand()); } + + public static void registerMmoupdateCommand() { + PluginCommand command = mcMMO.p.getCommand("mmoupdate"); + command.setDescription(LocaleLoader.getString("Commands.Description.mmoupdate")); + command.setPermission("mcmmo.commands.mmoupdate"); + command.setPermissionMessage(permissionsMessage); + command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mmoupdate")); + command.setExecutor(new MmoupdateCommand()); + } } diff --git a/src/main/java/com/gmail/nossr50/database/commands/MmoupdateCommand.java b/src/main/java/com/gmail/nossr50/database/commands/MmoupdateCommand.java index 7bf269cf3..fbe5d1abe 100644 --- a/src/main/java/com/gmail/nossr50/database/commands/MmoupdateCommand.java +++ b/src/main/java/com/gmail/nossr50/database/commands/MmoupdateCommand.java @@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.runnables.SQLConversionTask; import com.gmail.nossr50.locale.LocaleLoader; @@ -15,21 +14,22 @@ import com.gmail.nossr50.util.Users; public class MmoupdateCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoupdate")) { + switch (args.length) { + case 0: + sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start")); + Users.clearAll(); + convertToMySQL(); + + for (Player player : mcMMO.p.getServer().getOnlinePlayers()) { + Users.addUser(player); + } + + sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Finish")); return true; + + default: + return false; } - - sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start")); - Users.clearAll(); - convertToMySQL(); - - for (Player x : mcMMO.p.getServer().getOnlinePlayers()) { - Users.addUser(x); - } - - sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Finish")); - - return true; } /** diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 9f2bc0e68..94ebb3d44 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -32,7 +32,6 @@ import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.TreasuresConfig; import com.gmail.nossr50.database.Database; import com.gmail.nossr50.database.Leaderboard; -import com.gmail.nossr50.database.commands.MmoupdateCommand; import com.gmail.nossr50.database.runnables.UserPurgeTask; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.listeners.BlockListener; @@ -305,7 +304,7 @@ public class mcMMO extends JavaPlugin { CommandRegistrationHelper.registerMmoeditCommand(); CommandRegistrationHelper.registerInspectCommand(); CommandRegistrationHelper.registerXprateCommand(); - getCommand("mmoupdate").setExecutor(new MmoupdateCommand()); + CommandRegistrationHelper.registerMmoupdateCommand(); CommandRegistrationHelper.registerSkillresetCommand(); // Spout commands diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index bc7c04cb1..ea0eba4ba 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -702,6 +702,7 @@ Commands.Description.mcremove=Remove a user from the mcMMO database 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.mmoupdate=Convert mcMMO database from Flatfile to MySQL Commands.Description.Skill=Display detailed mcMMO skill info for {0} Commands.Description.skillreset=Reset mcMMO levels for a user Commands.Description.xprate=Modify the mcMMO XP rate or start an mcMMO XP event diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e51f76f42..0fbba1494 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -63,7 +63,6 @@ commands: inspect: description: View detailed mcMMO info on another player mmoupdate: - aliases: [] description: Convert from Flat File to MySQL p: aliases: [pc]