Don't run these calculations twice. Also, pretty sure one of these was

bugged.
This commit is contained in:
GJ 2013-05-21 11:41:39 -04:00
parent 4f8b66f94d
commit 0b6372a6ea
6 changed files with 82 additions and 63 deletions

View File

@ -55,12 +55,16 @@ public class PtpCommand implements TabExecutor {
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
long recentlyHurt = mcMMOPlayer.getRecentlyHurt(); long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
int recentlyhurt_cooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown(); int hurtCooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown();
if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)) { if (hurtCooldown > 0) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player))); int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
return true; return true;
} }
}
if (args[0].equalsIgnoreCase("accept")) { if (args[0].equalsIgnoreCase("accept")) {
return ptpAcceptCommand.onCommand(sender, command, label, args); return ptpAcceptCommand.onCommand(sender, command, label, args);
@ -74,10 +78,14 @@ public class PtpCommand implements TabExecutor {
int ptpCooldown = Config.getInstance().getPTPCommandCooldown(); int ptpCooldown = Config.getInstance().getPTPCommandCooldown();
long lastTeleport = mcMMOPlayer.getLastTeleport(); long lastTeleport = mcMMOPlayer.getLastTeleport();
if (!SkillUtils.cooldownOver(lastTeleport * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player)) { if (ptpCooldown > 0) {
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player))); int timeRemaining = SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player);
if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", timeRemaining));
return true; return true;
} }
}
sendTeleportRequest(sender, player, args[0]); sendTeleportRequest(sender, player, args[0]);
return true; return true;

View File

@ -28,8 +28,6 @@ public class ChimaeraWingWarmup extends BukkitRunnable {
private void checkChimaeraWingTeleport() { private void checkChimaeraWingTeleport() {
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
Location previousLocation = mcMMOPlayer.getTeleportCommenceLocation(); Location previousLocation = mcMMOPlayer.getTeleportCommenceLocation();
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
ItemStack inHand = player.getItemInHand();
mcMMOPlayer.setTeleportCommenceLocation(null); mcMMOPlayer.setTeleportCommenceLocation(null);
@ -38,17 +36,24 @@ public class ChimaeraWingWarmup extends BukkitRunnable {
return; return;
} }
ItemStack inHand = player.getItemInHand();
if (!ItemUtils.isChimaeraWing(inHand) || inHand.getAmount() < Config.getInstance().getChimaeraUseCost()) { if (!ItemUtils.isChimaeraWing(inHand) || inHand.getAmount() < Config.getInstance().getChimaeraUseCost()) {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", LocaleLoader.getString("Item.ChimaeraWing.Name"))); player.sendMessage(LocaleLoader.getString("Skills.NeedMore", LocaleLoader.getString("Item.ChimaeraWing.Name")));
return; return;
} }
int recentlyhurt_cooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown(); long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
int hurtCooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown();
if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)) { if (hurtCooldown > 0) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player))); int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
return; return;
} }
}
ChimaeraWing.chimaeraExecuteTeleport(); ChimaeraWing.chimaeraExecuteTeleport();
} }

View File

@ -47,12 +47,16 @@ public class TeleportationWarmup extends BukkitRunnable {
return; return;
} }
int recentlyhurt_cooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown(); int hurtCooldown = Config.getInstance().getPTPCommandRecentlyHurtCooldown();
if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, teleportingPlayer)) { if (hurtCooldown > 0) {
teleportingPlayer.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, teleportingPlayer))); int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, teleportingPlayer);
if (timeRemaining > 0) {
teleportingPlayer.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
return; return;
} }
}
PtpCommand.handlePartyTeleportEvent(teleportingPlayer, targetPlayer); PtpCommand.handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
} }

View File

@ -287,9 +287,10 @@ public class MiningManager extends SkillManager {
long oldTime = profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR; long oldTime = profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR;
int cooldown = AbilityType.BLAST_MINING.getCooldown(); int cooldown = AbilityType.BLAST_MINING.getCooldown();
int timeRemaining = SkillUtils.calculateTimeLeft(oldTime, cooldown, player);
if (!SkillUtils.cooldownOver(oldTime, cooldown, player)) { if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", SkillUtils.calculateTimeLeft(oldTime, cooldown, player))); player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
return false; return false;
} }

View File

@ -35,9 +35,13 @@ public final class ChimaeraWing {
* @param player Player whose item usage to check * @param player Player whose item usage to check
*/ */
public static void activationCheck(Player player) { public static void activationCheck(Player player) {
if (!Config.getInstance().getChimaeraEnabled()) {
return;
}
ItemStack inHand = player.getItemInHand(); ItemStack inHand = player.getItemInHand();
if (!Config.getInstance().getChimaeraEnabled() || !ItemUtils.isChimaeraWing(inHand)) { if (!ItemUtils.isChimaeraWing(inHand)) {
return; return;
} }
@ -48,32 +52,43 @@ public final class ChimaeraWing {
mcMMOPlayer = UserManager.getPlayer(player); mcMMOPlayer = UserManager.getPlayer(player);
location = player.getLocation();
int amount = inHand.getAmount();
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
long lastTeleport = mcMMOPlayer.getLastTeleport();
if (mcMMOPlayer.getTeleportCommenceLocation() != null) { if (mcMMOPlayer.getTeleportCommenceLocation() != null) {
return; return;
} }
if (Config.getInstance().getChimaeraCooldown() > 0 && !SkillUtils.cooldownOver(lastTeleport * Misc.TIME_CONVERSION_FACTOR, Config.getInstance().getChimaeraCooldown(), player)) { int amount = inHand.getAmount();
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, Config.getInstance().getChimaeraCooldown(), player)));
return;
}
int recentlyhurt_cooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown();
if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, recentlyhurt_cooldown, player)));
return;
}
if (amount < Config.getInstance().getChimaeraUseCost()) { if (amount < Config.getInstance().getChimaeraUseCost()) {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", LocaleLoader.getString("Item.ChimaeraWing.Name"))); player.sendMessage(LocaleLoader.getString("Skills.NeedMore", LocaleLoader.getString("Item.ChimaeraWing.Name")));
return; return;
} }
long lastTeleport = mcMMOPlayer.getLastTeleport();
int cooldown = Config.getInstance().getChimaeraCooldown();
if (cooldown > 0 ) {
int timeRemaining = SkillUtils.calculateTimeLeft(lastTeleport * Misc.TIME_CONVERSION_FACTOR, cooldown, player);
if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", timeRemaining));
return;
}
}
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
int hurtCooldown = Config.getInstance().getChimaeraRecentlyHurtCooldown();
if (hurtCooldown > 0) {
int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
return;
}
}
location = player.getLocation();
if (Config.getInstance().getChimaeraPreventUseUnderground()) { if (Config.getInstance().getChimaeraPreventUseUnderground()) {
if (location.getY() < player.getWorld().getHighestBlockYAt(location)) { if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost()))); player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));

View File

@ -55,25 +55,6 @@ public class SkillUtils {
return currentFoodLevel + foodChange; return currentFoodLevel + foodChange;
} }
/**
* Checks to see if the cooldown for an item or ability is expired.
*
* @param oldTime The time the ability or item was last used
* @param cooldown The amount of time that must pass between uses
* @param player The player whose cooldown is being checked
* @return true if the cooldown is over, false otherwise
*/
public static boolean cooldownOver(long oldTime, int cooldown, Player player) {
long currentTime = System.currentTimeMillis();
int adjustedCooldown = PerksUtils.handleCooldownPerks(player, cooldown);
if (currentTime - oldTime >= (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) {
return true;
}
return false;
}
/** /**
* Calculate the time remaining until the cooldown expires. * Calculate the time remaining until the cooldown expires.
* *
@ -96,15 +77,14 @@ public class SkillUtils {
return; return;
} }
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
AbilityType ability = skill.getAbility();
ToolType tool = skill.getTool();
ItemStack inHand = player.getItemInHand(); ItemStack inHand = player.getItemInHand();
if (ModUtils.isCustomTool(inHand) && !ModUtils.getToolFromItemStack(inHand).isAbilityEnabled()) { if (ModUtils.isCustomTool(inHand) && !ModUtils.getToolFromItemStack(inHand).isAbilityEnabled()) {
return; return;
} }
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.getAbilityUse()) { if (!mcMMOPlayer.getAbilityUse()) {
return; return;
} }
@ -116,6 +96,8 @@ public class SkillUtils {
} }
PlayerProfile playerProfile = mcMMOPlayer.getProfile(); PlayerProfile playerProfile = mcMMOPlayer.getProfile();
AbilityType ability = skill.getAbility();
ToolType tool = skill.getTool();
/* /*
* Woodcutting & Axes need to be treated differently. * Woodcutting & Axes need to be treated differently.
@ -123,8 +105,10 @@ public class SkillUtils {
*/ */
if (ability.getPermissions(player) && tool.inHand(inHand) && !mcMMOPlayer.getToolPreparationMode(tool)) { if (ability.getPermissions(player) && tool.inHand(inHand) && !mcMMOPlayer.getToolPreparationMode(tool)) {
if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) { if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) {
if (!mcMMOPlayer.getAbilityMode(ability) && !cooldownOver(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { int timeRemaining = calculateTimeLeft(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player);
player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)));
if (!mcMMOPlayer.getAbilityMode(ability) && timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
return; return;
} }
} }
@ -294,18 +278,20 @@ public class SkillUtils {
Player player = mcMMOPlayer.getPlayer(); Player player = mcMMOPlayer.getPlayer();
PlayerProfile playerProfile = mcMMOPlayer.getProfile(); PlayerProfile playerProfile = mcMMOPlayer.getProfile();
int timeRemaining = calculateTimeLeft(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player);
/* /*
* Axes and Woodcutting are odd because they share the same tool. * Axes and Woodcutting are odd because they share the same tool.
* We show them the too tired message when they take action. * We show them the too tired message when they take action.
*/ */
if (type == SkillType.WOODCUTTING || type == SkillType.AXES) { if (type == SkillType.WOODCUTTING || type == SkillType.AXES) {
if (!mcMMOPlayer.getAbilityMode(ability) && !cooldownOver(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { if (!mcMMOPlayer.getAbilityMode(ability) && timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", calculateTimeLeft(playerProfile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player))); player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
return; return;
} }
} }
if (!mcMMOPlayer.getAbilityMode(ability) && cooldownOver(playerProfile.getSkillDATS(ability), ability.getCooldown(), player)) { if (!mcMMOPlayer.getAbilityMode(ability) && timeRemaining <= 0) {
McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, type); McMMOPlayerAbilityActivateEvent event = new McMMOPlayerAbilityActivateEvent(player, type);
mcMMO.p.getServer().getPluginManager().callEvent(event); mcMMO.p.getServer().getPluginManager().callEvent(event);