Create a utility method in SkillUtils to easily check ability cooldowns

This commit is contained in:
riking 2013-10-19 15:59:58 -07:00
parent 95f15e68fe
commit c6ca65f5c9
5 changed files with 22 additions and 8 deletions

View File

@ -854,7 +854,7 @@ public class McMMOPlayer {
return; return;
} }
int timeRemaining = SkillUtils.calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player); int timeRemaining = SkillUtils.calculateTimeLeft(ability, profile, player);
if (timeRemaining > 0) { if (timeRemaining > 0) {
/* /*
@ -924,7 +924,7 @@ public class McMMOPlayer {
*/ */
if (ability.getPermissions(player) && tool.inHand(inHand) && !getToolPreparationMode(tool)) { if (ability.getPermissions(player) && tool.inHand(inHand) && !getToolPreparationMode(tool)) {
if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) { if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) {
int timeRemaining = SkillUtils.calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player); int timeRemaining = SkillUtils.calculateTimeLeft(ability, profile, player);
if (!getAbilityMode(ability) && timeRemaining > 0) { if (!getAbilityMode(ability) && timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining)); player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));

View File

@ -44,6 +44,6 @@ public class ScoreboardsListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onAbility(McMMOPlayerAbilityActivateEvent e) { public void onAbility(McMMOPlayerAbilityActivateEvent e) {
ScoreboardManager.cooldownUpdate(e.getPlayer(), e.getSkill(), SkillUtils.calculateTimeLeft(UserManager.getPlayer(e.getPlayer()).getProfile().getSkillDATS(e.getAbility()) * Misc.TIME_CONVERSION_FACTOR, e.getAbility().getCooldown(), e.getPlayer())); ScoreboardManager.cooldownUpdate(e.getPlayer(), e.getSkill(), SkillUtils.calculateTimeLeft(e.getAbility(), UserManager.getPlayer(e.getPlayer()).getProfile(), e.getPlayer()));
} }
} }

View File

@ -288,7 +288,7 @@ public class MiningManager extends SkillManager {
private boolean blastMiningCooldownOver() { private boolean blastMiningCooldownOver() {
Player player = getPlayer(); Player player = getPlayer();
PlayerProfile profile = getProfile(); PlayerProfile profile = getProfile();
int timeRemaining = SkillUtils.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player); int timeRemaining = SkillUtils.calculateTimeLeft(AbilityType.BLAST_MINING, profile, player);
if (timeRemaining > 0) { if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining)); player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));

View File

@ -415,7 +415,7 @@ public class ScoreboardWrapper {
if (targetSkill != SkillType.MINING) { if (targetSkill != SkillType.MINING) {
AbilityType ab = targetSkill.getAbility(); AbilityType ab = targetSkill.getAbility();
Score cooldown = sidebarObj.getScore(ScoreboardManager.abilityLabelsSkill.get(ab)); Score cooldown = sidebarObj.getScore(ScoreboardManager.abilityLabelsSkill.get(ab));
int seconds = SkillUtils.calculateTimeLeft(profile.getSkillDATS(ab) * Misc.TIME_CONVERSION_FACTOR, ab.getCooldown(), bukkitPlayer); int seconds = SkillUtils.calculateTimeLeft(ab, profile, bukkitPlayer);
seconds = (seconds <= 0) ? 0 : seconds; seconds = (seconds <= 0) ? 0 : seconds;
if (seconds == 0) { if (seconds == 0) {
cooldown.setScore(0); cooldown.setScore(0);
@ -431,8 +431,8 @@ public class ScoreboardWrapper {
AbilityType bm = AbilityType.BLAST_MINING; AbilityType bm = AbilityType.BLAST_MINING;
Score cooldownSB = sidebarObj.getScore(ScoreboardManager.abilityLabelsSkill.get(sb)); Score cooldownSB = sidebarObj.getScore(ScoreboardManager.abilityLabelsSkill.get(sb));
Score cooldownBM = sidebarObj.getScore(ScoreboardManager.abilityLabelsSkill.get(bm)); Score cooldownBM = sidebarObj.getScore(ScoreboardManager.abilityLabelsSkill.get(bm));
int secondsSB = SkillUtils.calculateTimeLeft(profile.getSkillDATS(sb) * Misc.TIME_CONVERSION_FACTOR, sb.getCooldown(), bukkitPlayer); int secondsSB = SkillUtils.calculateTimeLeft(sb, profile, bukkitPlayer);
int secondsBM = SkillUtils.calculateTimeLeft(profile.getSkillDATS(bm) * Misc.TIME_CONVERSION_FACTOR, bm.getCooldown(), bukkitPlayer); int secondsBM = SkillUtils.calculateTimeLeft(bm, profile, bukkitPlayer);
secondsSB = (secondsSB <= 0) ? 0 : secondsSB; secondsSB = (secondsSB <= 0) ? 0 : secondsSB;
secondsBM = (secondsBM <= 0) ? 0 : secondsBM; secondsBM = (secondsBM <= 0) ? 0 : secondsBM;
if (secondsSB == 0 && secondsBM == 0) { if (secondsSB == 0 && secondsBM == 0) {
@ -452,7 +452,7 @@ public class ScoreboardWrapper {
case COOLDOWNS_BOARD: case COOLDOWNS_BOARD:
boolean anyCooldownsActive = false; boolean anyCooldownsActive = false;
for (AbilityType ability : AbilityType.NORMAL_ABILITIES) { for (AbilityType ability : AbilityType.NORMAL_ABILITIES) {
int seconds = SkillUtils.calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), bukkitPlayer); int seconds = SkillUtils.calculateTimeLeft(ability, profile, bukkitPlayer);
seconds = (seconds <= 0) ? 0 : seconds; seconds = (seconds <= 0) ? 0 : seconds;
if (seconds != 0) { if (seconds != 0) {
anyCooldownsActive = true; anyCooldownsActive = true;

View File

@ -16,6 +16,7 @@ import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
@ -53,6 +54,19 @@ public class SkillUtils {
return (int) (((deactivatedTimeStamp + (PerksUtils.handleCooldownPerks(player, cooldown) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR); return (int) (((deactivatedTimeStamp + (PerksUtils.handleCooldownPerks(player, cooldown) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
} }
/**
* Calculate the time remaining until the ability's cooldown expires.
*
* @param ability AbilityType whose cooldown to check
* @param profile The PlayerProfile to get the cooldown from
* @param player The Player to check for cooldown perks
*
* @return the number of seconds remaining before the cooldown expires
*/
public static int calculateTimeLeft(AbilityType ability, PlayerProfile profile, Player player) {
return calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player);
}
/** /**
* Check if the cooldown has expired. * Check if the cooldown has expired.
* This does NOT account for cooldown perks! * This does NOT account for cooldown perks!