diff --git a/src/main/java/com/gmail/nossr50/skills/Combat.java b/src/main/java/com/gmail/nossr50/skills/Combat.java index a1f783504..c02d9d2b5 100644 --- a/src/main/java/com/gmail/nossr50/skills/Combat.java +++ b/src/main/java/com/gmail/nossr50/skills/Combat.java @@ -38,10 +38,10 @@ import com.gmail.nossr50.skills.swords.Swords; import com.gmail.nossr50.skills.swords.SwordsManager; import com.gmail.nossr50.skills.taming.Taming; import com.gmail.nossr50.skills.taming.TamingManager; +import com.gmail.nossr50.skills.unarmed.Unarmed; import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.util.ItemChecks; import com.gmail.nossr50.util.Misc; -import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; public class Combat { @@ -58,7 +58,7 @@ public class Combat { switch (damager.getType()) { case PLAYER: - Player attacker = (Player) event.getDamager(); + Player attacker = (Player) damager; if (Misc.isNPCPlayer(attacker)) { return; @@ -184,29 +184,33 @@ public class Combat { if (targetIsPlayer) { Player player = (Player) target; - AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player); - SwordsManager swordsManager = new SwordsManager(player); - if (damager instanceof Player) { if (Swords.pvpEnabled) { + SwordsManager swordsManager = new SwordsManager(player); swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage()); } if (Acrobatics.pvpEnabled) { + AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player); acrobaticsManager.dodgeCheck(event); } + + if (Unarmed.pvpEnabled && player.getItemInHand().getType() == Material.AIR) { + UnarmedManager unarmedManager = new UnarmedManager(player); + unarmedManager.deflectCheck(event); + } } else { if (Swords.pveEnabled && damager instanceof LivingEntity) { + SwordsManager swordsManager = new SwordsManager(player); swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage()); } if (Acrobatics.pveEnabled) { - if (damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) { - return; + if (!(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled)) { + AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player); + acrobaticsManager.dodgeCheck(event); } - - acrobaticsManager.dodgeCheck(event); } } } @@ -220,19 +224,11 @@ public class Combat { * @param event The event to run the archery checks on. */ public static void archeryCheck(Player shooter, LivingEntity target, EntityDamageByEntityEvent event) { - if (target instanceof Player) { - Player defender = (Player) target; - - if (defender.getItemInHand().getType().equals(Material.AIR)) { - if (configInstance.getUnarmedPVP()) { - UnarmedManager unarmedManager = new UnarmedManager(defender); - unarmedManager.deflectCheck(event); - } - } + if (Misc.isNPCPlayer(shooter)) { + return; } ArcheryManager archeryManager = new ArcheryManager(shooter); - archeryManager.skillShot(event); if (target instanceof Player) { @@ -244,8 +240,7 @@ public class Combat { } if (target != shooter) { - PlayerProfile profile = Users.getProfile(shooter); - startGainXp(shooter, profile, target, SkillType.ARCHERY); + startGainXp(shooter, archeryManager.getProfile(), target, SkillType.ARCHERY); } } @@ -322,13 +317,7 @@ public class Combat { } for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) { - if (entity instanceof Player) { - if (Misc.isNPCPlayer((Player) entity)) { - continue; - } - } - - if (!(entity instanceof LivingEntity)) { + if ((entity instanceof Player && Misc.isNPCPlayer((Player) entity)) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) { continue; } @@ -336,10 +325,6 @@ public class Combat { break; } - if (!shouldBeAffected(attacker, entity)) { - continue; - } - PlayerAnimationEvent armswing = new PlayerAnimationEvent(attacker); mcMMO.p.getServer().getPluginManager().callEvent(armswing); @@ -503,19 +488,7 @@ public class Combat { if (entity instanceof Player) { Player defender = (Player) entity; - if (!defender.getWorld().getPVP()) { - return false; - } - - if (defender == player) { - return false; - } - - if (PartyManager.getInstance().inSameParty(player, defender)) { - return false; - } - - if (Users.getProfile(defender).getGodMode()) { + if (!defender.getWorld().getPVP() || defender == player || PartyManager.getInstance().inSameParty(player, defender) || Users.getProfile(defender).getGodMode()) { return false; } @@ -528,9 +501,7 @@ public class Combat { } } else if (entity instanceof Tameable) { - Tameable pet = (Tameable) entity; - - if (Misc.isFriendlyPet(player, pet)) { + if (Misc.isFriendlyPet(player, (Tameable) entity)) { return false; } } diff --git a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java index eb6944e44..f43258640 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java @@ -60,11 +60,7 @@ public class ArcheryManager extends SkillManager { * @param event The event to modify. */ public void skillShot(EntityDamageEvent event) { - if (Misc.isNPCPlayer(player) || !Permissions.archeryBonus(player)) { - return; - } - - if (skillLevel >= Archery.skillShotIncreaseLevel) { + if (skillLevel >= Archery.skillShotIncreaseLevel && Permissions.archeryBonus(player)) { SkillShotEventHandler eventHandler = new SkillShotEventHandler(this, event); eventHandler.calculateDamageBonus(); diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java b/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java index fd13e4f6f..fd77802d2 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.skills.unarmed; import com.gmail.nossr50.config.AdvancedConfig; +import com.gmail.nossr50.config.Config; public class Unarmed { public static int ironArmMaxBonusDamage = AdvancedConfig.getInstance().getIronArmMaxBonus(); @@ -15,5 +16,8 @@ public class Unarmed { public static double ironGripMaxChance = AdvancedConfig.getInstance().getIronGripChanceMax(); public static int ironGripMaxBonusLevel = AdvancedConfig.getInstance().getIronGripMaxBonusLevel(); + public static boolean pvpEnabled = Config.getInstance().getUnarmedPVP(); + public static boolean pveEnabled = Config.getInstance().getUnarmedPVE(); + public static double berserkDamageModifier = 1.5; } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java index 8ab66618a..4a1bafb0f 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -49,9 +49,6 @@ public class UnarmedManager extends SkillManager { * @param event The event to modify */ public void deflectCheck(EntityDamageEvent event) { - if (player == null) - return; - if (!Permissions.deflect(player)) { return; }