浏览代码

Update /mcrefresh to use Bukkit command info. Also updated a few
description strings.

GJ 12 年之前
父节点
当前提交
958095d11b

+ 9 - 0
src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java

@@ -141,4 +141,13 @@ public final class CommandRegistrationHelper {
         command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcgod", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
         command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcgod", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
         command.setExecutor(new McgodCommand());
         command.setExecutor(new McgodCommand());
     }
     }
+
+    public static void registerMcrefreshCommand() {
+        PluginCommand command = mcMMO.p.getCommand("mcrefresh");
+        command.setDescription(LocaleLoader.getString("Commands.Description.mcrefresh"));
+        command.setPermission("mcmmo.commands.mcrefresh");
+        command.setPermissionMessage(permissionsMessage);
+        command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcrefresh", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
+        command.setExecutor(new McgodCommand());
+    }
 }
 }

+ 27 - 36
src/main/java/com/gmail/nossr50/commands/admin/McrefreshCommand.java

@@ -1,77 +1,68 @@
 package com.gmail.nossr50.commands.admin;
 package com.gmail.nossr50.commands.admin;
 
 
-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.commands.CommandHelper;
+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.util.Permissions;
 import com.gmail.nossr50.util.Users;
 import com.gmail.nossr50.util.Users;
 
 
 public class McrefreshCommand implements CommandExecutor {
 public class McrefreshCommand 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) {
-        OfflinePlayer player;
         PlayerProfile profile;
         PlayerProfile profile;
-        String usage = LocaleLoader.getString("Commands.Usage.1", "mcrefresh", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]");
-
-        if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mcrefresh")) {
-            return true;
-        }
 
 
         switch (args.length) {
         switch (args.length) {
         case 0:
         case 0:
-            if (sender instanceof Player) {
-                player = (Player) sender;
-                profile = Users.getProfile(player);
-            }
-            else {
-                sender.sendMessage(usage);
-                return true;
+            if (!(sender instanceof Player)) {
+                return false;
             }
             }
+
+            profile = Users.getPlayer(sender.getName()).getProfile();
+            sender.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
             break;
             break;
 
 
         case 1:
         case 1:
-            if (CommandHelper.noCommandPermissions(sender, "mcmmo.commands.mcrefresh.others")) {
-                return true;
+            if (!Permissions.hasPermission(sender, "mcmmo.commands.mcrefresh.others")) {
+                sender.sendMessage(command.getPermissionMessage());
             }
             }
 
 
-            player = mcMMO.p.getServer().getOfflinePlayer(args[0]);
-            profile = Users.getProfile(player);
-            String playerName = player.getName();
+            McMMOPlayer mcMMOPlayer = Users.getPlayer(args[0]);
 
 
-            if (profile == null) {
-                sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
-                return true;
-            }
+            // 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);
 
 
-            if (!profile.isLoaded()) {
-                sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
-                return true;
+                if (!profile.isLoaded()) {
+                    sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
+                    return true;
+                }
             }
             }
+            else {
+                profile = mcMMOPlayer.getProfile();
+                Player player = mcMMOPlayer.getPlayer();
 
 
-            sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", playerName));
+                // Check if the player is online before we try to send them a message.
+                if (player.isOnline()) {
+                    player.sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
+                }
+            }
 
 
+            sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", args[0]));
             break;
             break;
 
 
         default:
         default:
-            sender.sendMessage(usage);
-            return true;
+            return false;
         }
         }
 
 
         profile.setRecentlyHurt(0);
         profile.setRecentlyHurt(0);
         profile.resetCooldowns();
         profile.resetCooldowns();
         profile.resetToolPrepMode();
         profile.resetToolPrepMode();
         profile.resetAbilityMode();
         profile.resetAbilityMode();
-
-        if (player.isOnline()) {
-            ((Player) player).sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
-        }
-
         return true;
         return true;
     }
     }
 }
 }

+ 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.McrefreshCommand;
 import com.gmail.nossr50.commands.admin.MmoeditCommand;
 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;
@@ -441,7 +440,7 @@ public class mcMMO extends JavaPlugin {
         getCommand("mcc").setExecutor(new MccCommand());
         getCommand("mcc").setExecutor(new MccCommand());
         CommandRegistrationHelper.registerMcgodCommand();
         CommandRegistrationHelper.registerMcgodCommand();
         getCommand("mcmmo").setExecutor(new McmmoCommand());
         getCommand("mcmmo").setExecutor(new McmmoCommand());
-        getCommand("mcrefresh").setExecutor(new McrefreshCommand());
+        CommandRegistrationHelper.registerMcrefreshCommand();
         getCommand("mctop").setExecutor(new MctopCommand());
         getCommand("mctop").setExecutor(new MctopCommand());
         getCommand("mcrank").setExecutor(new McrankCommand());
         getCommand("mcrank").setExecutor(new McrankCommand());
         getCommand("mcstats").setExecutor(new McstatsCommand());
         getCommand("mcstats").setExecutor(new McstatsCommand());

+ 3 - 2
src/main/resources/locale/locale_en_US.properties

@@ -688,5 +688,6 @@ Smelting.SkillName=SMELTING
 #COMMAND DESCRIPTIONS
 #COMMAND DESCRIPTIONS
 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.mcgod=Toggles mcMMO god-mode on/off
-Commands.Description.Skill=Detailed mcMMO skill info for {0}
+Commands.Description.mcgod=Toggle mcMMO god-mode on/off
+Commands.Description.mcrefresh=Refresh all cooldowns for mcMMO
+Commands.Description.Skill=Display detailed mcMMO skill info for {0}

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

@@ -49,10 +49,9 @@ commands:
         aliases: []
         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:
-        aliases: []
         description: Refresh all cooldowns for mcMMO
         description: Refresh all cooldowns for mcMMO
     mcgod:
     mcgod:
-        description: Toggles mcMMO god-mode on/off
+        description: Toggle mcMMO god-mode on/off
     mcstats:
     mcstats:
         aliases: [/stats]
         aliases: [/stats]
         description: Shows your mcMMO stats and xp
         description: Shows your mcMMO stats and xp