From 01f38537de90565c9818591a37c45c1e1c2c4b10 Mon Sep 17 00:00:00 2001 From: Glitchfinder Date: Mon, 12 Nov 2012 21:57:57 -0800 Subject: [PATCH] Fixing cooldown timers so that they display the proper cooldown for players with perks. --- .../nossr50/skills/gathering/BlastMining.java | 2 +- .../java/com/gmail/nossr50/util/Item.java | 2 +- .../java/com/gmail/nossr50/util/Skills.java | 21 +++++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/BlastMining.java b/src/main/java/com/gmail/nossr50/skills/gathering/BlastMining.java index 36fa41306..a1760c042 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/BlastMining.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/BlastMining.java @@ -292,7 +292,7 @@ public class BlastMining { /* Check Cooldown */ if (!Skills.cooldownOver(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { - player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)"); + player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player) + "s)"); return; } diff --git a/src/main/java/com/gmail/nossr50/util/Item.java b/src/main/java/com/gmail/nossr50/util/Item.java index 1eb4aa9b9..6e421be15 100644 --- a/src/main/java/com/gmail/nossr50/util/Item.java +++ b/src/main/java/com/gmail/nossr50/util/Item.java @@ -53,7 +53,7 @@ public class Item { player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass")); } else if (!Skills.cooldownOver(profile.getRecentlyHurt(), 60, player) && amount >= Config.getInstance().getChimaeraCost()) { - player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", new Object[] {Skills.calculateTimeLeft(profile.getRecentlyHurt(), 60)})); + player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", new Object[] {Skills.calculateTimeLeft(profile.getRecentlyHurt(), 60, player)})); } else if (amount <= Config.getInstance().getChimaeraCost()) { player.sendMessage(LocaleLoader.getString("Skills.NeedMore")+ " " + ChatColor.GRAY + Misc.prettyItemString(Config.getInstance().getChimaeraItemId())); diff --git a/src/main/java/com/gmail/nossr50/util/Skills.java b/src/main/java/com/gmail/nossr50/util/Skills.java index b90ccffba..6a677c517 100644 --- a/src/main/java/com/gmail/nossr50/util/Skills.java +++ b/src/main/java/com/gmail/nossr50/util/Skills.java @@ -68,8 +68,21 @@ public class Skills { * @param cooldown The length of the cooldown * @return the number of seconds remaining before the cooldown expires */ - public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown) { - return (int) (((deactivatedTimeStamp + (cooldown * TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / TIME_CONVERSION_FACTOR); + public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown, Player player) { + int adjustedCooldown = cooldown; + + //Reduced Cooldown Donor Perks + if (player.hasPermission("mcmmo.perks.cooldowns.halved")) { + adjustedCooldown = (int) (adjustedCooldown * 0.5); + } + else if (player.hasPermission("mcmmo.perks.cooldowns.thirded")) { + adjustedCooldown = (int) (adjustedCooldown * 0.66); + } + else if (player.hasPermission("mcmmo.perks.cooldowns.quartered")) { + adjustedCooldown = (int) (adjustedCooldown * 0.75); + } + + return (int) (((deactivatedTimeStamp + (adjustedCooldown * TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / TIME_CONVERSION_FACTOR); } /** @@ -130,7 +143,7 @@ public class Skills { if (ability.getPermissions(player) && tool.inHand(inHand) && !profile.getToolPreparationMode(tool)) { if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) { if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { - player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)"); + player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player) + "s)"); return; } } @@ -417,7 +430,7 @@ public class Skills { */ if (type == SkillType.WOODCUTTING || type == SkillType.AXES) { if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) { - player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)"); + player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + calculateTimeLeft(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player) + "s)"); return; } }