From f52144fb3e8b0b2a63aca212e091588f62b4d2dd Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 24 Sep 2019 17:01:08 -0700 Subject: [PATCH] Static Abuse Removal PerkUtils --- .../nossr50/datatypes/player/McMMOPlayer.java | 3 +-- .../skills/subskills/acrobatics/Roll.java | 3 +-- src/main/java/com/gmail/nossr50/mcMMO.java | 11 ++++++++++- .../runnables/skills/AbilityDisableTask.java | 3 +-- .../gmail/nossr50/util/MessageOfTheDayUtils.java | 5 ++--- .../skills/{PerksUtils.java => PerkUtils.java} | 15 +++++++++------ .../com/gmail/nossr50/util/skills/SkillTools.java | 6 +++--- 7 files changed, 27 insertions(+), 19 deletions(-) rename src/main/java/com/gmail/nossr50/util/skills/{PerksUtils.java => PerkUtils.java} (69%) diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 273a264fb..37ed12b66 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -31,7 +31,6 @@ import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager; import com.gmail.nossr50.util.experience.ExperienceBarManager; -import com.gmail.nossr50.util.skills.PerksUtils; import com.gmail.nossr50.util.sounds.SoundType; import org.apache.commons.lang.Validate; import org.bukkit.GameMode; @@ -1012,7 +1011,7 @@ public class McMMOPlayer { */ public int calculateTimeRemaining(SuperAbilityType superAbilityType) { long deactivatedTimestamp = profile.getAbilityDATS(superAbilityType) * pluginRef.getMiscTools().TIME_CONVERSION_FACTOR; - return (int) (((deactivatedTimestamp + (PerksUtils.handleCooldownPerks(player, + return (int) (((deactivatedTimestamp + (pluginRef.getPerkUtils().handleCooldownPerks(player, pluginRef.getSkillTools().getSuperAbilityCooldown(superAbilityType)) * pluginRef.getMiscTools().TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / pluginRef.getMiscTools().TIME_CONVERSION_FACTOR); } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java index ef38ce963..3fc623144 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/acrobatics/Roll.java @@ -7,7 +7,6 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.random.RandomChanceSkill; -import com.gmail.nossr50.util.skills.PerksUtils; import com.gmail.nossr50.util.skills.SkillActivationType; import com.gmail.nossr50.util.sounds.SoundType; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -221,7 +220,7 @@ public class Roll extends AcrobaticsSubSkill { } private int getActivationChance(McMMOPlayer mcMMOPlayer) { - return PerksUtils.handleLuckyPerks(mcMMOPlayer.getPlayer(), getPrimarySkill()); + return pluginRef.getPerkUtils().handleLuckyPerks(mcMMOPlayer.getPlayer(), getPrimarySkill()); } /** diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 42b98c545..01bf9ea26 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -41,6 +41,7 @@ import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.random.RandomChanceTools; import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.skills.CombatTools; +import com.gmail.nossr50.util.skills.PerkUtils; import com.gmail.nossr50.util.skills.RankTools; import com.gmail.nossr50.util.skills.SkillTools; import com.gmail.nossr50.util.sounds.SoundManager; @@ -86,6 +87,7 @@ public class mcMMO extends JavaPlugin { private UserManager userManager; private ScoreboardManager scoreboardManager; private SoundManager soundManager; + private HardcoreManager hardcoreManager; /* Not-Managers but my naming scheme sucks */ private DatabaseManagerFactory databaseManagerFactory; @@ -105,7 +107,7 @@ public class mcMMO extends JavaPlugin { private MessageOfTheDayUtils messageOfTheDayUtils; private MiscTools miscTools; private ZipLibrary zipLibrary; - private HardcoreManager hardcoreManager; + private PerkUtils perkUtils; /* Never-Ending tasks */ private BleedTimerTask bleedTimerTask; @@ -297,6 +299,9 @@ public class mcMMO extends JavaPlugin { //Init HardcoreManager hardcoreManager = new HardcoreManager(this); + + //Init PerkUtils + perkUtils = new PerkUtils(this); } @Override @@ -849,4 +854,8 @@ public class mcMMO extends JavaPlugin { public HardcoreManager getHardcoreManager() { return hardcoreManager; } + + public PerkUtils getPerkUtils() { + return perkUtils; + } } diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/AbilityDisableTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/AbilityDisableTask.java index ba6c5a565..6e954fea4 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/AbilityDisableTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/AbilityDisableTask.java @@ -4,7 +4,6 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.util.skills.PerksUtils; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.entity.Player; @@ -58,7 +57,7 @@ public class AbilityDisableTask extends BukkitRunnable { pluginRef.getSkillTools().sendSkillMessage(player, NotificationType.SUPER_ABILITY_ALERT_OTHERS, pluginRef.getSkillTools().getSuperAbilityOtherPlayerDeactivationStr(superAbilityType)); new AbilityCooldownTask(pluginRef, mcMMOPlayer, superAbilityType).runTaskLater(pluginRef, - PerksUtils.handleCooldownPerks(player, + pluginRef.getPerkUtils().handleCooldownPerks(player, pluginRef.getSkillTools().getSuperAbilityCooldown(superAbilityType) * pluginRef.getMiscTools().TICK_CONVERSION_FACTOR)); } diff --git a/src/main/java/com/gmail/nossr50/util/MessageOfTheDayUtils.java b/src/main/java/com/gmail/nossr50/util/MessageOfTheDayUtils.java index 3eee1ea92..6f020f813 100644 --- a/src/main/java/com/gmail/nossr50/util/MessageOfTheDayUtils.java +++ b/src/main/java/com/gmail/nossr50/util/MessageOfTheDayUtils.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.util; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.util.skills.PerksUtils; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; @@ -88,7 +87,7 @@ public final class MessageOfTheDayUtils { */ public void displayXpPerks(Player player) { for (PrimarySkillType skill : PrimarySkillType.values()) { -// if (PerksUtils.handleXpPerks(player, 1, skill) > 1) { +// if (pluginRef.getPerkUtils().handleXpPerks(player, 1, skill) > 1) { // player.sendMessage(PERK_PREFIX + pluginRef.getLocaleManager().getString("Effects.Template", pluginRef.getLocaleManager().getString("Perks.XP.Name"), pluginRef.getLocaleManager().getString("Perks.XP.Desc"))); // return; // } @@ -101,7 +100,7 @@ public final class MessageOfTheDayUtils { * @param player Target player */ public void displayCooldownPerks(Player player) { - double cooldownReduction = 1 - (PerksUtils.handleCooldownPerks(player, 12) / 12.0); + double cooldownReduction = 1 - (pluginRef.getPerkUtils().handleCooldownPerks(player, 12) / 12.0); if (cooldownReduction > 0.0) { DecimalFormat percent = new DecimalFormat("##0.00%"); diff --git a/src/main/java/com/gmail/nossr50/util/skills/PerksUtils.java b/src/main/java/com/gmail/nossr50/util/skills/PerkUtils.java similarity index 69% rename from src/main/java/com/gmail/nossr50/util/skills/PerksUtils.java rename to src/main/java/com/gmail/nossr50/util/skills/PerkUtils.java index dab2a8c42..703e9a604 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/PerksUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/PerkUtils.java @@ -1,16 +1,19 @@ package com.gmail.nossr50.util.skills; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; +import com.gmail.nossr50.mcMMO; import org.bukkit.entity.Player; -public final class PerksUtils { - private static final int LUCKY_SKILL_ACTIVATION_CHANCE = 75; - private static final int NORMAL_SKILL_ACTIVATION_CHANCE = 100; +public final class PerkUtils { + private final int LUCKY_SKILL_ACTIVATION_CHANCE = 75; + private final int NORMAL_SKILL_ACTIVATION_CHANCE = 100; + private final mcMMO pluginRef; - private PerksUtils() { + public PerkUtils(mcMMO pluginRef) { + this.pluginRef = pluginRef; } - public static int handleCooldownPerks(Player player, int cooldown) { + public int handleCooldownPerks(Player player, int cooldown) { if (pluginRef.getPermissionTools().halvedCooldowns(player)) { cooldown *= 0.5; } else if (pluginRef.getPermissionTools().thirdedCooldowns(player)) { @@ -29,7 +32,7 @@ public final class PerksUtils { * @param skill PrimarySkillType to check the activation chance of * @return the activation chance with "lucky perk" accounted for */ - public static int handleLuckyPerks(Player player, PrimarySkillType skill) { + public int handleLuckyPerks(Player player, PrimarySkillType skill) { if (pluginRef.getPermissionTools().lucky(player, skill)) { return LUCKY_SKILL_ACTIVATION_CHANCE; } diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java b/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java index 4991e2514..267536f56 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java @@ -315,7 +315,7 @@ public class SkillTools { * @return the number of seconds remaining before the cooldown expires */ public int calculateTimeLeft(long deactivatedTimeStamp, int cooldown, Player player) { - return (int) (((deactivatedTimeStamp + (PerksUtils.handleCooldownPerks(player, cooldown) * pluginRef.getMiscTools().TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / pluginRef.getMiscTools().TIME_CONVERSION_FACTOR); + return (int) (((deactivatedTimeStamp + (pluginRef.getPerkUtils().handleCooldownPerks(player, cooldown) * pluginRef.getMiscTools().TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / pluginRef.getMiscTools().TIME_CONVERSION_FACTOR); } /** @@ -401,10 +401,10 @@ public class SkillTools { if(abilityLengthCap > 0) { - ticks = PerksUtils.calculateAbilityLength(player, Math.min(abilityLengthCap, 2 + (mcMMOPlayer.getSkillLevel(skill) / abilityLengthVar)), + ticks = pluginRef.getPerkUtils().calculateAbilityLength(player, Math.min(abilityLengthCap, 2 + (mcMMOPlayer.getSkillLevel(skill) / abilityLengthVar)), skill.getSuperAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR; } else { - ticks = PerksUtils.calculateAbilityLength(player, 2 + ((mcMMOPlayer.getSkillLevel(skill)) / abilityLengthVar), + ticks = pluginRef.getPerkUtils().calculateAbilityLength(player, 2 + ((mcMMOPlayer.getSkillLevel(skill)) / abilityLengthVar), skill.getSuperAbility().getMaxLength()) * Misc.TICK_CONVERSION_FACTOR; }