diff --git a/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java b/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java index c700eda60..0766c2713 100644 --- a/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java @@ -6,8 +6,8 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; -import com.gmail.nossr50.config.Config; import com.gmail.nossr50.util.Hardcore; +import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; public class HardcoreListener implements Listener { @@ -19,13 +19,17 @@ public class HardcoreListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR) public void onPlayerDeath(PlayerDeathEvent event) { - Player player = event.getEntity(); //Note this returns a Player object for this subevent + Player player = event.getEntity(); - if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + if (Misc.isNPCPlayer(player)) { + return; + } if (!Permissions.hardcoremodeBypass(player)) { - if (player.getKiller() != null && Config.getInstance().getHardcoreVampirismEnabled()) { - Hardcore.invokeVampirism(player.getKiller(), player); + Player killer = player.getKiller(); + + if (killer != null && Hardcore.vampirismEnabled) { + Hardcore.invokeVampirism(killer, player); } Hardcore.invokeStatPenalty(player); diff --git a/src/main/java/com/gmail/nossr50/util/Hardcore.java b/src/main/java/com/gmail/nossr50/util/Hardcore.java index 238b861dc..3f43479cf 100644 --- a/src/main/java/com/gmail/nossr50/util/Hardcore.java +++ b/src/main/java/com/gmail/nossr50/util/Hardcore.java @@ -8,11 +8,14 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; public abstract class Hardcore { + public static double statLossPercentage = Config.getInstance().getHardcoreDeathStatPenaltyPercentage(); + public static double vampirismStatLeechPercentage = Config.getInstance().getHardcoreVampirismStatLeechPercentage(); + + public static boolean statLossEnabled = Config.getInstance().getHardcoreEnabled(); + public static boolean vampirismEnabled = Config.getInstance().getHardcoreVampirismEnabled(); public static void invokeStatPenalty(Player player) { - double hardcorePenalty = Config.getInstance().getHardcoreDeathStatPenaltyPercentage(); - - if (hardcorePenalty <= 0 || hardcorePenalty > 100) { + if (statLossPercentage <= 0 || statLossPercentage > 100) { return; } @@ -31,7 +34,7 @@ public abstract class Hardcore { continue; } - int levelsLost = (int) (playerSkillLevel * (hardcorePenalty * 0.01D)); + int levelsLost = (int) (playerSkillLevel * (statLossPercentage * 0.01D)); totalLost += levelsLost; playerProfile.modifySkill(skillType, playerSkillLevel - levelsLost); @@ -41,9 +44,7 @@ public abstract class Hardcore { } public static void invokeVampirism(Player killer, Player victim) { - double vampirismLeech = Config.getInstance().getHardcoreVampirismStatLeechPercentage(); - - if (vampirismLeech <= 0 || vampirismLeech > 100) { + if (vampirismStatLeechPercentage <= 0 || vampirismStatLeechPercentage > 100) { return; } @@ -64,7 +65,7 @@ public abstract class Hardcore { continue; } - int levelsStolen = (int) (victimSkillLevel * (vampirismLeech * 0.01D)); + int levelsStolen = (int) (victimSkillLevel * (vampirismStatLeechPercentage * 0.01D)); totalStolen += levelsStolen; killerProfile.modifySkill(skillType, killerSkillLevel + levelsStolen); diff --git a/src/main/java/com/gmail/nossr50/util/MOTD.java b/src/main/java/com/gmail/nossr50/util/MOTD.java index 2f4145a0c..bd3bacbbf 100644 --- a/src/main/java/com/gmail/nossr50/util/MOTD.java +++ b/src/main/java/com/gmail/nossr50/util/MOTD.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.util; import org.bukkit.entity.Player; -import com.gmail.nossr50.config.Config; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillType; @@ -26,15 +25,15 @@ public class MOTD { * Display Hardcore Mode settings. */ public void displayHardcoreSettings() { - if (Config.getInstance().getHardcoreEnabled()) { - if (Config.getInstance().getHardcoreVampirismEnabled()) { + if (Hardcore.statLossEnabled) { + if (Hardcore.vampirismEnabled) { player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn")); - player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Config.getInstance().getHardcoreDeathStatPenaltyPercentage()})); - player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", new Object[] {Config.getInstance().getHardcoreVampirismStatLeechPercentage()})); + player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Hardcore.statLossPercentage})); + player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", new Object[] {Hardcore.vampirismStatLeechPercentage})); } else { player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOff")); - player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Config.getInstance().getHardcoreDeathStatPenaltyPercentage()})); + player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Hardcore.statLossPercentage })); } } }