diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 8ac7704c5..92c373db5 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.Tameable; -import org.bukkit.entity.Wolf; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -105,12 +104,15 @@ public class EntityListener implements Listener { } Entity entity = event.getEntity(); - EntityType type = entity.getType(); DamageCause cause = event.getCause(); - - switch(type) { - case PLAYER: + if (!(entity instanceof LivingEntity)) { + return; + } + + LivingEntity lEntity = (LivingEntity) entity; + + if (lEntity instanceof Player) { /* Check for invincibility */ Player player = (Player) entity; PlayerProfile PP = Users.getProfile(player); @@ -132,18 +134,12 @@ public class EntityListener implements Listener { PP.setRecentlyHurt(System.currentTimeMillis()); } } - break; + } else if (lEntity instanceof Tameable) { + Tameable pet = (Tameable) lEntity; - case WOLF: - Wolf wolf = (Wolf) entity; - - if ((!Misc.isInvincible(wolf, event)) && wolf.isTamed() && (wolf.getOwner() instanceof Player)) { + if ((!Misc.isInvincible(lEntity, event)) && pet.isTamed() && (pet.getOwner() instanceof Player)) { Taming.preventDamage(event); } - break; - - default: - break; } } diff --git a/src/main/java/com/gmail/nossr50/skills/combat/Axes.java b/src/main/java/com/gmail/nossr50/skills/combat/Axes.java index 0c63218e3..32adac9b1 100644 --- a/src/main/java/com/gmail/nossr50/skills/combat/Axes.java +++ b/src/main/java/com/gmail/nossr50/skills/combat/Axes.java @@ -6,7 +6,7 @@ import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.entity.Wolf; +import org.bukkit.entity.Tameable; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -51,11 +51,11 @@ public class Axes { public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) { Entity entity = event.getEntity(); - if (entity instanceof Wolf) { - Wolf wolf = (Wolf) entity; + if (entity instanceof Tameable) { + Tameable pet = (Tameable) entity; - if (wolf.isTamed()) { - AnimalTamer tamer = wolf.getOwner(); + if (pet.isTamed()) { + AnimalTamer tamer = pet.getOwner(); if (tamer instanceof Player) { Player owner = (Player) tamer; diff --git a/src/main/java/com/gmail/nossr50/skills/combat/Swords.java b/src/main/java/com/gmail/nossr50/skills/combat/Swords.java index 7c01482ca..a6848892e 100644 --- a/src/main/java/com/gmail/nossr50/skills/combat/Swords.java +++ b/src/main/java/com/gmail/nossr50/skills/combat/Swords.java @@ -6,6 +6,7 @@ import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Tameable; import org.bukkit.entity.Wolf; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -34,11 +35,11 @@ public class Swords { */ public static void bleedCheck(Player attacker, LivingEntity entity, mcMMO plugin) { - if (entity instanceof Wolf) { - Wolf wolf = (Wolf) entity; + if (entity instanceof Tameable) { + Tameable pet = (Tameable) entity; - if (wolf.isTamed()) { - AnimalTamer tamer = wolf.getOwner(); + if (pet.isTamed()) { + AnimalTamer tamer = pet.getOwner(); if (tamer instanceof Player) { Player owner = (Player) tamer; diff --git a/src/main/java/com/gmail/nossr50/skills/combat/Taming.java b/src/main/java/com/gmail/nossr50/skills/combat/Taming.java index 550c4f92e..27f603562 100644 --- a/src/main/java/com/gmail/nossr50/skills/combat/Taming.java +++ b/src/main/java/com/gmail/nossr50/skills/combat/Taming.java @@ -132,6 +132,10 @@ public class Taming { final int THICK_FUR_MODIFIER = 2; final int SHOCK_PROOF_MODIFIER = 6; + if (!(event.getEntity() instanceof Wolf)) { + return; + } + DamageCause cause = event.getCause(); Wolf wolf = (Wolf) event.getEntity(); Player master = (Player) wolf.getOwner(); diff --git a/src/main/java/com/gmail/nossr50/util/Combat.java b/src/main/java/com/gmail/nossr50/util/Combat.java index 1271394d7..6836a2d9c 100644 --- a/src/main/java/com/gmail/nossr50/util/Combat.java +++ b/src/main/java/com/gmail/nossr50/util/Combat.java @@ -3,12 +3,13 @@ package com.gmail.nossr50.util; import org.bukkit.Material; import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Animals; -import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.IronGolem; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.entity.Tameable; import org.bukkit.entity.Wolf; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; @@ -51,11 +52,11 @@ public class Combat { Entity damager = event.getDamager(); LivingEntity target = (LivingEntity) event.getEntity(); - EntityType damagerType = damager.getType(); - EntityType targetType = target.getType(); - switch (damagerType) { - case PLAYER: + boolean targetIsPlayer = target instanceof Player; + boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false; + + if (damager instanceof Player) { Player attacker = (Player) event.getDamager(); ItemStack itemInHand = attacker.getItemInHand(); PlayerProfile PPa = Users.getProfile(attacker); @@ -64,13 +65,13 @@ public class Combat { if (ItemChecks.isSword(itemInHand) && permInstance.swords(attacker)) { if (!configInstance.getSwordsPVP()) { - if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + if (targetIsPlayer || targetIsTamedPet) { return; } } if (!configInstance.getSwordsPVE()) { - if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + if (!targetIsPlayer || !targetIsTamedPet) { return; } } @@ -88,13 +89,13 @@ public class Combat { } else if (ItemChecks.isAxe(itemInHand) && permInstance.axes(attacker)) { if (!configInstance.getAxesPVP()) { - if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + if (targetIsPlayer || targetIsTamedPet) { return; } } if (!configInstance.getAxesPVE()) { - if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + if (!targetIsPlayer || !targetIsTamedPet) { return; } } @@ -119,13 +120,13 @@ public class Combat { } else if (itemInHand.getType().equals(Material.AIR) && permInstance.unarmed(attacker)) { if (!configInstance.getUnarmedPVP()) { - if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + if (targetIsPlayer || targetIsTamedPet) { return; } } if (!configInstance.getUnarmedPVE()) { - if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + if (!targetIsPlayer || !targetIsTamedPet) { return; } } @@ -138,7 +139,7 @@ public class Combat { event.setDamage((int) (event.getDamage() * 1.5)); } - if (targetType.equals(EntityType.PLAYER) && permInstance.disarm(attacker)) { + if (targetIsPlayer && permInstance.disarm(attacker)) { Unarmed.disarmProcCheck(attacker, (Player) target); } @@ -147,9 +148,7 @@ public class Combat { else if (itemInHand.getType().equals(Material.BONE) && permInstance.beastLore(attacker)) { Taming.beastLore(event, target, attacker); } - break; - - case WOLF: + } else if (damager instanceof Tameable) { Wolf wolf = (Wolf) damager; if (wolf.isTamed() && wolf.getOwner() instanceof Player) { @@ -157,13 +156,13 @@ public class Combat { PlayerProfile PPo = Users.getProfile(master); if (!configInstance.getTamingPVP()) { - if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + if (targetIsPlayer || targetIsTamedPet) { return; } } if (!configInstance.getTamingPVE()) { - if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + if (!targetIsPlayer || !targetIsTamedPet) { return; } } @@ -184,39 +183,36 @@ public class Combat { startGainXp(master, PPo, target, SkillType.TAMING, plugin); } } - break; - - case ARROW: - if (!configInstance.getArcheryPVP() && ((Arrow) damager).getShooter().getType().equals(EntityType.PLAYER)) { - if (targetType.equals(EntityType.PLAYER) || (targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + } else if (damager instanceof Projectile) { + if (!configInstance.getArcheryPVP() && ((Projectile) damager).getShooter().getType().equals(EntityType.PLAYER)) { + if (targetIsPlayer || targetIsTamedPet) { return; } } - if (!configInstance.getArcheryPVE() && !((Arrow) damager).getShooter().getType().equals(EntityType.PLAYER)) { - if (!targetType.equals(EntityType.PLAYER) || !(targetType.equals(EntityType.WOLF) && ((Wolf) target).isTamed())) { + if (!configInstance.getArcheryPVE() && !((Projectile) damager).getShooter().getType().equals(EntityType.PLAYER)) { + if (!targetIsPlayer || !targetIsTamedPet) { return; } } archeryCheck(event, plugin); - break; } - if (targetType.equals(EntityType.PLAYER)) { - if (configInstance.getSwordsPVP() && damagerType.equals(EntityType.PLAYER)) { + if (target instanceof Player) { + if (configInstance.getSwordsPVP() && damager instanceof Player) { Swords.counterAttackChecks(event); } - if (configInstance.getSwordsPVE() && !damagerType.equals(EntityType.PLAYER)) { + if (configInstance.getSwordsPVE() && !(damager instanceof Player)) { Swords.counterAttackChecks(event); } - if (configInstance.getAcrobaticsPVP() && damagerType.equals(EntityType.PLAYER)) { + if (configInstance.getAcrobaticsPVP() && damager instanceof Player) { Acrobatics.dodgeChecks(event); } - if (configInstance.getAcrobaticsPVE() && !damagerType.equals(EntityType.PLAYER)) { + if (configInstance.getAcrobaticsPVE() && !(damager instanceof Player)) { Acrobatics.dodgeChecks(event); } } @@ -248,7 +244,7 @@ public class Combat { * @param pluginx mcMMO plugin instance */ public static void archeryCheck(EntityDamageByEntityEvent event, mcMMO pluginx) { - Arrow arrow = (Arrow) event.getDamager(); + Projectile arrow = (Projectile) event.getDamager(); LivingEntity shooter = arrow.getShooter(); LivingEntity target = (LivingEntity) event.getEntity(); @@ -388,19 +384,7 @@ public class Combat { break; } - switch (entity.getType()) { - case WOLF: - AnimalTamer tamer = ((Wolf) entity).getOwner(); - - if (tamer instanceof Player) { - if (tamer.equals(attacker) || Party.getInstance().inSameParty(attacker, (Player) tamer)) { - continue; - } - } - - break; - - case PLAYER: + if (entity instanceof Player) { Player defender = (Player) entity; if (!target.getWorld().getPVP()) { @@ -420,11 +404,14 @@ public class Combat { if (playerProfile.getGodMode()) { continue; } + } else if (entity instanceof Tameable) { + AnimalTamer tamer = ((Tameable) entity).getOwner(); - break; - - default: - break; + if (tamer instanceof Player) { + if (tamer.equals(attacker) || Party.getInstance().inSameParty(attacker, (Player) tamer)) { + continue; + } + } } switch (type) {