mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Use proper functions where they exist, and move functions to better locations.
This commit is contained in:
parent
8369ae4616
commit
c79f8043ad
@ -8,13 +8,12 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class MccooldownCommand implements TabExecutor {
|
||||
@ -36,7 +35,7 @@ public class MccooldownCommand implements TabExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
PlayerProfile profile = UserManager.getPlayer(player).getProfile();
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Header"));
|
||||
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
|
||||
@ -46,7 +45,7 @@ public class MccooldownCommand implements TabExecutor {
|
||||
continue;
|
||||
}
|
||||
|
||||
int seconds = SkillUtils.calculateTimeLeft(ability, profile, player);
|
||||
int seconds = mcMMOPlayer.calculateTimeRemaining(ability);
|
||||
|
||||
if (seconds <= 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Row.Y", ability.getName()));
|
||||
|
@ -854,7 +854,7 @@ public class McMMOPlayer {
|
||||
return;
|
||||
}
|
||||
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(ability, profile, player);
|
||||
int timeRemaining = calculateTimeRemaining(ability);
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
/*
|
||||
@ -924,7 +924,7 @@ public class McMMOPlayer {
|
||||
*/
|
||||
if (ability.getPermissions(player) && tool.inHand(inHand) && !getToolPreparationMode(tool)) {
|
||||
if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) {
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(ability, profile, player);
|
||||
int timeRemaining = calculateTimeRemaining(ability);
|
||||
|
||||
if (!getAbilityMode(ability) && timeRemaining > 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
|
||||
@ -941,4 +941,16 @@ public class McMMOPlayer {
|
||||
new ToolLowerTask(this, tool).runTaskLaterAsynchronously(mcMMO.p, 4 * Misc.TICK_CONVERSION_FACTOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the time remaining until the ability's cooldown expires.
|
||||
*
|
||||
* @param ability AbilityType whose cooldown to check
|
||||
*
|
||||
* @return the number of seconds remaining before the cooldown expires
|
||||
*/
|
||||
public int calculateTimeRemaining(AbilityType ability) {
|
||||
long deactivatedTimestamp = profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR;
|
||||
return (int) (((deactivatedTimestamp + (PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ public class PlayerProfile {
|
||||
* Xp Functions
|
||||
*/
|
||||
|
||||
public int getSkillLevel(SkillType skillType) {
|
||||
protected int getSkillLevel(SkillType skillType) {
|
||||
return skillType.isChildSkill() ? getChildSkillLevel(skillType) : skills.get(skillType);
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class AxesManager extends SkillManager {
|
||||
short maxDurability = mcMMO.getRepairableManager().isRepairable(armorType) ? mcMMO.getRepairableManager().getRepairable(armorType).getMaximumDurability() : armorType.getMaxDurability();
|
||||
double maxDurabilityDamage = maxDurability * Axes.impactMaxDurabilityModifier;
|
||||
|
||||
armor.setDurability((short) (Math.min(modifiedDurabilityDamage, maxDurabilityDamage) + armor.getDurability()));
|
||||
SkillUtils.handleDurabilityChange(armor, (int) Math.min(modifiedDurabilityDamage, maxDurabilityDamage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -472,7 +472,6 @@ public class FishingManager extends SkillManager {
|
||||
}
|
||||
|
||||
ItemStack treasureDrop = treasure.getDrop();
|
||||
|
||||
short maxDurability = treasureDrop.getType().getMaxDurability();
|
||||
|
||||
if (maxDurability > 0) {
|
||||
|
@ -14,7 +14,6 @@ import org.bukkit.metadata.FixedMetadataValue;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
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.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -286,12 +285,10 @@ public class MiningManager extends SkillManager {
|
||||
}
|
||||
|
||||
private boolean blastMiningCooldownOver() {
|
||||
Player player = getPlayer();
|
||||
PlayerProfile profile = getProfile();
|
||||
int timeRemaining = SkillUtils.calculateTimeLeft(AbilityType.BLAST_MINING, profile, player);
|
||||
int timeRemaining = mcMMOPlayer.calculateTimeRemaining(AbilityType.BLAST_MINING);
|
||||
|
||||
if (timeRemaining > 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
|
||||
getPlayer().sendMessage(LocaleLoader.getString("Skills.TooTired", timeRemaining));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.ModUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
|
||||
public final class Woodcutting {
|
||||
public static int doubleDropsMaxLevel = AdvancedConfig.getInstance().getWoodcuttingDoubleDropMaxLevel();
|
||||
@ -227,12 +228,8 @@ public final class Woodcutting {
|
||||
}
|
||||
}
|
||||
|
||||
short finalDurability = (short) (inHand.getDurability() + durabilityLoss);
|
||||
short maxDurability = inHandMaterial.getMaxDurability();
|
||||
boolean overMax = (finalDurability >= maxDurability);
|
||||
|
||||
inHand.setDurability(overMax ? maxDurability : finalDurability);
|
||||
return !overMax;
|
||||
SkillUtils.handleDurabilityChange(inHand, durabilityLoss);
|
||||
return (inHand.getDurability() < inHandMaterial.getMaxDurability());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,6 @@ import com.gmail.nossr50.skills.child.FamilyTree;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
|
||||
public class ScoreboardWrapper {
|
||||
|
||||
@ -427,8 +426,8 @@ public class ScoreboardWrapper {
|
||||
// Special-Case: Mining has two abilities, both with cooldowns
|
||||
Score cooldownSB = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(AbilityType.SUPER_BREAKER));
|
||||
Score cooldownBM = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(AbilityType.BLAST_MINING));
|
||||
int secondsSB = Math.max(SkillUtils.calculateTimeLeft(AbilityType.SUPER_BREAKER, profile, player), 0);
|
||||
int secondsBM = Math.max(SkillUtils.calculateTimeLeft(AbilityType.BLAST_MINING, profile, player), 0);
|
||||
int secondsSB = Math.max(mcMMOPlayer.calculateTimeRemaining(AbilityType.SUPER_BREAKER), 0);
|
||||
int secondsBM = Math.max(mcMMOPlayer.calculateTimeRemaining(AbilityType.BLAST_MINING), 0);
|
||||
|
||||
cooldownSB.setScore(secondsSB);
|
||||
cooldownBM.setScore(secondsBM);
|
||||
@ -438,7 +437,7 @@ public class ScoreboardWrapper {
|
||||
else {
|
||||
AbilityType ability = targetSkill.getAbility();
|
||||
Score cooldown = sidebarObjective.getScore(ScoreboardManager.abilityLabelsSkill.get(ability));
|
||||
int seconds = Math.max(SkillUtils.calculateTimeLeft(ability, profile, player), 0);
|
||||
int seconds = Math.max(mcMMOPlayer.calculateTimeRemaining(ability), 0);
|
||||
|
||||
cooldown.setScore(seconds);
|
||||
|
||||
@ -458,7 +457,7 @@ public class ScoreboardWrapper {
|
||||
boolean anyCooldownsActive = false;
|
||||
|
||||
for (AbilityType ability : AbilityType.NORMAL_ABILITIES) {
|
||||
int seconds = Math.max(SkillUtils.calculateTimeLeft(ability, profile, player), 0);
|
||||
int seconds = Math.max(mcMMOPlayer.calculateTimeRemaining(ability), 0);
|
||||
|
||||
if (seconds != 0) {
|
||||
anyCooldownsActive = true;
|
||||
|
@ -16,7 +16,6 @@ import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.HiddenConfig;
|
||||
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.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -54,19 +53,6 @@ public class SkillUtils {
|
||||
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.
|
||||
* This does NOT account for cooldown perks!
|
||||
|
Loading…
Reference in New Issue
Block a user