Update /mcability to use Bukkit CommandAPI. Addresses #628

This commit is contained in:
GJ 2013-02-04 17:35:48 -05:00
parent 0683745dd2
commit 4d93f3271d
5 changed files with 34 additions and 21 deletions

View File

@ -14,6 +14,7 @@ import com.gmail.nossr50.commands.admin.MmoeditCommand;
import com.gmail.nossr50.commands.admin.SkillresetCommand; import com.gmail.nossr50.commands.admin.SkillresetCommand;
import com.gmail.nossr50.commands.admin.XprateCommand; import com.gmail.nossr50.commands.admin.XprateCommand;
import com.gmail.nossr50.commands.player.InspectCommand; import com.gmail.nossr50.commands.player.InspectCommand;
import com.gmail.nossr50.commands.player.McabilityCommand;
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;
@ -193,4 +194,13 @@ public final class CommandRegistrationHelper {
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "inspect", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">")); command.setUsage(LocaleLoader.getString("Commands.Usage.1", "inspect", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
command.setExecutor(new InspectCommand()); 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());
}
} }

View File

@ -1,26 +1,25 @@
package com.gmail.nossr50.commands.player; package com.gmail.nossr50.commands.player;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class McabilityCommand implements CommandExecutor { public class McabilityCommand 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) {
PlayerProfile profile; PlayerProfile profile;
String usage = LocaleLoader.getString("Commands.Usage.1", "mcability", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">");
switch (args.length) { switch (args.length) {
case 0: case 0:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mcability")) { if (!Permissions.hasPermission(sender, "mcmmo.commands.mcability")) {
sender.sendMessage(command.getPermissionMessage());
return true; return true;
} }
@ -37,32 +36,37 @@ public class McabilityCommand implements CommandExecutor {
return true; return true;
case 1: case 1:
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mcability.others")) { if (!Permissions.hasPermission(sender, "mcmmo.commands.mcability.others")) {
sender.sendMessage(command.getPermissionMessage());
return true; return true;
} }
OfflinePlayer modifiedPlayer = mcMMO.p.getServer().getOfflinePlayer(args[0]); McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
profile = Users.getPlayer(args[0]).getProfile();
// TODO:Not sure if we actually need a null check here if (mcMMOPlayer == null) {
if (profile == null || !profile.isLoaded()) { profile = new PlayerProfile(args[0], false);
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true; return true;
} }
if (profile.getAbilityUse()) {
((Player) modifiedPlayer).sendMessage(LocaleLoader.getString("Commands.Ability.Off"));
} }
else { 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(); profile.toggleAbilityUse();
return true; return true;
default: default:
sender.sendMessage(usage); return false;
return true;
} }
} }
} }

View File

@ -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.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.McabilityCommand;
import com.gmail.nossr50.commands.player.MccCommand; import com.gmail.nossr50.commands.player.MccCommand;
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;
@ -431,7 +430,7 @@ public class mcMMO extends JavaPlugin {
// mc* commands // mc* commands
getCommand("mcpurge").setExecutor(new McpurgeCommand()); getCommand("mcpurge").setExecutor(new McpurgeCommand());
getCommand("mcremove").setExecutor(new McremoveCommand()); getCommand("mcremove").setExecutor(new McremoveCommand());
getCommand("mcability").setExecutor(new McabilityCommand()); CommandRegistrationHelper.registerMcabilityCommand();
getCommand("mcc").setExecutor(new MccCommand()); getCommand("mcc").setExecutor(new MccCommand());
CommandRegistrationHelper.registerMcgodCommand(); CommandRegistrationHelper.registerMcgodCommand();
getCommand("mcmmo").setExecutor(new McmmoCommand()); getCommand("mcmmo").setExecutor(new McmmoCommand());

View File

@ -690,6 +690,7 @@ Smelting.SkillName=SMELTING
Commands.Description.addlevels=Add mcMMO levels to a user Commands.Description.addlevels=Add mcMMO levels to a user
Commands.Description.addxp=Add mcMMO XP to a user Commands.Description.addxp=Add mcMMO XP to a user
Commands.Description.inspect=View detailed mcMMO info on another player 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.mcgod=Toggle mcMMO god-mode on/off
Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO
Commands.Description.mmoedit=Edit mcMMO levels for a user Commands.Description.mmoedit=Edit mcMMO levels for a user

View File

@ -45,7 +45,6 @@ commands:
addlevels: addlevels:
description: Add mcMMO levels to a user description: Add mcMMO levels to a user
mcability: mcability:
aliases: []
description: Toggle whether or not abilities get readied on right click description: Toggle whether or not abilities get readied on right click
mcrefresh: mcrefresh:
description: Refresh all cooldowns for mcMMO description: Refresh all cooldowns for mcMMO