From 0683745dd2f140966767763a11421cb758042653 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 4 Feb 2013 16:43:37 -0500 Subject: [PATCH] Update /inspect to use Bukkit command API. Addresses #628 --- .../commands/CommandRegistrationHelper.java | 10 ++ .../commands/player/InspectCommand.java | 99 ++++++++++--------- src/main/java/com/gmail/nossr50/mcMMO.java | 3 +- .../resources/locale/locale_en_US.properties | 1 + src/main/resources/plugin.yml | 2 +- 5 files changed, 64 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java index 1413e0b6c..13b05f0a6 100644 --- a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java +++ b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java @@ -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()); + } } diff --git a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java index 4cd967950..f5f88b9b9 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java @@ -17,72 +17,75 @@ 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 (!Permissions.hasPermission(sender, "mcmmo.commands.inspect")) { + sender.sendMessage(command.getPermissionMessage()); + return true; + } - if (mcmmoPlayer != null) { - Player target = mcmmoPlayer.getPlayer(); + McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]); - if (sender instanceof Player && !Misc.isNear(((Player) sender).getLocation(), target.getLocation(), 5.0) && !Permissions.inspectFar((Player) sender)) { - sender.sendMessage(LocaleLoader.getString("Inspect.TooFar")); + // 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; } - PlayerProfile profile = mcmmoPlayer.getProfile(); + if (sender instanceof Player && !Permissions.inspectOffline((Player) sender)) { + sender.sendMessage(LocaleLoader.getString("Inspect.Offline")); + return true; + } + + sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", args[0])); + + sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering")); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Excavation.Listener"), profile.getSkillLevel(SkillType.EXCAVATION), profile.getSkillXpLevel(SkillType.EXCAVATION), profile.getXpToLevel(SkillType.EXCAVATION))); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Fishing.Listener"), profile.getSkillLevel(SkillType.FISHING), profile.getSkillXpLevel(SkillType.FISHING), profile.getXpToLevel(SkillType.FISHING))); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Herbalism.Listener"), profile.getSkillLevel(SkillType.HERBALISM), profile.getSkillXpLevel(SkillType.HERBALISM), profile.getXpToLevel(SkillType.HERBALISM))); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Mining.Listener"), profile.getSkillLevel(SkillType.MINING), profile.getSkillXpLevel(SkillType.MINING), profile.getXpToLevel(SkillType.MINING))); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Woodcutting.Listener"), profile.getSkillLevel(SkillType.WOODCUTTING), profile.getSkillXpLevel(SkillType.WOODCUTTING), profile.getXpToLevel(SkillType.WOODCUTTING))); + + sender.sendMessage(LocaleLoader.getString("Stats.Header.Combat")); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Axes.Listener"), profile.getSkillLevel(SkillType.AXES), profile.getSkillXpLevel(SkillType.AXES), profile.getXpToLevel(SkillType.AXES))); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Archery.Listener"), profile.getSkillLevel(SkillType.ARCHERY), profile.getSkillXpLevel(SkillType.ARCHERY), profile.getXpToLevel(SkillType.ARCHERY))); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Swords.Listener"), profile.getSkillLevel(SkillType.SWORDS), profile.getSkillXpLevel(SkillType.SWORDS), profile.getXpToLevel(SkillType.SWORDS))); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Taming.Listener"), profile.getSkillLevel(SkillType.TAMING), profile.getSkillXpLevel(SkillType.TAMING), profile.getXpToLevel(SkillType.TAMING))); + sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Unarmed.Listener"), profile.getSkillLevel(SkillType.UNARMED), profile.getSkillXpLevel(SkillType.UNARMED), profile.getXpToLevel(SkillType.UNARMED))); + + 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; + sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel())); } - if (sender instanceof Player && !Permissions.inspectOffline((Player) sender)) { - sender.sendMessage(LocaleLoader.getString("Inspect.Offline")); - 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")); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Excavation.Listener"), profile.getSkillLevel(SkillType.EXCAVATION), profile.getSkillXpLevel(SkillType.EXCAVATION), profile.getXpToLevel(SkillType.EXCAVATION))); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Fishing.Listener"), profile.getSkillLevel(SkillType.FISHING), profile.getSkillXpLevel(SkillType.FISHING), profile.getXpToLevel(SkillType.FISHING))); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Herbalism.Listener"), profile.getSkillLevel(SkillType.HERBALISM), profile.getSkillXpLevel(SkillType.HERBALISM), profile.getXpToLevel(SkillType.HERBALISM))); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Mining.Listener"), profile.getSkillLevel(SkillType.MINING), profile.getSkillXpLevel(SkillType.MINING), profile.getXpToLevel(SkillType.MINING))); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Woodcutting.Listener"), profile.getSkillLevel(SkillType.WOODCUTTING), profile.getSkillXpLevel(SkillType.WOODCUTTING), profile.getXpToLevel(SkillType.WOODCUTTING))); - - sender.sendMessage(LocaleLoader.getString("Stats.Header.Combat")); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Axes.Listener"), profile.getSkillLevel(SkillType.AXES), profile.getSkillXpLevel(SkillType.AXES), profile.getXpToLevel(SkillType.AXES))); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Archery.Listener"), profile.getSkillLevel(SkillType.ARCHERY), profile.getSkillXpLevel(SkillType.ARCHERY), profile.getXpToLevel(SkillType.ARCHERY))); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Swords.Listener"), profile.getSkillLevel(SkillType.SWORDS), profile.getSkillXpLevel(SkillType.SWORDS), profile.getXpToLevel(SkillType.SWORDS))); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Taming.Listener"), profile.getSkillLevel(SkillType.TAMING), profile.getSkillXpLevel(SkillType.TAMING), profile.getXpToLevel(SkillType.TAMING))); - sender.sendMessage(LocaleLoader.getString("Skills.Stats", LocaleLoader.getString("Unarmed.Listener"), profile.getSkillLevel(SkillType.UNARMED), profile.getSkillXpLevel(SkillType.UNARMED), profile.getXpToLevel(SkillType.UNARMED))); - - 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))); - 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 1198757ef..ab78da4e6 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.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(); diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index de5c21873..47007de32 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -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 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fcce683b7..1f9efdaca 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -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