Made /mcrefresh work for offline users & from console.

This commit is contained in:
GJ 2012-04-19 17:21:55 -04:00
parent 6991fa4907
commit 2f66c93bfd
3 changed files with 73 additions and 48 deletions

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.commands.mc; package com.gmail.nossr50.commands.mc;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
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;
@ -8,61 +9,67 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.ToolType;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
public class McrefreshCommand implements CommandExecutor { public class McrefreshCommand implements CommandExecutor {
private final mcMMO plugin; private final mcMMO plugin;
public McrefreshCommand(mcMMO instance) { public McrefreshCommand(mcMMO instance) {
this.plugin = instance; this.plugin = instance;
} }
@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 PP;
String usage = ChatColor.RED + "Proper usage is /mcrefresh [playername]"; //TODO: Needs more locale
if (!(sender instanceof Player)) { if (CommandHelper.noCommandPermissions(sender, "mcmmo.tools.mcrefresh")) {
sender.sendMessage("This command does not support console useage."); //TODO: Needs more locale. return true;
return true; }
}
Player player = (Player) sender; switch (args.length) {
PlayerProfile PP = Users.getProfile(player); 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)) { case 1:
player.sendMessage(ChatColor.YELLOW + "[mcMMO] " + ChatColor.DARK_RED + mcLocale.getString("mcPlayerListener.NoPermission")); player = plugin.getServer().getOfflinePlayer(args[0]);
return true; PP = Users.getProfile(player);
} String playerName = player.getName();
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]);
}
/* if (!PP.isLoaded()) {
* PREP MODES sender.sendMessage(mcLocale.getString("Commands.DoesNotExist"));
*/ return true;
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);
//RESET COOLDOWNS sender.sendMessage("You have refreshed " + playerName + "'s cooldowns!"); //TODO: Use locale
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);
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;
}
} }

View File

@ -648,6 +648,15 @@ public class PlayerProfile {
* Tools * 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. * Get the current prep mode of a tool.
* *
@ -741,6 +750,15 @@ public class PlayerProfile {
* Abilities * 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. * Get the mode of an ability.
* *

View File

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