Static Abuse Removal - HardcoreManager

This commit is contained in:
nossr50 2019-09-24 16:53:57 -07:00
parent 3552457790
commit f7aaf25d93
5 changed files with 34 additions and 23 deletions

View File

@ -17,7 +17,6 @@ import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.salvage.SalvageManager; import com.gmail.nossr50.skills.salvage.SalvageManager;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.ChimaeraWing; import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.HardcoreManager;
import com.gmail.nossr50.util.sounds.SoundType; import com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -130,8 +129,8 @@ public class PlayerListener implements Listener {
if (pluginRef.getDynamicSettingsManager().isWorldBlacklisted(event.getEntity().getWorld().getName())) if (pluginRef.getDynamicSettingsManager().isWorldBlacklisted(event.getEntity().getWorld().getName()))
return; return;
boolean statLossEnabled = HardcoreManager.isStatLossEnabled(); boolean statLossEnabled = pluginRef.getHardcoreManager().isStatLossEnabled();
boolean vampirismEnabled = HardcoreManager.isVampirismEnabled(); boolean vampirismEnabled = pluginRef.getHardcoreManager().isVampirismEnabled();
if (!statLossEnabled && !vampirismEnabled) { if (!statLossEnabled && !vampirismEnabled) {
return; return;
@ -157,11 +156,11 @@ public class PlayerListener implements Listener {
} }
if (killer != null && vampirismEnabled) { if (killer != null && vampirismEnabled) {
HardcoreManager.invokeVampirism(killer, killedPlayer); pluginRef.getHardcoreManager().invokeVampirism(killer, killedPlayer);
} }
if (statLossEnabled) { if (statLossEnabled) {
HardcoreManager.invokeStatPenalty(killedPlayer); pluginRef.getHardcoreManager().invokeStatPenalty(killedPlayer);
} }
} }
} }

View File

@ -105,6 +105,7 @@ public class mcMMO extends JavaPlugin {
private MessageOfTheDayUtils messageOfTheDayUtils; private MessageOfTheDayUtils messageOfTheDayUtils;
private MiscTools miscTools; private MiscTools miscTools;
private ZipLibrary zipLibrary; private ZipLibrary zipLibrary;
private HardcoreManager hardcoreManager;
/* Never-Ending tasks */ /* Never-Ending tasks */
private BleedTimerTask bleedTimerTask; private BleedTimerTask bleedTimerTask;
@ -293,6 +294,9 @@ public class mcMMO extends JavaPlugin {
//Misc Tools Init //Misc Tools Init
miscTools = new MiscTools(this); miscTools = new MiscTools(this);
//Init HardcoreManager
hardcoreManager = new HardcoreManager(this);
} }
@Override @Override
@ -841,4 +845,8 @@ public class mcMMO extends JavaPlugin {
public MiscTools getMiscTools() { public MiscTools getMiscTools() {
return miscTools; return miscTools;
} }
public HardcoreManager getHardcoreManager() {
return hardcoreManager;
}
} }

View File

@ -3,19 +3,23 @@ package com.gmail.nossr50.util;
import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.worldguard.WorldGuardManager; import com.gmail.nossr50.mcMMO;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashMap; import java.util.HashMap;
public final class HardcoreManager { 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(pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if(!WorldGuardManager.getInstance().hasHardcoreFlag(player)) { if(!pluginRef.getWorldGuardManager().hasHardcoreFlag(player)) {
return; return;
} }
} }
@ -33,7 +37,7 @@ public final class HardcoreManager {
HashMap<String, Double> experienceChanged = new HashMap<>(); HashMap<String, Double> experienceChanged = new HashMap<>();
for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) { for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) {
if (!primarySkillType.getHardcoreStatLossEnabled()) { if (!pluginRef.getSkillTools().getHardcoreStatLossEnabled(primarySkillType)) {
levelChanged.put(primarySkillType.toString(), 0); levelChanged.put(primarySkillType.toString(), 0);
experienceChanged.put(primarySkillType.toString(), 0.0); experienceChanged.put(primarySkillType.toString(), 0.0);
continue; continue;
@ -64,10 +68,10 @@ public final class HardcoreManager {
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.HARDCORE_MODE, "Hardcore.DeathStatLoss.PlayerDeath", String.valueOf(totalLevelsLost)); 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(pluginRef.getWorldGuardUtils().isWorldGuardLoaded()) {
if(!WorldGuardManager.getInstance().hasHardcoreFlag(killer) || !WorldGuardManager.getInstance().hasHardcoreFlag(victim)) { if(!pluginRef.getWorldGuardManager().hasHardcoreFlag(killer) || !pluginRef.getWorldGuardManager().hasHardcoreFlag(victim)) {
return; return;
} }
} }
@ -86,7 +90,7 @@ public final class HardcoreManager {
HashMap<String, Double> experienceChanged = new HashMap<>(); HashMap<String, Double> experienceChanged = new HashMap<>();
for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) { for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) {
if (!primarySkillType.getHardcoreVampirismEnabled()) { if (!pluginRef.getSkillTools().getHardcoreVampirismEnabled(primarySkillType)) {
levelChanged.put(primarySkillType.toString(), 0); levelChanged.put(primarySkillType.toString(), 0);
experienceChanged.put(primarySkillType.toString(), 0.0); experienceChanged.put(primarySkillType.toString(), 0.0);
continue; continue;
@ -130,11 +134,11 @@ public final class HardcoreManager {
* *
* @return true if Stat Loss is enabled for one or more skill types * @return true if Stat Loss is enabled for one or more skill types
*/ */
public static boolean isStatLossEnabled() { public boolean isStatLossEnabled() {
boolean enabled = false; boolean enabled = false;
for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) { for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) {
if (primarySkillType.getHardcoreStatLossEnabled()) { if (pluginRef.getSkillTools().getHardcoreStatLossEnabled(primarySkillType)) {
enabled = true; enabled = true;
break; break;
} }
@ -148,11 +152,11 @@ public final class HardcoreManager {
* *
* @return true if Vampirism is enabled for one or more skill types * @return true if Vampirism is enabled for one or more skill types
*/ */
public static boolean isVampirismEnabled() { public boolean isVampirismEnabled() {
boolean enabled = false; boolean enabled = false;
for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) { for (PrimarySkillType primarySkillType : pluginRef.getSkillTools().NON_CHILD_SKILLS) {
if (primarySkillType.getHardcoreVampirismEnabled()) { if (pluginRef.getSkillTools().getHardcoreVampirismEnabled(primarySkillType)) {
enabled = true; enabled = true;
break; break;
} }

View File

@ -47,8 +47,8 @@ public final class MessageOfTheDayUtils {
* @param player Target player * @param player Target player
*/ */
public void displayHardcoreSettings(Player player) { public void displayHardcoreSettings(Player player) {
boolean deathStatLossEnabled = HardcoreManager.isStatLossEnabled(); boolean deathStatLossEnabled = pluginRef.getHardcoreManager().isStatLossEnabled();
boolean vampirismEnabled = HardcoreManager.isVampirismEnabled(); boolean vampirismEnabled = pluginRef.getHardcoreManager().isVampirismEnabled();
if (!deathStatLossEnabled && !vampirismEnabled) { if (!deathStatLossEnabled && !vampirismEnabled) {
return; return;

View File

@ -674,12 +674,12 @@ public class SkillTools {
return pluginRef.getConfigManager().getConfigCoreSkills().isPVEEnabled(primarySkillType); return pluginRef.getConfigManager().getConfigCoreSkills().isPVEEnabled(primarySkillType);
} }
public boolean getHardcoreStatLossEnabled() { public boolean getHardcoreStatLossEnabled(PrimarySkillType primarySkillType) {
return pluginRef.getConfigManager().getConfigHardcore().getDeathPenalty().getSkillToggleMap().get(this); return pluginRef.getConfigManager().getConfigHardcore().getDeathPenalty().getSkillToggleMap().get(primarySkillType);
} }
public boolean getHardcoreVampirismEnabled() { public boolean getHardcoreVampirismEnabled(PrimarySkillType primarySkillType) {
return pluginRef.getConfigManager().getConfigHardcore().getVampirism().getSkillToggleMap().get(this); return pluginRef.getConfigManager().getConfigHardcore().getVampirism().getSkillToggleMap().get(primarySkillType);
} }
public ToolType getPrimarySkillToolType(PrimarySkillType primarySkillType) { public ToolType getPrimarySkillToolType(PrimarySkillType primarySkillType) {