From f7aaf25d931899870ce85ff0a8f739678b4265b9 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 24 Sep 2019 16:53:57 -0700 Subject: [PATCH] Static Abuse Removal - HardcoreManager --- .../nossr50/listeners/PlayerListener.java | 9 +++--- src/main/java/com/gmail/nossr50/mcMMO.java | 8 ++++++ .../gmail/nossr50/util/HardcoreManager.java | 28 +++++++++++-------- .../nossr50/util/MessageOfTheDayUtils.java | 4 +-- .../gmail/nossr50/util/skills/SkillTools.java | 8 +++--- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 6e13c97f1..e5b965305 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -17,7 +17,6 @@ import com.gmail.nossr50.skills.repair.RepairManager; import com.gmail.nossr50.skills.salvage.SalvageManager; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.util.ChimaeraWing; -import com.gmail.nossr50.util.HardcoreManager; import com.gmail.nossr50.util.sounds.SoundType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -130,8 +129,8 @@ public class PlayerListener implements Listener { if (pluginRef.getDynamicSettingsManager().isWorldBlacklisted(event.getEntity().getWorld().getName())) return; - boolean statLossEnabled = HardcoreManager.isStatLossEnabled(); - boolean vampirismEnabled = HardcoreManager.isVampirismEnabled(); + boolean statLossEnabled = pluginRef.getHardcoreManager().isStatLossEnabled(); + boolean vampirismEnabled = pluginRef.getHardcoreManager().isVampirismEnabled(); if (!statLossEnabled && !vampirismEnabled) { return; @@ -157,11 +156,11 @@ public class PlayerListener implements Listener { } if (killer != null && vampirismEnabled) { - HardcoreManager.invokeVampirism(killer, killedPlayer); + pluginRef.getHardcoreManager().invokeVampirism(killer, killedPlayer); } if (statLossEnabled) { - HardcoreManager.invokeStatPenalty(killedPlayer); + pluginRef.getHardcoreManager().invokeStatPenalty(killedPlayer); } } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 9754c7dfa..42b98c545 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -105,6 +105,7 @@ public class mcMMO extends JavaPlugin { private MessageOfTheDayUtils messageOfTheDayUtils; private MiscTools miscTools; private ZipLibrary zipLibrary; + private HardcoreManager hardcoreManager; /* Never-Ending tasks */ private BleedTimerTask bleedTimerTask; @@ -293,6 +294,9 @@ public class mcMMO extends JavaPlugin { //Misc Tools Init miscTools = new MiscTools(this); + + //Init HardcoreManager + hardcoreManager = new HardcoreManager(this); } @Override @@ -841,4 +845,8 @@ public class mcMMO extends JavaPlugin { public MiscTools getMiscTools() { return miscTools; } + + public HardcoreManager getHardcoreManager() { + return hardcoreManager; + } } diff --git a/src/main/java/com/gmail/nossr50/util/HardcoreManager.java b/src/main/java/com/gmail/nossr50/util/HardcoreManager.java index 53fc8d417..5c78ba468 100644 --- a/src/main/java/com/gmail/nossr50/util/HardcoreManager.java +++ b/src/main/java/com/gmail/nossr50/util/HardcoreManager.java @@ -3,19 +3,23 @@ package com.gmail.nossr50.util; import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import com.gmail.nossr50.worldguard.WorldGuardManager; +import com.gmail.nossr50.mcMMO; import org.bukkit.entity.Player; import java.util.HashMap; public final class HardcoreManager { - private HardcoreManager() { + + private final mcMMO pluginRef; + + public HardcoreManager(mcMMO pluginRef) { + this.pluginRef = pluginRef; } - public static void invokeStatPenalty(Player player) { + public void invokeStatPenalty(Player player) { if(pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) { - if(!WorldGuardManager.getInstance().hasHardcoreFlag(player)) { + if(!pluginRef.getWorldGuardManager().hasHardcoreFlag(player)) { return; } } @@ -33,7 +37,7 @@ public final class HardcoreManager { HashMap experienceChanged = new HashMap<>(); for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) { - if (!primarySkillType.getHardcoreStatLossEnabled()) { + if (!pluginRef.getSkillTools().getHardcoreStatLossEnabled(primarySkillType)) { levelChanged.put(primarySkillType.toString(), 0); experienceChanged.put(primarySkillType.toString(), 0.0); continue; @@ -64,10 +68,10 @@ public final class HardcoreManager { pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.HARDCORE_MODE, "Hardcore.DeathStatLoss.PlayerDeath", String.valueOf(totalLevelsLost)); } - public static void invokeVampirism(Player killer, Player victim) { + public void invokeVampirism(Player killer, Player victim) { if(pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) { - if(!WorldGuardManager.getInstance().hasHardcoreFlag(killer) || !WorldGuardManager.getInstance().hasHardcoreFlag(victim)) { + if(!pluginRef.getWorldGuardManager().hasHardcoreFlag(killer) || !pluginRef.getWorldGuardManager().hasHardcoreFlag(victim)) { return; } } @@ -86,7 +90,7 @@ public final class HardcoreManager { HashMap experienceChanged = new HashMap<>(); for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) { - if (!primarySkillType.getHardcoreVampirismEnabled()) { + if (!pluginRef.getSkillTools().getHardcoreVampirismEnabled(primarySkillType)) { levelChanged.put(primarySkillType.toString(), 0); experienceChanged.put(primarySkillType.toString(), 0.0); continue; @@ -130,11 +134,11 @@ public final class HardcoreManager { * * @return true if Stat Loss is enabled for one or more skill types */ - public static boolean isStatLossEnabled() { + public boolean isStatLossEnabled() { boolean enabled = false; for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) { - if (primarySkillType.getHardcoreStatLossEnabled()) { + if (pluginRef.getSkillTools().getHardcoreStatLossEnabled(primarySkillType)) { enabled = true; break; } @@ -148,11 +152,11 @@ public final class HardcoreManager { * * @return true if Vampirism is enabled for one or more skill types */ - public static boolean isVampirismEnabled() { + public boolean isVampirismEnabled() { boolean enabled = false; for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) { - if (primarySkillType.getHardcoreVampirismEnabled()) { + if (pluginRef.getSkillTools().getHardcoreVampirismEnabled(primarySkillType)) { enabled = true; break; } diff --git a/src/main/java/com/gmail/nossr50/util/MessageOfTheDayUtils.java b/src/main/java/com/gmail/nossr50/util/MessageOfTheDayUtils.java index f10ba77c4..3eee1ea92 100644 --- a/src/main/java/com/gmail/nossr50/util/MessageOfTheDayUtils.java +++ b/src/main/java/com/gmail/nossr50/util/MessageOfTheDayUtils.java @@ -47,8 +47,8 @@ public final class MessageOfTheDayUtils { * @param player Target player */ public void displayHardcoreSettings(Player player) { - boolean deathStatLossEnabled = HardcoreManager.isStatLossEnabled(); - boolean vampirismEnabled = HardcoreManager.isVampirismEnabled(); + boolean deathStatLossEnabled = pluginRef.getHardcoreManager().isStatLossEnabled(); + boolean vampirismEnabled = pluginRef.getHardcoreManager().isVampirismEnabled(); if (!deathStatLossEnabled && !vampirismEnabled) { return; 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 460f1c079..4991e2514 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillTools.java @@ -674,12 +674,12 @@ public class SkillTools { return pluginRef.getConfigManager().getConfigCoreSkills().isPVEEnabled(primarySkillType); } - public boolean getHardcoreStatLossEnabled() { - return pluginRef.getConfigManager().getConfigHardcore().getDeathPenalty().getSkillToggleMap().get(this); + public boolean getHardcoreStatLossEnabled(PrimarySkillType primarySkillType) { + return pluginRef.getConfigManager().getConfigHardcore().getDeathPenalty().getSkillToggleMap().get(primarySkillType); } - public boolean getHardcoreVampirismEnabled() { - return pluginRef.getConfigManager().getConfigHardcore().getVampirism().getSkillToggleMap().get(this); + public boolean getHardcoreVampirismEnabled(PrimarySkillType primarySkillType) { + return pluginRef.getConfigManager().getConfigHardcore().getVampirism().getSkillToggleMap().get(primarySkillType); } public ToolType getPrimarySkillToolType(PrimarySkillType primarySkillType) {