diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 55dbbda79..fb18dccf1 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -124,7 +124,7 @@ public class EntityListener implements Listener { if (defender instanceof LivingEntity) { LivingEntity livingDefender = (LivingEntity) defender; - if (!Misc.isInvincible(livingDefender, event)) { + if (!CombatTools.isInvincible(livingDefender, event)) { CombatTools.combatChecks(event, attacker, livingDefender); } } @@ -166,7 +166,7 @@ public class EntityListener implements Listener { return; } - if (!Misc.isInvincible(player, event)) { + if (!CombatTools.isInvincible(player, event)) { if (cause == DamageCause.FALL && player.getItemInHand().getType() != Material.ENDER_PEARL && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player)) { AcrobaticsManager acrobaticsManager = new AcrobaticsManager(mcMMOPlayer); acrobaticsManager.rollCheck(event); @@ -185,7 +185,7 @@ public class EntityListener implements Listener { Tameable pet = (Tameable) livingEntity; AnimalTamer owner = pet.getOwner(); - if ((!Misc.isInvincible(livingEntity, event)) && pet.isTamed() && owner instanceof Player && pet instanceof Wolf) { + if ((!CombatTools.isInvincible(livingEntity, event)) && pet.isTamed() && owner instanceof Player && pet instanceof Wolf) { TamingManager tamingManager = new TamingManager(Users.getPlayer((Player) owner)); tamingManager.preventDamage(event); } @@ -357,7 +357,7 @@ public class EntityListener implements Listener { Player player = (Player) event.getTarget(); Tameable tameable = (Tameable) event.getEntity(); - if (Misc.isFriendlyPet(player, tameable)) { + if (CombatTools.isFriendlyPet(player, tameable)) { // isFriendlyPet ensures that the Tameable is: Tamed, owned by a player, and the owner is in the same party // So we can make some assumptions here, about our casting and our check Player owner = (Player) tameable.getOwner(); diff --git a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java index 21559cff1..f32788e19 100644 --- a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java +++ b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.skills.utilities; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Animals; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; @@ -604,7 +605,7 @@ public final class CombatTools { } } else if (entity instanceof Tameable) { - if (Misc.isFriendlyPet(player, (Tameable) entity)) { + if (isFriendlyPet(player, (Tameable) entity)) { // isFriendlyPet ensures that the Tameable is: Tamed, owned by a player, and the owner is in the same party // So we can make some assumptions here, about our casting and our check Player owner = (Player) ((Tameable) entity).getOwner(); @@ -616,4 +617,47 @@ public final class CombatTools { return true; } + + /** + * Checks to see if an entity is currently invincible. + * + * @param le The LivingEntity to check + * @param event The event the entity is involved in + * @return true if the entity is invincible, false otherwise + */ + public static boolean isInvincible(LivingEntity le, EntityDamageEvent event) { + + /* + * So apparently if you do more damage to a LivingEntity than its last damage int you bypass the invincibility. + * So yeah, this is for that. + */ + if (le.getNoDamageTicks() > le.getMaximumNoDamageTicks() / 2.0F && event.getDamage() <= le.getLastDamage()) { + return true; + } + + return false; + } + + /** + * Checks to see if an entity is currently friendly toward a given player. + * + * @param attacker The player to check. + * @param pet The entity to check. + * @return true if the entity is friendly, false otherwise + */ + public static boolean isFriendlyPet(Player attacker, Tameable pet) { + if (pet.isTamed()) { + AnimalTamer tamer = pet.getOwner(); + + if (tamer instanceof Player) { + Player owner = (Player) tamer; + + if (owner == attacker || PartyManager.inSameParty(attacker, owner)) { + return true; + } + } + } + + return false; + } } diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 89b0e9d0e..1cf442c33 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -5,13 +5,9 @@ import java.util.Random; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.entity.Tameable; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.PluginManager; @@ -23,7 +19,6 @@ import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.items.McMMOItemSpawnEvent; import com.gmail.nossr50.mods.ModChecks; -import com.gmail.nossr50.party.PartyManager; public final class Misc { private static Random random = new Random(); @@ -43,22 +38,6 @@ public final class Misc { private Misc() {}; - public static boolean isFriendlyPet(Player attacker, Tameable pet) { - if (pet.isTamed()) { - AnimalTamer tamer = pet.getOwner(); - - if (tamer instanceof Player) { - Player owner = (Player) tamer; - - if (owner == attacker || PartyManager.inSameParty(attacker, owner)) { - return true; - } - } - } - - return false; - } - public static boolean isNPCEntity(Entity entity) { if (entity == null || entity.hasMetadata("NPC")) { return true; @@ -75,26 +54,6 @@ public final class Misc { return false; } - /** - * Checks to see if an entity is currently invincible. - * - * @param le The LivingEntity to check - * @param event The event the entity is involved in - * @return true if the entity is invincible, false otherwise - */ - public static boolean isInvincible(LivingEntity le, EntityDamageEvent event) { - - /* - * So apparently if you do more damage to a LivingEntity than its last damage int you bypass the invincibility. - * So yeah, this is for that. - */ - if (le.getNoDamageTicks() > le.getMaximumNoDamageTicks() / 2.0F && event.getDamage() <= le.getLastDamage()) { - return true; - } - - return false; - } - /** * Simulate a block break event. *