Java 类org.bukkit.craftbukkit.entity.CraftEntity 实例源码

项目:Thermos    文件:CustomProjectileEntity.java   
@Override
public LivingEntity _INVALID_getShooter() {
    if (shooter instanceof LivingEntity) { return (LivingEntity)shooter; }
    if (shooter instanceof BlockProjectileSource)
    {
        Block block = ((BlockProjectileSource)shooter).getBlock();
        if(!(block.getWorld() instanceof WorldServer))return null;
        int x = block.getX(), y = block.getY(), z = block.getZ();
        WorldServer ws = (WorldServer)block.getWorld();
        EntityPlayerMP fake_dropper = new EntityPlayerMP(MinecraftServer.getServer(), ws, dropper, new ItemInWorldManager(MinecraftServer.getServer().worldServerForDimension(0)));
        fake_dropper.posX = x; fake_dropper.posY = y; fake_dropper.posZ = z;
        CraftEntity ce = org.bukkit.craftbukkit.entity.CraftEntity.getEntity(MinecraftServer.getServer().server, fake_dropper);
        if(ce instanceof LivingEntity) return (LivingEntity)ce;
        return null;
    } return null;
}
项目:CardinalPGM    文件:AllMobFilter.java   
@Override
public FilterState evaluate(final Object... objects) {
    boolean abstain = true;
    for (Object object : objects) {
        if (object instanceof Entity) {
            if (((CraftEntity)object).getHandle() instanceof EntityInsentient) {
                return allow ? FilterState.ALLOW : FilterState.DENY;
            }
            abstain = false;
        }
    }
    if (abstain) {
        return (getParent() == null ? ABSTAIN : getParent().evaluate(objects));
    }
    return allow ? FilterState.DENY : FilterState.ALLOW;
}
项目:SpigotSource    文件:Entity.java   
protected void p(Entity entity) {
    if (entity.bz() == this) {
        throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)");
    } else {
        // CraftBukkit start
        CraftEntity craft = (CraftEntity) entity.getBukkitEntity().getVehicle();
        Entity orig = craft == null ? null : craft.getHandle();
        if (getBukkitEntity() instanceof Vehicle && entity.getBukkitEntity() instanceof LivingEntity) {
            VehicleExitEvent event = new VehicleExitEvent(
                    (Vehicle) getBukkitEntity(),
                    (LivingEntity) entity.getBukkitEntity()
            );
            Bukkit.getPluginManager().callEvent(event);
            CraftEntity craftn = (CraftEntity) entity.getBukkitEntity().getVehicle();
            Entity n = craftn == null ? null : craftn.getHandle();
            if (event.isCancelled() || n != orig) {
                return;
            }
        }
        // CraftBukkit end
        Bukkit.getPluginManager().callEvent( new org.spigotmc.event.entity.EntityDismountEvent(entity.getBukkitEntity(), this.getBukkitEntity())); // Spigot
        this.passengers.remove(entity);
        entity.j = 60;
    }
}
项目:ProjectAres    文件:NMSHacks.java   
public static String getTranslationKey(Entity entity) {
    if(entity instanceof TNTPrimed) {
        return "tile.tnt.name";
    } else if(entity instanceof Egg) {
        return "item.egg.name";
    } else {
        final String id = EntityTypes.b(((CraftEntity) entity).getHandle());
        return "entity." + (id != null ? id : "generic") + ".name";
    }
}
项目:Tweakkit-Server    文件:CraftEventFactory.java   
/**
 * Mob spawner event
 */
public static SpawnerSpawnEvent callSpawnerSpawnEvent(Entity spawnee, int spawnerX, int spawnerY, int spawnerZ) {
    org.bukkit.craftbukkit.entity.CraftEntity entity = spawnee.getBukkitEntity();
    BlockState state = entity.getWorld().getBlockAt(spawnerX, spawnerY, spawnerZ).getState();

    if (!(state instanceof CreatureSpawner)) {
        state = null;
    }

    SpawnerSpawnEvent event = new SpawnerSpawnEvent(entity, (CreatureSpawner) state);
    entity.getServer().getPluginManager().callEvent(event);
    return event;
}
项目:Cauldron    文件:Entity.java   
public CraftEntity getBukkitEntity()
{
    if (this.bukkitEntity == null)
    {
        this.bukkitEntity = CraftEntity.getEntity(this.worldObj.getServer(), this);
    }

    return this.bukkitEntity;
}
项目:CardinalPGM    文件:MobFilter.java   
@Override
public FilterState evaluate(Object... objects) {
    for (Object object : objects) {
        if (object instanceof Entity) {
            if (((CraftEntity)object).getHandle() instanceof EntityInsentient && mobType.equals(((CraftEntity) object).getType()))
                return ALLOW;
            else
                return DENY;
        }
    }
    return (getParent() == null ? ABSTAIN : getParent().evaluate(objects));
}
项目:SpigotSource    文件:CraftEventFactory.java   
/**
 * Mob spawner event.
 */
public static SpawnerSpawnEvent callSpawnerSpawnEvent(Entity spawnee, BlockPosition pos) {
    org.bukkit.craftbukkit.entity.CraftEntity entity = spawnee.getBukkitEntity();
    BlockState state = entity.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()).getState();
    if (!(state instanceof org.bukkit.block.CreatureSpawner)) {
        state = null;
    }

    SpawnerSpawnEvent event = new SpawnerSpawnEvent(entity, (org.bukkit.block.CreatureSpawner) state);
    entity.getServer().getPluginManager().callEvent(event);
    return event;
}
项目:ProjectAres    文件:NMSHacks.java   
private static EntityTrackerEntry getTrackerEntry(Entity entity) {
    return getTrackerEntry(((CraftEntity) entity).getHandle());
}
项目:ProjectAres    文件:NMSHacks.java   
private static List<DataWatcher.Item<?>> copyEntityMetadata(Entity entity) {
    final List<DataWatcher.Item<?>> metadata = ((CraftEntity) entity).getHandle().getDataWatcher().c();
    DataWatcher.deepCopy(metadata);
    return metadata;
}
项目:ProjectAres    文件:NMSHacks.java   
public static Packet entityMetadataPacket(int entityId, Entity entity, boolean complete) {
    return entityMetadataPacket(entityId, ((CraftEntity) entity).getHandle(), complete);
}
项目:ProjectAres    文件:NMSHacks.java   
public static void createExplosion(Entity entity, Location loc, float power, boolean fire, boolean destroy) {
    ((CraftWorld) loc.getWorld()).getHandle().createExplosion(((CraftEntity) entity).getHandle(), loc.getX(), loc.getY(), loc.getZ(), power, fire, destroy);
}
项目:CraftBukkit    文件:Entity.java   
public CraftEntity getBukkitEntity() {
    if (this.bukkitEntity == null) {
        this.bukkitEntity = CraftEntity.getEntity(this.world.getServer(), this);
    }
    return this.bukkitEntity;
}
项目:CraftBukkit    文件:EntitySlime.java   
protected void bq() {
    this.w();
    // CraftBukkit start
    Entity entityhuman = this.world.findNearbyVulnerablePlayer(this, 16.0D); // EntityHuman -> Entity
    EntityTargetEvent event = null;

    if (entityhuman != null && !entityhuman.equals(lastTarget)) {
        event = CraftEventFactory.callEntityTargetEvent(this, entityhuman, EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
    } else if (lastTarget != null && entityhuman == null) {
        event = CraftEventFactory.callEntityTargetEvent(this, entityhuman, EntityTargetEvent.TargetReason.FORGOT_TARGET);
    }

    if (event != null && !event.isCancelled()) {
        entityhuman = event.getTarget() == null ? null : ((CraftEntity) event.getTarget()).getHandle();
    }

    this.lastTarget = entityhuman;
    // CraftBukkit end

    if (entityhuman != null) {
        this.a(entityhuman, 10.0F, 20.0F);
    }

    if (this.onGround && this.jumpDelay-- <= 0) {
        this.jumpDelay = this.bR();
        if (entityhuman != null) {
            this.jumpDelay /= 3;
        }

        this.bc = true;
        if (this.bY()) {
            this.makeSound(this.bV(), this.bf(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) * 0.8F);
        }

        this.bd = 1.0F - this.random.nextFloat() * 2.0F;
        this.be = (float) (1 * this.getSize());
    } else {
        this.bc = false;
        if (this.onGround) {
            this.bd = this.be = 0.0F;
        }
    }
}
项目:CraftBukkit    文件:PathfinderGoalTarget.java   
protected boolean a(EntityLiving entityliving, boolean flag) {
    if (entityliving == null) {
        return false;
    } else if (entityliving == this.c) {
        return false;
    } else if (!entityliving.isAlive()) {
        return false;
    } else if (!this.c.a(entityliving.getClass())) {
        return false;
    } else {
        if (this.c instanceof EntityOwnable && StringUtils.isNotEmpty(((EntityOwnable) this.c).getOwnerUUID())) {
            if (entityliving instanceof EntityOwnable && ((EntityOwnable) this.c).getOwnerUUID().equals(((EntityOwnable) entityliving).getOwnerUUID())) {
                return false;
            }

            if (entityliving == ((EntityOwnable) this.c).getOwner()) {
                return false;
            }
        } else if (entityliving instanceof EntityHuman && !flag && ((EntityHuman) entityliving).abilities.isInvulnerable) {
            return false;
        }

        if (!this.c.b(MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
            return false;
        } else if (this.d && !this.c.getEntitySenses().canSee(entityliving)) {
            return false;
        } else {
            if (this.a) {
                if (--this.e <= 0) {
                    this.b = 0;
                }

                if (this.b == 0) {
                    this.b = this.a(entityliving) ? 1 : 2;
                }

                if (this.b == 2) {
                    return false;
                }
            }

            // CraftBukkit start - Check all the different target goals for the reason, default to RANDOM_TARGET
            EntityTargetEvent.TargetReason reason = EntityTargetEvent.TargetReason.RANDOM_TARGET;

            if (this instanceof PathfinderGoalDefendVillage) {
                reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE;
            } else if (this instanceof PathfinderGoalHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY;
            } else if (this instanceof PathfinderGoalNearestAttackableTarget) {
                if (entityliving instanceof EntityHuman) {
                    reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER;
                }
            } else if (this instanceof PathfinderGoalOwnerHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER;
            } else if (this instanceof PathfinderGoalOwnerHurtTarget) {
                reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET;
            }

            org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(this.c, entityliving, reason);
            if (event.isCancelled() || event.getTarget() == null) {
                this.c.setGoalTarget(null);
                return false;
            } else if (entityliving.getBukkitEntity() != event.getTarget()) {
                this.c.setGoalTarget((EntityLiving) ((CraftEntity) event.getTarget()).getHandle());
            }
            if (this.c instanceof EntityCreature) {
                ((EntityCreature) this.c).target = ((CraftEntity) event.getTarget()).getHandle();
            }
            // CraftBukkit end

            return true;
        }
    }
}
项目:Almura-Server    文件:Entity.java   
public CraftEntity getBukkitEntity() {
    if (this.bukkitEntity == null) {
        this.bukkitEntity = CraftEntity.getEntity(this.world.getServer(), this);
    }
    return this.bukkitEntity;
}
项目:Almura-Server    文件:EntitySlime.java   
protected void bl() {
    this.u();
    // CraftBukkit start
    Entity entityhuman = this.world.findNearbyVulnerablePlayer(this, 16.0D); // EntityHuman -> Entity
    EntityTargetEvent event = null;

    if (entityhuman != null && !entityhuman.equals(lastTarget)) {
        event = CraftEventFactory.callEntityTargetEvent(this, entityhuman, EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
    } else if (lastTarget != null && entityhuman == null) {
        event = CraftEventFactory.callEntityTargetEvent(this, entityhuman, EntityTargetEvent.TargetReason.FORGOT_TARGET);
    }

    if (event != null && !event.isCancelled()) {
        entityhuman = event.getTarget() == null ? null : ((CraftEntity) event.getTarget()).getHandle();
    }

    this.lastTarget = entityhuman;
    // CraftBukkit end

    if (entityhuman != null) {
        this.a(entityhuman, 10.0F, 20.0F);
    }

    if (this.onGround && this.jumpDelay-- <= 0) {
        this.jumpDelay = this.bL();
        if (entityhuman != null) {
            this.jumpDelay /= 3;
        }

        this.bd = true;
        if (this.bS()) {
            this.makeSound(this.bP(), this.ba(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) * 0.8F);
        }

        this.be = 1.0F - this.random.nextFloat() * 2.0F;
        this.bf = (float) (1 * this.getSize());
    } else {
        this.bd = false;
        if (this.onGround) {
            this.be = this.bf = 0.0F;
        }
    }
}
项目:Almura-Server    文件:PathfinderGoalTarget.java   
protected boolean a(EntityLiving entityliving, boolean flag) {
    if (entityliving == null) {
        return false;
    } else if (entityliving == this.c) {
        return false;
    } else if (!entityliving.isAlive()) {
        return false;
    } else if (!this.c.a(entityliving.getClass())) {
        return false;
    } else {
        if (this.c instanceof EntityOwnable && StringUtils.isNotEmpty(((EntityOwnable) this.c).getOwnerName())) {
            if (entityliving instanceof EntityOwnable && ((EntityOwnable) this.c).getOwnerName().equals(((EntityOwnable) entityliving).getOwnerName())) {
                return false;
            }

            if (entityliving == ((EntityOwnable) this.c).getOwner()) {
                return false;
            }
        } else if (entityliving instanceof EntityHuman && !flag && ((EntityHuman) entityliving).abilities.isInvulnerable) {
            return false;
        }

        if (!this.c.b(MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
            return false;
        } else if (this.d && !this.c.getEntitySenses().canSee(entityliving)) {
            return false;
        } else {
            if (this.a) {
                if (--this.e <= 0) {
                    this.b = 0;
                }

                if (this.b == 0) {
                    this.b = this.a(entityliving) ? 1 : 2;
                }

                if (this.b == 2) {
                    return false;
                }
            }

            // CraftBukkit start - Check all the different target goals for the reason, default to RANDOM_TARGET
            EntityTargetEvent.TargetReason reason = EntityTargetEvent.TargetReason.RANDOM_TARGET;

            if (this instanceof PathfinderGoalDefendVillage) {
                reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE;
            } else if (this instanceof PathfinderGoalHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY;
            } else if (this instanceof PathfinderGoalNearestAttackableTarget) {
                if (entityliving instanceof EntityHuman) {
                    reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER;
                }
            } else if (this instanceof PathfinderGoalOwnerHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER;
            } else if (this instanceof PathfinderGoalOwnerHurtTarget) {
                reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET;
            }

            org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(this.c, entityliving, reason);
            if (event.isCancelled() || event.getTarget() == null) {
                this.c.setGoalTarget(null);
                return false;
            } else if (entityliving.getBukkitEntity() != event.getTarget()) {
                this.c.setGoalTarget((EntityLiving) ((CraftEntity) event.getTarget()).getHandle());
            }
            if (this.c instanceof EntityCreature) {
                ((EntityCreature) this.c).target = ((CraftEntity) event.getTarget()).getHandle();
            }
            // CraftBukkit end

            return true;
        }
    }
}
项目:Tweakkit-Server    文件:Entity.java   
public CraftEntity getBukkitEntity() {
    if (this.bukkitEntity == null) {
        this.bukkitEntity = CraftEntity.getEntity(this.world.getServer(), this);
    }
    return this.bukkitEntity;
}
项目:Tweakkit-Server    文件:EntitySlime.java   
protected void bq() {
    this.w();
    // CraftBukkit start
    Entity entityhuman = this.world.findNearbyVulnerablePlayer(this, 16.0D); // EntityHuman -> Entity
    EntityTargetEvent event = null;

    if (entityhuman != null && !entityhuman.equals(lastTarget)) {
        event = CraftEventFactory.callEntityTargetEvent(this, entityhuman, EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
    } else if (lastTarget != null && entityhuman == null) {
        event = CraftEventFactory.callEntityTargetEvent(this, entityhuman, EntityTargetEvent.TargetReason.FORGOT_TARGET);
    }

    if (event != null && !event.isCancelled()) {
        entityhuman = event.getTarget() == null ? null : ((CraftEntity) event.getTarget()).getHandle();
    }

    this.lastTarget = entityhuman;
    // CraftBukkit end

    if (entityhuman != null) {
        this.a(entityhuman, 10.0F, 20.0F);
    }

    if (this.onGround && this.jumpDelay-- <= 0) {
        this.jumpDelay = this.bR();
        if (entityhuman != null) {
            this.jumpDelay /= 3;
        }

        this.bc = true;
        if (this.bY()) {
            this.makeSound(this.bV(), this.bf(), ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F) * 0.8F);
        }

        this.bd = 1.0F - this.random.nextFloat() * 2.0F;
        this.be = (float) (1 * this.getSize());
    } else {
        this.bc = false;
        if (this.onGround) {
            this.bd = this.be = 0.0F;
        }
    }
}
项目:Tweakkit-Server    文件:PathfinderGoalTarget.java   
protected boolean a(EntityLiving entityliving, boolean flag) {
    if (entityliving == null) {
        return false;
    } else if (entityliving == this.c) {
        return false;
    } else if (!entityliving.isAlive()) {
        return false;
    } else if (!this.c.a(entityliving.getClass())) {
        return false;
    } else {
        if (this.c instanceof EntityOwnable && StringUtils.isNotEmpty(((EntityOwnable) this.c).getOwnerUUID())) {
            if (entityliving instanceof EntityOwnable && ((EntityOwnable) this.c).getOwnerUUID().equals(((EntityOwnable) entityliving).getOwnerUUID())) {
                return false;
            }

            if (entityliving == ((EntityOwnable) this.c).getOwner()) {
                return false;
            }
        } else if (entityliving instanceof EntityHuman && !flag && ((EntityHuman) entityliving).abilities.isInvulnerable) {
            return false;
        }

        if (!this.c.b(MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
            return false;
        } else if (this.d && !this.c.getEntitySenses().canSee(entityliving)) {
            return false;
        } else {
            if (this.a) {
                if (--this.e <= 0) {
                    this.b = 0;
                }

                if (this.b == 0) {
                    this.b = this.a(entityliving) ? 1 : 2;
                }

                if (this.b == 2) {
                    return false;
                }
            }

            // CraftBukkit start - Check all the different target goals for the reason, default to RANDOM_TARGET
            EntityTargetEvent.TargetReason reason = EntityTargetEvent.TargetReason.RANDOM_TARGET;

            if (this instanceof PathfinderGoalDefendVillage) {
                reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE;
            } else if (this instanceof PathfinderGoalHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY;
            } else if (this instanceof PathfinderGoalNearestAttackableTarget) {
                if (entityliving instanceof EntityHuman) {
                    reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER;
                }
            } else if (this instanceof PathfinderGoalOwnerHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER;
            } else if (this instanceof PathfinderGoalOwnerHurtTarget) {
                reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET;
            }

            org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(this.c, entityliving, reason);
            if (event.isCancelled() || event.getTarget() == null) {
                this.c.setGoalTarget(null);
                return false;
            } else if (entityliving.getBukkitEntity() != event.getTarget()) {
                this.c.setGoalTarget((EntityLiving) ((CraftEntity) event.getTarget()).getHandle());
            }
            if (this.c instanceof EntityCreature) {
                ((EntityCreature) this.c).target = ((CraftEntity) event.getTarget()).getHandle();
            }
            // CraftBukkit end

            return true;
        }
    }
}
项目:Cauldron    文件:EntitySlime.java   
protected void updateEntityActionState()
{
    this.despawnEntity();
    // CraftBukkit start
    Entity entityplayer = this.worldObj.getClosestVulnerablePlayerToEntity(this, 16.0D); // EntityPlayer -> Entity
    EntityTargetEvent event = null;

    if (entityplayer != null && !entityplayer.equals(lastTarget))
    {
        event = CraftEventFactory.callEntityTargetEvent(this, entityplayer, EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
    }
    else if (lastTarget != null && entityplayer == null)
    {
        event = CraftEventFactory.callEntityTargetEvent(this, entityplayer, EntityTargetEvent.TargetReason.FORGOT_TARGET);
    }

    if (event != null && !event.isCancelled())
    {
        entityplayer = event.getTarget() == null ? null : ((CraftEntity) event.getTarget()).getHandle();
    }

    this.lastTarget = entityplayer;
    // CraftBukkit end

    if (entityplayer != null)
    {
        this.faceEntity(entityplayer, 10.0F, 20.0F);
    }

    if (this.onGround && this.slimeJumpDelay-- <= 0)
    {
        this.slimeJumpDelay = this.getJumpDelay();

        if (entityplayer != null)
        {
            this.slimeJumpDelay /= 3;
        }

        this.isJumping = true;

        if (this.makesSoundOnJump())
        {
            this.playSound(this.getJumpSound(), this.getSoundVolume(), ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 0.8F);
        }

        this.moveStrafing = 1.0F - this.rand.nextFloat() * 2.0F;
        this.moveForward = (float)(1 * this.getSlimeSize());
    }
    else
    {
        this.isJumping = false;

        if (this.onGround)
        {
            this.moveStrafing = this.moveForward = 0.0F;
        }
    }
}
项目:SpigotSource    文件:Entity.java   
public CraftEntity getBukkitEntity() {
    if (bukkitEntity == null) {
        bukkitEntity = CraftEntity.getEntity(world.getServer(), this);
    }
    return bukkitEntity;
}
项目:Craft-city    文件:Entity.java   
public CraftEntity getBukkitEntity() {
    if (this.bukkitEntity == null) {
        this.bukkitEntity = CraftEntity.getEntity(this.world.getServer(), this);
    }
    return this.bukkitEntity;
}
项目:Craft-city    文件:PathfinderGoalTarget.java   
protected boolean a(EntityLiving entityliving, boolean flag) {
    if (entityliving == null) {
        return false;
    } else if (entityliving == this.d) {
        return false;
    } else if (!entityliving.isAlive()) {
        return false;
    } else if (!this.d.a(entityliving.getClass())) {
        return false;
    } else {
        if (this.d instanceof EntityTameableAnimal && ((EntityTameableAnimal) this.d).isTamed()) {
            if (entityliving instanceof EntityTameableAnimal && ((EntityTameableAnimal) entityliving).isTamed()) {
                return false;
            }

            if (entityliving == ((EntityTameableAnimal) this.d).getOwner()) {
                return false;
            }
        } else if (entityliving instanceof EntityHuman && !flag && ((EntityHuman) entityliving).abilities.isInvulnerable) {
            return false;
        }

        if (!this.d.d(MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
            return false;
        } else if (this.f && !this.d.aD().canSee(entityliving)) {
            return false;
        } else {
            if (this.a) {
                if (--this.c <= 0) {
                    this.b = 0;
                }

                if (this.b == 0) {
                    this.b = this.a(entityliving) ? 1 : 2;
                }

                if (this.b == 2) {
                    return false;
                }
            }

            // CraftBukkit start - Check all the different target goals for the reason, default to RANDOM_TARGET
            EntityTargetEvent.TargetReason reason = EntityTargetEvent.TargetReason.RANDOM_TARGET;

            if (this instanceof PathfinderGoalDefendVillage) {
                reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE;
            } else if (this instanceof PathfinderGoalHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY;
            } else if (this instanceof PathfinderGoalNearestAttackableTarget) {
                if (entityliving instanceof EntityHuman) {
                    reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER;
                }
            } else if (this instanceof PathfinderGoalOwnerHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER;
            } else if (this instanceof PathfinderGoalOwnerHurtTarget) {
                reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET;
            }

            org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(this.d, entityliving, reason);
            if (event.isCancelled() || event.getTarget() == null) {
                this.d.setGoalTarget(null);
                return false;
            } else if (entityliving.getBukkitEntity() != event.getTarget()) {
                this.d.setGoalTarget((EntityLiving) ((CraftEntity) event.getTarget()).getHandle());
            }
            if (this.d instanceof EntityCreature) {
                ((EntityCreature) this.d).target = ((CraftEntity) event.getTarget()).getHandle();
            }
            // CraftBukkit end

            return true;
        }
    }
}