A little more cleanup

This commit is contained in:
GJ 2013-01-24 22:22:02 -05:00
parent f5179cdcea
commit 96d59a2e81
3 changed files with 23 additions and 19 deletions

View File

@ -6,8 +6,8 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.util.Hardcore; import com.gmail.nossr50.util.Hardcore;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
public class HardcoreListener implements Listener { public class HardcoreListener implements Listener {
@ -19,13 +19,17 @@ public class HardcoreListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event) { 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 (!Permissions.hardcoremodeBypass(player)) {
if (player.getKiller() != null && Config.getInstance().getHardcoreVampirismEnabled()) { Player killer = player.getKiller();
Hardcore.invokeVampirism(player.getKiller(), player);
if (killer != null && Hardcore.vampirismEnabled) {
Hardcore.invokeVampirism(killer, player);
} }
Hardcore.invokeStatPenalty(player); Hardcore.invokeStatPenalty(player);

View File

@ -8,11 +8,14 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.SkillType;
public abstract class Hardcore { 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) { public static void invokeStatPenalty(Player player) {
double hardcorePenalty = Config.getInstance().getHardcoreDeathStatPenaltyPercentage(); if (statLossPercentage <= 0 || statLossPercentage > 100) {
if (hardcorePenalty <= 0 || hardcorePenalty > 100) {
return; return;
} }
@ -31,7 +34,7 @@ public abstract class Hardcore {
continue; continue;
} }
int levelsLost = (int) (playerSkillLevel * (hardcorePenalty * 0.01D)); int levelsLost = (int) (playerSkillLevel * (statLossPercentage * 0.01D));
totalLost += levelsLost; totalLost += levelsLost;
playerProfile.modifySkill(skillType, playerSkillLevel - levelsLost); playerProfile.modifySkill(skillType, playerSkillLevel - levelsLost);
@ -41,9 +44,7 @@ public abstract class Hardcore {
} }
public static void invokeVampirism(Player killer, Player victim) { public static void invokeVampirism(Player killer, Player victim) {
double vampirismLeech = Config.getInstance().getHardcoreVampirismStatLeechPercentage(); if (vampirismStatLeechPercentage <= 0 || vampirismStatLeechPercentage > 100) {
if (vampirismLeech <= 0 || vampirismLeech > 100) {
return; return;
} }
@ -64,7 +65,7 @@ public abstract class Hardcore {
continue; continue;
} }
int levelsStolen = (int) (victimSkillLevel * (vampirismLeech * 0.01D)); int levelsStolen = (int) (victimSkillLevel * (vampirismStatLeechPercentage * 0.01D));
totalStolen += levelsStolen; totalStolen += levelsStolen;
killerProfile.modifySkill(skillType, killerSkillLevel + levelsStolen); killerProfile.modifySkill(skillType, killerSkillLevel + levelsStolen);

View File

@ -2,7 +2,6 @@ package com.gmail.nossr50.util;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.SkillType;
@ -26,15 +25,15 @@ public class MOTD {
* Display Hardcore Mode settings. * Display Hardcore Mode settings.
*/ */
public void displayHardcoreSettings() { public void displayHardcoreSettings() {
if (Config.getInstance().getHardcoreEnabled()) { if (Hardcore.statLossEnabled) {
if (Config.getInstance().getHardcoreVampirismEnabled()) { if (Hardcore.vampirismEnabled) {
player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn")); player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOn"));
player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Config.getInstance().getHardcoreDeathStatPenaltyPercentage()})); player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.Stats", new Object[] {Hardcore.statLossPercentage}));
player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", new Object[] {Config.getInstance().getHardcoreVampirismStatLeechPercentage()})); player.sendMessage(LocaleLoader.getString("MOTD.Vampire.Stats", new Object[] {Hardcore.vampirismStatLeechPercentage}));
} }
else { else {
player.sendMessage(LocaleLoader.getString("MOTD.Hardcore.VampireOff")); 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 }));
} }
} }
} }