diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java index c9883433d..d36c49d56 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java @@ -5,7 +5,9 @@ import java.util.Random; import com.gmail.nossr50.config.AdvancedConfig; public class Acrobatics { - static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); + private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); + private static Random random = new Random(); + public static final int DODGE_MAX_CHANCE = advancedConfig.getDodgeChanceMax(); public static final int DODGE_MAX_BONUS_LEVEL = advancedConfig.getDodgeMaxBonusLevel(); public static final int DODGE_XP_MODIFIER = advancedConfig.getDodgeXPModifier(); @@ -18,9 +20,7 @@ public class Acrobatics { public static final int ROLL_XP_MODIFIER = advancedConfig.getRollXPModifier(); public static final int FALL_XP_MODIFIER = advancedConfig.getFallXPModifier(); - private static Random random = new Random(); - - public static Random getRandom() { + protected static Random getRandom() { return random; } } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsEventHandler.java index 383cd70a4..f123724ed 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsEventHandler.java @@ -3,6 +3,8 @@ package com.gmail.nossr50.skills.acrobatics; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; +import com.gmail.nossr50.util.Misc; + public abstract class AcrobaticsEventHandler { protected AcrobaticsManager manager; protected Player player; @@ -51,14 +53,10 @@ public abstract class AcrobaticsEventHandler { * @return true if the damage is fatal, false otherwise */ protected boolean isFatal(int damage) { - if(player == null) + if (Misc.isCitizensNPC(player) || player.getHealth() - damage < 1) { return true; + } - if (player.getHealth() - damage < 1) { - return true; - } - else { - return false; - } + return false; } } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java index aff0a0e93..473836f3c 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -6,10 +6,13 @@ import org.bukkit.event.entity.EntityDamageEvent; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; public class AcrobaticsManager { + private static Config config = Config.getInstance(); + private Player player; private PlayerProfile profile; private int skillLevel; @@ -26,29 +29,28 @@ public class AcrobaticsManager { * @param event The event to check */ public void rollCheck(EntityDamageEvent event) { - if(player == null) - return; - - if (!Permissions.roll(player)) { + if (Misc.isCitizensNPC(player) || !Permissions.roll(player)) { return; } - if(Config.getInstance().getAcrobaticsAFKDisabled() && player.isInsideVehicle()) + if (config.getAcrobaticsAFKDisabled() && player.isInsideVehicle()) { return; + } RollEventHandler eventHandler = new RollEventHandler(this, event); int randomChance = 100; - if (Permissions.luckyAcrobatics(player)) { randomChance = (int) (randomChance * 0.75); } - float chance = (float) (((double) Acrobatics.ROLL_MAX_CHANCE / (double) Acrobatics.ROLL_MAX_BONUS_LEVEL) * skillLevel); - if (chance > Acrobatics.ROLL_MAX_CHANCE) chance = Acrobatics.ROLL_MAX_CHANCE; + float chance; + if (eventHandler.isGraceful) { - chance = (float) (((double) Acrobatics.GRACEFUL_MAX_CHANCE / (double) Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * skillLevel); - if (chance > Acrobatics.GRACEFUL_MAX_CHANCE) chance = Acrobatics.GRACEFUL_MAX_CHANCE; + chance = ((float) Acrobatics.GRACEFUL_MAX_CHANCE / Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * eventHandler.skillModifier; + } + else { + chance = ((float) Acrobatics.ROLL_MAX_CHANCE / Acrobatics.ROLL_MAX_BONUS_LEVEL) * eventHandler.skillModifier; } if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { @@ -67,23 +69,18 @@ public class AcrobaticsManager { * @param event The event to check */ public void dodgeCheck(EntityDamageEvent event) { - if(player == null) - return; - - if (!Permissions.dodge(player)) { + if (Misc.isCitizensNPC(player) || !Permissions.dodge(player)) { return; } DodgeEventHandler eventHandler = new DodgeEventHandler(this, event); int randomChance = 100; - if (Permissions.luckyAcrobatics(player)) { randomChance = (int) (randomChance * 0.75); } - float chance = (float) (((double) Acrobatics.DODGE_MAX_CHANCE / (double) Acrobatics.DODGE_MAX_BONUS_LEVEL) * skillLevel); - if (chance > Acrobatics.DODGE_MAX_CHANCE) chance = Acrobatics.DODGE_MAX_CHANCE; + float chance = ((float) Acrobatics.DODGE_MAX_CHANCE / Acrobatics.DODGE_MAX_BONUS_LEVEL) * eventHandler.skillModifier; if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { eventHandler.modifyEventDamage(); diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java index 6fe6064e9..64f28adb4 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/DodgeEventHandler.java @@ -39,20 +39,14 @@ public class DodgeEventHandler extends AcrobaticsEventHandler { @Override protected void sendAbilityMessage() { - if(player == null) - return; - player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc")); } @Override protected void processXPGain(int xp) { - if(player == null) - return; - PlayerProfile profile = manager.getProfile(); - if (System.currentTimeMillis() >= profile.getRespawnATS() + 5) { + if (System.currentTimeMillis() >= profile.getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) { Skills.xpProcessing(player, profile, SkillType.ACROBATICS, xp); } } diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java index 4e98848b5..43cbcebc3 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java @@ -56,9 +56,6 @@ public class RollEventHandler extends AcrobaticsEventHandler { @Override protected void sendAbilityMessage() { - if(player == null) - return; - if (isGraceful) { player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc")); } @@ -70,9 +67,6 @@ public class RollEventHandler extends AcrobaticsEventHandler { @Override protected void processXPGain(int xpGain) { - if(player == null) - return; - Skills.xpProcessing(player, manager.getProfile(), SkillType.ACROBATICS, xpGain); } @@ -80,9 +74,6 @@ public class RollEventHandler extends AcrobaticsEventHandler { * Check if this is a graceful roll. */ private void isGracefulRoll() { - if(player == null) - return; - if (Permissions.gracefulRoll(player)) { this.isGraceful = player.isSneaking(); } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index 34b853bdd..b8740c5c2 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -63,8 +63,7 @@ public class MiningManager { return; } - MiningManager manager = new MiningManager(player); - SuperBreakerEventHandler eventHandler = new SuperBreakerEventHandler(manager, block); + SuperBreakerEventHandler eventHandler = new SuperBreakerEventHandler(this, block); if (eventHandler.tierCheck()) { return; diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 596286518..3056dbc6d 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -23,6 +23,11 @@ public class Misc { private static Random random = new Random(); public static final int TOOL_DURABILITY_LOSS = Config.getInstance().getAbilityToolDamage(); + public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5; + + public static boolean isCitizensNPC(Player player) { + return player.hasMetadata("NPC"); + } /** * Gets a capitalized version of the target string.