From 4d93f3271db5c60f671c74d504de89f26009c15e Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 4 Feb 2013 17:35:48 -0500 Subject: [PATCH] Update /mcability to use Bukkit CommandAPI. Addresses #628 --- .../commands/CommandRegistrationHelper.java | 10 +++++ .../commands/player/McabilityCommand.java | 40 ++++++++++--------- 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, 34 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java index 13b05f0a6..813326e44 100644 --- a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java +++ b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java @@ -14,6 +14,7 @@ import com.gmail.nossr50.commands.admin.MmoeditCommand; import com.gmail.nossr50.commands.admin.SkillresetCommand; import com.gmail.nossr50.commands.admin.XprateCommand; import com.gmail.nossr50.commands.player.InspectCommand; +import com.gmail.nossr50.commands.player.McabilityCommand; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand; import com.gmail.nossr50.skills.archery.ArcheryCommand; @@ -193,4 +194,13 @@ public final class CommandRegistrationHelper { command.setUsage(LocaleLoader.getString("Commands.Usage.1", "inspect", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">")); command.setExecutor(new InspectCommand()); } + + public static void registerMcabilityCommand() { + PluginCommand command = mcMMO.p.getCommand("mcability"); + command.setDescription(LocaleLoader.getString("Commands.Description.mcability")); + command.setPermission("mcmmo.commands.ability;mcmmo.commands.mcability.others"); + command.setPermissionMessage(permissionsMessage); + command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcability", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">")); + command.setExecutor(new McabilityCommand()); + } } diff --git a/src/main/java/com/gmail/nossr50/commands/player/McabilityCommand.java b/src/main/java/com/gmail/nossr50/commands/player/McabilityCommand.java index ccb86ebe3..b4b73fb08 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/McabilityCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/McabilityCommand.java @@ -1,26 +1,25 @@ package com.gmail.nossr50.commands.player; -import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; 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.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; public class McabilityCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { PlayerProfile profile; - String usage = LocaleLoader.getString("Commands.Usage.1", "mcability", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"); switch (args.length) { case 0: - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mcability")) { + if (!Permissions.hasPermission(sender, "mcmmo.commands.mcability")) { + sender.sendMessage(command.getPermissionMessage()); return true; } @@ -37,32 +36,37 @@ public class McabilityCommand implements CommandExecutor { return true; case 1: - if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mcability.others")) { + if (!Permissions.hasPermission(sender, "mcmmo.commands.mcability.others")) { + sender.sendMessage(command.getPermissionMessage()); return true; } - OfflinePlayer modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]); - profile = Users.getPlayer(args[0]).getProfile(); + McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]); - // TODO:Not sure if we actually need a null check here - if (profile == null || !profile.isLoaded()) { - sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); - return true; - } + if (mcMMOPlayer == null) { + profile = new PlayerProfile(args[0], false); - if (profile.getAbilityUse()) { - ((Player) modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.Ability.Off")); + if (!profile.isLoaded()) { + sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); + return true; + } } else { - ((Player) modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.Ability.On")); + profile = mcMMOPlayer.getProfile(); + + if (profile.getAbilityUse()) { + mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Ability.Off")); + } + else { + mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Ability.On")); + } } profile.toggleAbilityUse(); return true; default: - sender.sendMessage(usage); - return true; + return false; } } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index ab78da4e6..da2144aad 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.util.blockmeta.chunkmeta.ChunkManagerFactory; 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.McabilityCommand; import com.gmail.nossr50.commands.player.MccCommand; import com.gmail.nossr50.commands.player.McmmoCommand; import com.gmail.nossr50.commands.player.McrankCommand; @@ -431,7 +430,7 @@ public class mcMMO extends JavaPlugin { // mc* commands getCommand("mcpurge").setExecutor(new McpurgeCommand()); getCommand("mcremove").setExecutor(new McremoveCommand()); - getCommand("mcability").setExecutor(new McabilityCommand()); + CommandRegistrationHelper.registerMcabilityCommand(); getCommand("mcc").setExecutor(new MccCommand()); CommandRegistrationHelper.registerMcgodCommand(); getCommand("mcmmo").setExecutor(new McmmoCommand()); diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index 47007de32..eab6abbdf 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -690,6 +690,7 @@ Smelting.SkillName=SMELTING Commands.Description.addlevels=Add mcMMO levels to a user Commands.Description.addxp=Add mcMMO XP to a user Commands.Description.inspect=View detailed mcMMO info on another player +Commands.Description.mcability=Toggle mcMMO abilities being readied on right-click on/off Commands.Description.mcgod=Toggle mcMMO god-mode on/off Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO Commands.Description.mmoedit=Edit mcMMO levels for a user diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1f9efdaca..b2172002a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -45,7 +45,6 @@ commands: addlevels: description: Add mcMMO levels to a user mcability: - aliases: [] description: Toggle whether or not abilities get readied on right click mcrefresh: description: Refresh all cooldowns for mcMMO