Update /inspect to use Bukkit command API. Addresses #628

This commit is contained in:
GJ 2013-02-04 16:43:37 -05:00
parent 49ef013152
commit 0683745dd2
5 changed files with 64 additions and 51 deletions

View File

@ -13,6 +13,7 @@ import com.gmail.nossr50.commands.admin.McrefreshCommand;
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.locale.LocaleLoader;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsCommand;
import com.gmail.nossr50.skills.archery.ArcheryCommand;
@ -183,4 +184,13 @@ public final class CommandRegistrationHelper {
command.setAliases(aliasList);
command.setExecutor(new XprateCommand());
}
public static void registerInspectCommand() {
PluginCommand command = mcMMO.p.getCommand("inspect");
command.setDescription(LocaleLoader.getString("Commands.Description.inspect"));
command.setPermission("mcmmo.commands.inspect;mcmmo.commands.inspect.far;mcmmo.commands.inspect.offline");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "inspect", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
command.setExecutor(new InspectCommand());
}
}

View File

@ -17,32 +17,23 @@ import com.gmail.nossr50.util.Users;
public class InspectCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String usage = LocaleLoader.getString("Commands.Usage.1", "inspect", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">");
if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.inspect")) {
return true;
}
PlayerProfile profile;
switch (args.length) {
case 1:
McMMOPlayer mcmmoPlayer = Users.getPlayer(args[0]);
if (mcmmoPlayer != null) {
Player target = mcmmoPlayer.getPlayer();
if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), 5.0) && !Permissions.inspectFar((Player) sender)) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
if (!Permissions.hasPermission(sender, "mcmmo.commands.inspect")) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
PlayerProfile profile = mcmmoPlayer.getProfile();
McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName()));
CommandHelper.printGatheringSkills(target, profile, sender);
CommandHelper.printCombatSkills(target, profile, sender);
CommandHelper.printMiscSkills(target, profile, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcmmoPlayer.getPowerLevel()));
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
profile = new PlayerProfile(args[0], false); //Temporary Profile
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
@ -51,13 +42,6 @@ public class InspectCommand implements CommandExecutor {
return true;
}
PlayerProfile profile = new PlayerProfile(args[0], false); //Temporary Profile
if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", args[0]));
sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
@ -77,12 +61,31 @@ public class InspectCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Acrobatics.Listener"), profile.getSkillLevel(SkillType.ACROBATICS), profile.getSkillXpLevel(SkillType.ACROBATICS), profile.getXpToLevel(SkillType.ACROBATICS)));
sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Repair.Listener"), profile.getSkillLevel(SkillType.REPAIR), profile.getSkillXpLevel(SkillType.REPAIR), profile.getXpToLevel(SkillType.REPAIR)));
}
else {
Player target = mcMMOPlayer.getPlayer();
if (sender instanceof Player) {
Player inspector = (Player) sender;
if (!Misc.isNear(inspector.getLocation(), target.getLocation(), 5.0) && !Permissions.inspectFar(inspector)) {
sender.sendMessage(LocaleLoader.getString("Inspect.TooFar"));
return true;
}
}
profile = mcMMOPlayer.getProfile();
sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName()));
CommandHelper.printGatheringSkills(target, profile, sender);
CommandHelper.printCombatSkills(target, profile, sender);
CommandHelper.printMiscSkills(target, profile, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel()));
}
return true;
default:
sender.sendMessage(usage);
return true;
return false;
}
}
}

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.PCommand;
import com.gmail.nossr50.commands.CommandRegistrationHelper;
import com.gmail.nossr50.commands.player.InspectCommand;
import com.gmail.nossr50.commands.player.McabilityCommand;
import com.gmail.nossr50.commands.player.MccCommand;
import com.gmail.nossr50.commands.player.McmmoCommand;
@ -451,7 +450,7 @@ public class mcMMO extends JavaPlugin {
CommandRegistrationHelper.registerAddxpCommand();
CommandRegistrationHelper.registerAddlevelsCommand();
CommandRegistrationHelper.registerMmoeditCommand();
getCommand("inspect").setExecutor(new InspectCommand());
CommandRegistrationHelper.registerInspectCommand();
CommandRegistrationHelper.registerXprateCommand();
getCommand("mmoupdate").setExecutor(new MmoupdateCommand());
CommandRegistrationHelper.registerSkillresetCommand();

View File

@ -689,6 +689,7 @@ Smelting.SkillName=SMELTING
#COMMAND DESCRIPTIONS
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.mcgod=Toggle mcMMO god-mode on/off
Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO
Commands.Description.mmoedit=Edit mcMMO levels for a user

View File

@ -66,7 +66,7 @@ commands:
aliases: []
description: Create/join a party
inspect:
aliases: []
description: View detailed mcMMO info on another player
mmoupdate:
aliases: []
description: Convert from Flat File to MySQL