Prechádzať zdrojové kódy

Made /mcrefresh work for offline users & from console.

GJ 13 rokov pred
rodič
commit
2f66c93bfd

+ 51 - 44
src/main/java/com/gmail/nossr50/commands/mc/McrefreshCommand.java

@@ -1,6 +1,7 @@
 package com.gmail.nossr50.commands.mc;
 
 import org.bukkit.ChatColor;
+import org.bukkit.OfflinePlayer;
 import org.bukkit.command.Command;
 import org.bukkit.command.CommandExecutor;
 import org.bukkit.command.CommandSender;
@@ -8,61 +9,67 @@ import org.bukkit.entity.Player;
 
 import com.gmail.nossr50.Users;
 import com.gmail.nossr50.mcMMO;
-import com.gmail.nossr50.mcPermissions;
-import com.gmail.nossr50.datatypes.AbilityType;
+import com.gmail.nossr50.commands.CommandHelper;
 import com.gmail.nossr50.datatypes.PlayerProfile;
-import com.gmail.nossr50.datatypes.ToolType;
 import com.gmail.nossr50.locale.mcLocale;
 
 public class McrefreshCommand implements CommandExecutor {
-	private final mcMMO plugin;
+    private final mcMMO plugin;
 
-	public McrefreshCommand(mcMMO instance) {
-		this.plugin = instance;
-	}
+    public McrefreshCommand(mcMMO instance) {
+        this.plugin = instance;
+    }
 
-	@Override
-	public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+    @Override
+    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+        OfflinePlayer player;
+        PlayerProfile PP;
+        String usage = ChatColor.RED + "Proper usage is /mcrefresh [playername]"; //TODO: Needs more locale
 
-		if (!(sender instanceof Player)) {
-			sender.sendMessage("This command does not support console useage."); //TODO: Needs more locale.
-			return true;
-		}
+        if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mcrefresh")) {
+            return true;
+        }
 
-		Player player = (Player) sender;
-		PlayerProfile PP = Users.getProfile(player);
+        switch (args.length) {
+        case 0:
+            if (sender instanceof Player) {
+                player = (Player) sender;
+                PP = Users.getProfile(player);
+            }
+            else {
+                sender.sendMessage(usage);
+                return true;
+            }
+            break;
 
-		if (!mcPermissions.getInstance().mcrefresh(player)) {
-			player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission"));
-			return true;
-		}
-		if (args.length >= 1 && (plugin.getServer().getPlayer(args[0]) != null)) {
-			player.sendMessage("You have refreshed " + args[0] + "'s cooldowns!"); //TODO: Needs more locale.
-			player = plugin.getServer().getPlayer(args[0]);
-		}
+        case 1:
+            player = plugin.getServer().getOfflinePlayer(args[0]);
+            PP = Users.getProfile(player);
+            String playerName = player.getName();
 
-		/*
-		 * PREP MODES
-		 */
-		PP = Users.getProfile(player);
-		PP.setRecentlyHurt((long) 0);
-		PP.setToolPreparationMode(ToolType.AXE, false);
-		PP.setToolPreparationMode(ToolType.FISTS, false);
-		PP.setToolPreparationMode(ToolType.HOE, false);
-		PP.setToolPreparationMode(ToolType.PICKAXE, false);
-		PP.setToolPreparationMode(ToolType.SWORD, false);
+            if (!PP.isLoaded()) {
+                sender.sendMessage(mcLocale.getString("Commands.DoesNotExist"));
+                return true;
+            }
 
-		//RESET COOLDOWNS
-		PP.resetCooldowns();
-		PP.setAbilityMode(AbilityType.GREEN_TERRA, false);
-		PP.setAbilityMode(AbilityType.GIGA_DRILL_BREAKER, false);
-		PP.setAbilityMode(AbilityType.SERRATED_STRIKES, false);
-		PP.setAbilityMode(AbilityType.SUPER_BREAKER, false);
-		PP.setAbilityMode(AbilityType.TREE_FELLER, false);
-		PP.setAbilityMode(AbilityType.BERSERK, false);
+            sender.sendMessage("You have refreshed " + playerName + "'s cooldowns!"); //TODO: Use locale
 
-		player.sendMessage(mcLocale.getString("mcPlayerListener.AbilitiesRefreshed"));
+            break;
 
-		return true;
-	}
+        default:
+            sender.sendMessage(usage);
+            return true;
+        }
+
+        PP.setRecentlyHurt((long) 0);
+        PP.resetCooldowns();
+        PP.resetToolPrepMode();
+        PP.resetAbilityMode();
+
+        if (player.isOnline()) {
+            ((Player) player).sendMessage(mcLocale.getString("Ability.Generic.Refresh"));
+        }
+
+        return true;
+    }
 }

+ 18 - 0
src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java

@@ -648,6 +648,15 @@ public class PlayerProfile {
      * Tools
      */
 
+    /**
+     * Reset the prep modes of all tools.
+     */
+    public void resetToolPrepMode() {
+        for (ToolType tool : ToolType.values()) {
+            setToolPreparationMode(tool, false);
+        }
+    }
+
     /**
      * Get the current prep mode of a tool.
      *
@@ -741,6 +750,15 @@ public class PlayerProfile {
      * Abilities
      */
 
+    /**
+     * Reset the prep modes of all tools.
+     */
+    public void resetAbilityMode() {
+        for (AbilityType ability : AbilityType.values()) {
+            setAbilityMode(ability, false);
+        }
+    }
+
     /**
      * Get the mode of an ability.
      *

+ 4 - 4
src/main/resources/locale/locale_en_us.properties

@@ -24,7 +24,7 @@ Acrobatics.Effect.1=Reduces or Negates fall damage
 Acrobatics.Effect.2=Graceful Roll
 Acrobatics.Effect.3=Twice as effective as a normal Roll
 Acrobatics.Effect.4=Dodge
-Acrobatics.Effect.5=Reduce fall damage by half
+Acrobatics.Effect.5=Reduce attack damage by half
 Acrobatics.Listener=Acrobatics: 
 Acrobatics.Roll.Chance=[[RED]]Roll Chance: [[YELLOW]]{0}%
 Acrobatics.Roll.GraceChance=[[RED]]Graceful Roll Chance: [[YELLOW]]{0}%
@@ -384,7 +384,7 @@ Commands.Invite.Accepted=[[GREEN]]Invite Accepted. You have joined party {0}
 Commands.Invite.Success=[[GREEN]]Invite sent successfully.
 Commands.Leaderboards=<skillname> <page> [[RED]]- Leaderboards
 Commands.mcgod=[[RED]]- Toggle GodMode
-Commands.mmoedit=<player> <skill> <newvalue> [[RED]] - Modify target
+Commands.mmoedit=[playername] <skill> <newvalue> [[RED]] - Modify target
 Commands.ModDescription=[[RED]]- Read brief mod description
 Commands.NoConsole=This command does not support console usage.
 Commands.Other=[[GREEN]]--OTHER COMMANDS--
@@ -394,13 +394,13 @@ Commands.Party.Chat.On=Party Chat only [[GREEN]]On
 Commands.Party.Commands=[[GREEN]]--PARTY COMMANDS--
 Commands.Party.Invite.0=[[RED]]ALERT: [[GREEN]]You have received a party invite for {0} from {1}
 Commands.Party.Invite.1=[[YELLOW]]Type [[GREEN]]/{0}[[YELLOW]] to accept the invite 
-Commands.Party.Invite=<player> [[RED]]- Send party invite
+Commands.Party.Invite=<playername> [[RED]]- Send party invite
 Commands.Party.Join=Joined Party: {0}
 Commands.Party.Leave=[[RED]]You have left that party
 Commands.Party.Members=[[GREEN]]Party Members
 Commands.Party.None=[[RED]]You are not in a party.
 Commands.Party.Quit=[[RED]]- Leave your current party
-Commands.Party.Teleport=<player> [[RED]]- Teleport to party member
+Commands.Party.Teleport=<playername> [[RED]]- Teleport to party member
 Commands.Party.Toggle=[[RED]]- Toggle Party Chat
 Commands.Party=<party name> [[RED]]- Create/Join designated party
 Commands.PowerLevel.Leaderboard=[[YELLOW]]--mcMMO[[BLUE]] Power Level [[YELLOW]]Leaderboard--