Java Code Examples for org.bukkit.event.entity.EntityTargetEvent#TargetReason

The following examples show how to use org.bukkit.event.entity.EntityTargetEvent#TargetReason . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BehaviourGoalMeleeAttack.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean shouldContinue() {
    LivingEntity target = this.getControllableEntity().getTarget();

    // CraftBukkit start
    EntityTargetEvent.TargetReason reason = this.getControllableEntity().getTarget() == null ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
    if (this.getControllableEntity().getTarget() == null || (this.getControllableEntity().getTarget() != null && !((CraftLivingEntity) this.getControllableEntity().getTarget()).getHandle().isAlive())) {
        org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callEntityTargetEvent(this.getHandle(), null, reason);
    }
    // CraftBukkit end

    if (target == null) {
        return false;
    }
    EntityLiving targetHandle = ((CraftLivingEntity) target).getHandle();
    return !targetHandle.isAlive() ? false : (!this.ignoreSight ? !NMSEntityUtil.getNavigation(this.getHandle()).g() : NMSEntityUtil.isInHomeArea(this.getHandle(), MathHelper.floor(targetHandle.locX), MathHelper.floor(targetHandle.locY), MathHelper.floor(targetHandle.locZ)));
}
 
Example 2
Source File: BehaviourGoalMeleeAttack.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean shouldContinue() {
    LivingEntity target = this.getControllableEntity().getTarget();

    // CraftBukkit start
    EntityTargetEvent.TargetReason reason = this.getControllableEntity().getTarget() == null ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
    if (this.getControllableEntity().getTarget() == null || (this.getControllableEntity().getTarget() != null && !((CraftLivingEntity) this.getControllableEntity().getTarget()).getHandle().isAlive())) {
        org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callEntityTargetEvent(this.getHandle(), null, reason);
    }
    // CraftBukkit end

    if (target == null) {
        return false;
    }
    EntityLiving targetHandle = ((CraftLivingEntity) target).getHandle();
    return !targetHandle.isAlive() ? false : (!this.ignoreSight ? !NMSEntityUtil.getNavigation(this.getHandle()).g() : NMSEntityUtil.isInHomeArea(this.getHandle(), MathHelper.floor(targetHandle.locX), MathHelper.floor(targetHandle.locY), MathHelper.floor(targetHandle.locZ)));
}
 
Example 3
Source File: BehaviourGoalMeleeAttack.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean shouldContinue() {
    LivingEntity target = this.getControllableEntity().getTarget();

    // CraftBukkit start
    EntityTargetEvent.TargetReason reason = this.getControllableEntity().getTarget() == null ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
    if (this.getControllableEntity().getTarget() == null || (this.getControllableEntity().getTarget() != null && !((CraftLivingEntity) this.getControllableEntity().getTarget()).getHandle().isAlive())) {
        org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callEntityTargetEvent(this.getHandle(), null, reason);
    }
    // CraftBukkit end

    if (target == null) {
        return false;
    }
    EntityLiving targetHandle = ((CraftLivingEntity) target).getHandle();
    return !targetHandle.isAlive() ? false : (!this.ignoreSight ? !NMSEntityUtil.getNavigation(this.getHandle()).g() : NMSEntityUtil.isInHomeArea(this.getHandle(), MathHelper.floor(targetHandle.locX), MathHelper.floor(targetHandle.locY), MathHelper.floor(targetHandle.locZ)));
}
 
Example 4
Source File: BehaviourGoalMeleeAttack.java    From EntityAPI with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean shouldContinue() {
    LivingEntity target = this.getControllableEntity().getTarget();

    // CraftBukkit start
    EntityTargetEvent.TargetReason reason = this.getControllableEntity().getTarget() == null ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
    if (this.getControllableEntity().getTarget() == null || (this.getControllableEntity().getTarget() != null && !((CraftLivingEntity) this.getControllableEntity().getTarget()).getHandle().isAlive())) {
        org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callEntityTargetEvent(this.getHandle(), null, reason);
    }
    // CraftBukkit end

    if (target == null) {
        return false;
    }
    EntityLiving targetHandle = ((CraftLivingEntity) target).getHandle();
    return !targetHandle.isAlive() ? false : (!this.ignoreSight ? !NMSEntityUtil.getNavigation(this.getHandle()).g() : NMSEntityUtil.isInHomeArea(this.getHandle(), MathHelper.floor(targetHandle.locX), MathHelper.floor(targetHandle.locY), MathHelper.floor(targetHandle.locZ)));
}
 
Example 5
Source File: BehaviourGoalRangedAttack.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void finish() {
    // CraftBukkit start
    EntityTargetEvent.TargetReason reason = this.target.isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
    CraftEventFactory.callEntityTargetEvent(this.getHandle(), null, reason);
    // CraftBukkit end
    this.target = null;
    this.inRangeTicks = 0;
    this.shootCooldown = -1;
}
 
Example 6
Source File: BehaviourGoalRangedAttack.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void finish() {
    // CraftBukkit start
    EntityTargetEvent.TargetReason reason = this.target.isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
    CraftEventFactory.callEntityTargetEvent(this.getHandle(), null, reason);
    // CraftBukkit end
    this.target = null;
    this.inRangeTicks = 0;
    this.shootCooldown = -1;
}
 
Example 7
Source File: BehaviourGoalRangedAttack.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void finish() {
    // CraftBukkit start
    EntityTargetEvent.TargetReason reason = this.target.isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
    CraftEventFactory.callEntityTargetEvent(this.getHandle(), null, reason);
    // CraftBukkit end
    this.target = null;
    this.inRangeTicks = 0;
    this.shootCooldown = -1;
}
 
Example 8
Source File: BehaviourGoalRangedAttack.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void finish() {
    // CraftBukkit start
    EntityTargetEvent.TargetReason reason = this.target.isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
    CraftEventFactory.callEntityTargetEvent(this.getHandle(), null, reason);
    // CraftBukkit end
    this.target = null;
    this.inRangeTicks = 0;
    this.shootCooldown = -1;
}
 
Example 9
Source File: BehaviourGoalTarget.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean isSuitableTarget(EntityLiving entityliving, boolean flag) {
    if (entityliving == null) {
        return false;
    } else if (entityliving == this.getHandle()) {
        return false;
    } else if (!entityliving.isAlive()) {
        return false;
    } else if (!this.canAttackClass(entityliving.getClass())) {
        return false;
    } else {
        if (this.getHandle() instanceof EntityOwnable && StringUtils.isNotEmpty(((EntityOwnable) this.getHandle()).getOwnerName())) {
            if (entityliving instanceof EntityOwnable && ((EntityOwnable) this.getHandle()).getOwnerName().equals(((EntityOwnable) entityliving).getOwnerName())) {
                return false;
            }

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

        if (!NMSEntityUtil.isInHomeArea(this.getHandle(), MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
            return false;
        } else if (this.checkSenses && !NMSEntityUtil.getEntitySenses(this.getHandle()).canSee(entityliving)) {
            return false;
        } else {
            if (this.useMelee) {
                if (--this.ticksAfterLastAttack <= 0) {
                    this.shouldAttack = 0;
                }

                if (this.shouldAttack == 0) {
                    this.shouldAttack = this.attack(entityliving) ? 1 : 2;
                }

                if (this.shouldAttack == 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 BehaviourGoalDefendVillage) {
                reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE;
            } else if (this instanceof BehaviourGoalHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY;
            } else if (this instanceof BehaviourGoalMoveTowardsNearestAttackableTarget) {
                if (entityliving instanceof EntityHuman) {
                    reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER;
                }
            } else if (this instanceof BehaviourGoalDefendTamer) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER;
            } else if (this instanceof BehaviourGoalHelpTamerTarget) {
                reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET;
            }

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

            return true;
        }
    }
}
 
Example 10
Source File: BehaviourGoalTarget.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean isSuitableTarget(EntityLiving entityliving, boolean flag) {
    if (entityliving == null) {
        return false;
    } else if (entityliving == this.getHandle()) {
        return false;
    } else if (!entityliving.isAlive()) {
        return false;
    } else if (!this.canAttackClass(entityliving.getClass())) {
        return false;
    } else {
        if (this.getHandle() instanceof EntityOwnable && StringUtils.isNotEmpty(((EntityOwnable) this.getHandle()).getOwnerName())) {
            if (entityliving instanceof EntityOwnable && ((EntityOwnable) this.getHandle()).getOwnerName().equals(((EntityOwnable) entityliving).getOwnerName())) {
                return false;
            }

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

        if (!NMSEntityUtil.isInHomeArea(this.getHandle(), MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
            return false;
        } else if (this.checkSenses && !NMSEntityUtil.getEntitySenses(this.getHandle()).canSee(entityliving)) {
            return false;
        } else {
            if (this.useMelee) {
                if (--this.ticksAfterLastAttack <= 0) {
                    this.shouldAttack = 0;
                }

                if (this.shouldAttack == 0) {
                    this.shouldAttack = this.attack(entityliving) ? 1 : 2;
                }

                if (this.shouldAttack == 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 BehaviourGoalDefendVillage) {
                reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE;
            } else if (this instanceof BehaviourGoalHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY;
            } else if (this instanceof BehaviourGoalMoveTowardsNearestAttackableTarget) {
                if (entityliving instanceof EntityHuman) {
                    reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER;
                }
            } else if (this instanceof BehaviourGoalDefendTamer) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER;
            } else if (this instanceof BehaviourGoalHelpTamerTarget) {
                reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET;
            }

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

            return true;
        }
    }
}
 
Example 11
Source File: BehaviourGoalTarget.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean isSuitableTarget(EntityLiving entityliving, boolean flag) {
    if (entityliving == null) {
        return false;
    } else if (entityliving == this.getHandle()) {
        return false;
    } else if (!entityliving.isAlive()) {
        return false;
    } else if (!this.canAttackClass(entityliving.getClass())) {
        return false;
    } else {
        if (this.getHandle() instanceof EntityOwnable && StringUtils.isNotEmpty(((EntityOwnable) this.getHandle()).getOwnerName())) {
            if (entityliving instanceof EntityOwnable && ((EntityOwnable) this.getHandle()).getOwnerName().equals(((EntityOwnable) entityliving).getOwnerName())) {
                return false;
            }

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

        if (!NMSEntityUtil.isInHomeArea(this.getHandle(), MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
            return false;
        } else if (this.checkSenses && !NMSEntityUtil.getEntitySenses(this.getHandle()).canSee(entityliving)) {
            return false;
        } else {
            if (this.useMelee) {
                if (--this.ticksAfterLastAttack <= 0) {
                    this.shouldAttack = 0;
                }

                if (this.shouldAttack == 0) {
                    this.shouldAttack = this.attack(entityliving) ? 1 : 2;
                }

                if (this.shouldAttack == 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 BehaviourGoalDefendVillage) {
                reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE;
            } else if (this instanceof BehaviourGoalHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY;
            } else if (this instanceof BehaviourGoalMoveTowardsNearestAttackableTarget) {
                if (entityliving instanceof EntityHuman) {
                    reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER;
                }
            } else if (this instanceof BehaviourGoalDefendTamer) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER;
            } else if (this instanceof BehaviourGoalHelpTamerTarget) {
                reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET;
            }

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

            return true;
        }
    }
}
 
Example 12
Source File: BehaviourGoalTarget.java    From EntityAPI with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean isSuitableTarget(EntityLiving entityliving, boolean flag) {
    if (entityliving == null) {
        return false;
    } else if (entityliving == this.getHandle()) {
        return false;
    } else if (!entityliving.isAlive()) {
        return false;
    } else if (!this.canAttackClass(entityliving.getClass())) {
        return false;
    } else {
        if (this.getHandle() instanceof EntityOwnable && StringUtils.isNotEmpty(((EntityOwnable) this.getHandle()).getOwnerName())) {
            if (entityliving instanceof EntityOwnable && ((EntityOwnable) this.getHandle()).getOwnerName().equals(((EntityOwnable) entityliving).getOwnerName())) {
                return false;
            }

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

        if (!NMSEntityUtil.isInHomeArea(this.getHandle(), MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
            return false;
        } else if (this.checkSenses && !NMSEntityUtil.getEntitySenses(this.getHandle()).canSee(entityliving)) {
            return false;
        } else {
            if (this.useMelee) {
                if (--this.ticksAfterLastAttack <= 0) {
                    this.shouldAttack = 0;
                }

                if (this.shouldAttack == 0) {
                    this.shouldAttack = this.attack(entityliving) ? 1 : 2;
                }

                if (this.shouldAttack == 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 BehaviourGoalDefendVillage) {
                reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE;
            } else if (this instanceof BehaviourGoalHurtByTarget) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY;
            } else if (this instanceof BehaviourGoalMoveTowardsNearestAttackableTarget) {
                if (entityliving instanceof EntityHuman) {
                    reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER;
                }
            } else if (this instanceof BehaviourGoalDefendTamer) {
                reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER;
            } else if (this instanceof BehaviourGoalHelpTamerTarget) {
                reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET;
            }

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

            return true;
        }
    }
}