浏览代码

Changed /mmoedit to use Bukkit command info. Also fixed bug where
/mcrefresh was registered with the info of /mcgod

GJ 12 年之前
父节点
当前提交
c3db026fd9

+ 12 - 2
src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java

@@ -9,6 +9,8 @@ import com.gmail.nossr50.mcMMO;
 import com.gmail.nossr50.commands.admin.AddlevelsCommand;
 import com.gmail.nossr50.commands.admin.AddlevelsCommand;
 import com.gmail.nossr50.commands.admin.AddxpCommand;
 import com.gmail.nossr50.commands.admin.AddxpCommand;
 import com.gmail.nossr50.commands.admin.McgodCommand;
 import com.gmail.nossr50.commands.admin.McgodCommand;
+import com.gmail.nossr50.commands.admin.McrefreshCommand;
+import com.gmail.nossr50.commands.admin.MmoeditCommand;
 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;
@@ -28,7 +30,6 @@ import com.gmail.nossr50.util.Misc;
 
 
 public final class CommandRegistrationHelper {
 public final class CommandRegistrationHelper {
     private CommandRegistrationHelper() {};
     private CommandRegistrationHelper() {};
-
     private static String permissionsMessage = LocaleLoader.getString("mcMMO.NoPermission");
     private static String permissionsMessage = LocaleLoader.getString("mcMMO.NoPermission");
 
 
     public static void registerSkillCommands() {
     public static void registerSkillCommands() {
@@ -148,6 +149,15 @@ public final class CommandRegistrationHelper {
         command.setPermission("mcmmo.commands.mcrefresh");
         command.setPermission("mcmmo.commands.mcrefresh");
         command.setPermissionMessage(permissionsMessage);
         command.setPermissionMessage(permissionsMessage);
         command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcrefresh", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
         command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcrefresh", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
-        command.setExecutor(new McgodCommand());
+        command.setExecutor(new McrefreshCommand());
+    }
+
+    public static void registerMmoeditCommand() {
+        PluginCommand command = mcMMO.p.getCommand("mmoedit");
+        command.setDescription(LocaleLoader.getString("Commands.Description.mmoedit"));
+        command.setPermission("mcmmo.commands.mmoedit");
+        command.setPermissionMessage(permissionsMessage);
+        command.setUsage(LocaleLoader.getString("Commands.Usage.3", "mmoedit", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">"));
+        command.setExecutor(new MmoeditCommand());
     }
     }
 }
 }

+ 49 - 63
src/main/java/com/gmail/nossr50/commands/admin/MmoeditCommand.java

@@ -5,13 +5,13 @@ 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.commands.CommandHelper;
 import com.gmail.nossr50.datatypes.McMMOPlayer;
 import com.gmail.nossr50.datatypes.McMMOPlayer;
 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.skills.utilities.SkillTools;
 import com.gmail.nossr50.skills.utilities.SkillTools;
 import com.gmail.nossr50.skills.utilities.SkillType;
 import com.gmail.nossr50.skills.utilities.SkillType;
 import com.gmail.nossr50.util.Misc;
 import com.gmail.nossr50.util.Misc;
+import com.gmail.nossr50.util.Permissions;
 import com.gmail.nossr50.util.Users;
 import com.gmail.nossr50.util.Users;
 
 
 public class MmoeditCommand implements CommandExecutor {
 public class MmoeditCommand implements CommandExecutor {
@@ -20,109 +20,95 @@ public class MmoeditCommand implements CommandExecutor {
         PlayerProfile profile;
         PlayerProfile profile;
         int newValue;
         int newValue;
         SkillType skill;
         SkillType skill;
-        String skillName;
-        String usage = LocaleLoader.getString("Commands.Usage.3", "mmoedit", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">", "<" + LocaleLoader.getString("Commands.Usage.Level") + ">");
 
 
         switch (args.length) {
         switch (args.length) {
         case 2:
         case 2:
-            if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit")) {
-                return true;
+            if (!(sender instanceof Player)) {
+                return false;
             }
             }
 
 
-            if (sender instanceof Player) {
-                if (!SkillTools.isSkill(args[0])) {
-                    sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
-                    return true;
-                }
+            if (!SkillTools.isSkill(args[0])) {
+                sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
+                return true;
+            }
 
 
-                if (Misc.isInt(args[1])) {
-                    Player player = (Player) sender;
-                    newValue = Integer.valueOf(args[1]);
-                    skill = SkillTools.getSkillType(args[0]);
-                    profile = Users.getProfile(player);
+            if (!Misc.isInt(args[1])) {
+                return false;
+            }
 
 
-                    if (skill.equals(SkillType.ALL)) {
-                        sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
-                    }
-                    else {
-                        sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(skill.toString()), newValue));
-                    }
+            newValue = Integer.valueOf(args[1]);
+            skill = SkillTools.getSkillType(args[0]);
+            profile = Users.getPlayer((Player) sender).getProfile();
 
 
-                    profile.modifySkill(skill, newValue);
-                }
-                else {
-                    sender.sendMessage(usage);
-                }
+            if (skill == SkillType.ALL) {
+                sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
             }
             }
             else {
             else {
-                sender.sendMessage(usage);
+                sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", Misc.getCapitalized(skill.toString()), newValue));
             }
             }
 
 
+            profile.modifySkill(skill, newValue);
             return true;
             return true;
 
 
         case 3:
         case 3:
-            if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mmoedit.others")) {
+            if (Permissions.hasPermission(sender, "mcmmo.commands.mmoedit.others")) {
+                sender.sendMessage(command.getPermissionMessage());
                 return true;
                 return true;
             }
             }
 
 
-            if (!Misc.isInt(args[2])) {
-                sender.sendMessage(usage);
+            if (!SkillTools.isSkill(args[1])) {
+                sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
                 return true;
                 return true;
             }
             }
 
 
-            skill = SkillTools.getSkillType(args[1]);
-
-            if (skill == null) {
-                sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid"));
-                return true;
+            if (!Misc.isInt(args[2])) {
+                return false;
             }
             }
 
 
             newValue = Integer.valueOf(args[2]);
             newValue = Integer.valueOf(args[2]);
-            McMMOPlayer mcmmoPlayer = Users.getPlayer(args[0]);
+            skill = SkillTools.getSkillType(args[1]);
+            McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
 
 
-            if (mcmmoPlayer != null) {
-                profile = mcmmoPlayer.getProfile();
+            // 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 == null) {
+                if (!profile.isLoaded()) {
                     sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
                     sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
                     return true;
                     return true;
                 }
                 }
 
 
                 profile.modifySkill(skill, newValue);
                 profile.modifySkill(skill, newValue);
-                if (skill == SkillType.ALL) {
-                    mcmmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
-                    sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
-                }
-                else {
-                    skillName = Misc.getCapitalized(skill.toString());
-
-                    mcmmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", skillName, newValue));
-                    sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", skillName, args[0]));
-                }
+                profile.save(); // Since this is a temporary profile, we save it here.
             }
             }
             else {
             else {
-                profile = new PlayerProfile(args[0], false); //Temporary Profile
-
-                if (!profile.isLoaded()) {
-                    sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
-                    return true;
-                }
+                profile = mcMMOPlayer.getProfile();
+                Player player = mcMMOPlayer.getPlayer();
 
 
                 profile.modifySkill(skill, newValue);
                 profile.modifySkill(skill, newValue);
-                profile.save();
 
 
-                if (skill == SkillType.ALL) {
-                    sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
-                }
-                else {
-                    sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(skill.toString()), args[0]));
+                // Check if the player is online before we try to send them a message.
+                if (player.isOnline()) {
+                    if (skill == SkillType.ALL) {
+                        player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", newValue));
+                    }
+                    else {
+                        player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1",  Misc.getCapitalized(skill.toString()), newValue));
+                    }
                 }
                 }
             }
             }
+
+            if (skill == SkillType.ALL) {
+                sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", args[0]));
+            }
+            else {
+                sender.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.2", Misc.getCapitalized(skill.toString()), args[0]));
+            }
+
             return true;
             return true;
 
 
         default:
         default:
-            sender.sendMessage(usage);
-            return true;
+            return false;
         }
         }
     }
     }
 }
 }

+ 1 - 2
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.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.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;
@@ -454,7 +453,7 @@ public class mcMMO extends JavaPlugin {
         // Other commands
         // Other commands
         CommandRegistrationHelper.registerAddxpCommand();
         CommandRegistrationHelper.registerAddxpCommand();
         CommandRegistrationHelper.registerAddlevelsCommand();
         CommandRegistrationHelper.registerAddlevelsCommand();
-        getCommand("mmoedit").setExecutor(new MmoeditCommand());
+        CommandRegistrationHelper.registerMmoeditCommand();
         getCommand("inspect").setExecutor(new InspectCommand());
         getCommand("inspect").setExecutor(new InspectCommand());
         getCommand("xprate").setExecutor(new XprateCommand());
         getCommand("xprate").setExecutor(new XprateCommand());
         getCommand("mmoupdate").setExecutor(new MmoupdateCommand());
         getCommand("mmoupdate").setExecutor(new MmoupdateCommand());

+ 1 - 0
src/main/resources/locale/locale_en_US.properties

@@ -690,4 +690,5 @@ 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.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.Skill=Display detailed mcMMO skill info for {0}
 Commands.Description.Skill=Display detailed mcMMO skill info for {0}

+ 1 - 2
src/main/resources/plugin.yml

@@ -59,8 +59,7 @@ commands:
         aliases: []
         aliases: []
         description: Remove a user from the database
         description: Remove a user from the database
     mmoedit:
     mmoedit:
-        aliases: []
-        description: Edit the skill values for a user
+        description: Edit the mcMMO skill values for a user
     ptp:
     ptp:
         aliases: []
         aliases: []
         description: Teleport to a party member
         description: Teleport to a party member