org.bukkit.event.entity.EntityTargetEvent Java Examples

The following examples show how to use org.bukkit.event.entity.EntityTargetEvent. 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: CommonCustomMob.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
public void onTarget(EntityTargetEvent event) {
	if (event.isCancelled()) {
		return;
	}
	
	if ((event.getReason().equals(TargetReason.CLOSEST_PLAYER) ||
			event.getReason().equals(TargetReason.OWNER_ATTACKED_TARGET)) &&
			(event.getTarget() instanceof Player)) {
		
		double followRange = this.getFollowRange();
		double distance = event.getEntity().getLocation().distance(event.getTarget().getLocation());
		if ((distance-0.5) <= followRange) {
			this.targetName = ((Player)event.getTarget()).getName();
			this.lastLocation = event.getEntity().getLocation();
		}
	} else {
		this.targetName = null;
		this.lastLocation = null;
	}
}
 
Example #3
Source File: MobListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityTarget(EntityTargetEvent event) {
	if (!(event.getEntity() instanceof LivingEntity)) {
		return;
	}
	
	if (!MobLib.isMobLibEntity((LivingEntity) event.getEntity())) {
		return;
	}
		
	CommonCustomMob mob = CommonCustomMob.getCCM(event.getEntity());
	if (mob != null) {
		mob.onTarget(event);
	}
	
}
 
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: ExprTarget.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
	if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) {
		final LivingEntity target = delta == null ? null : (LivingEntity) delta[0];
		for (final LivingEntity entity : getExpr().getArray(e)) {
			if (getTime() >= 0 && e instanceof EntityTargetEvent && entity.equals(((EntityTargetEvent) e).getEntity()) && !Delay.isDelayed(e)) {
				((EntityTargetEvent) e).setTarget(target);
			} else {
				if (entity instanceof Creature)
					((Creature) entity).setTarget(target);
			}
		}
	} else {
		super.change(e, delta, mode);
	}
}
 
Example #6
Source File: ExprTarget.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Entity[] get(final Event e, final LivingEntity[] source) {
	return get(source, new Converter<LivingEntity, Entity>() {
		@Override
		@Nullable
		public Entity convert(final LivingEntity en) {
			if (getTime() >= 0 && e instanceof EntityTargetEvent && en.equals(((EntityTargetEvent) e).getEntity()) && !Delay.isDelayed(e)) {
				final Entity t = ((EntityTargetEvent) e).getTarget();
				if (t == null || type != null && !type.isInstance(t))
					return null;
				return t;
			}
			return Utils.getTarget(en, type);
		}
	});
}
 
Example #7
Source File: DamageMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onTarget(EntityTargetEvent event) {
    if(!(event.getEntity() instanceof ExperienceOrb)) {
        ParticipantState victimState = null;
        if(event.getTarget() instanceof Player) {
            // Don't target allies
            MatchPlayer victim = getVictim(event.getTarget());
            if(victim == null) return;
            victimState = victim.getParticipantState();
        } else if(event.getTarget() != null) {
            // Don't target other mobs owned by allies
            victimState = entityResolver.getOwner(event.getTarget());
        }
        if(victimState == null) return;
        DamageInfo damageInfo = damageResolver.resolveDamage(EntityDamageEvent.DamageCause.ENTITY_ATTACK, event.getTarget(), event.getEntity());
        if(queryHostile(event, victimState, damageInfo).isDenied()) {
            event.setCancelled(true);
        }
    }
}
 
Example #8
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 #9
Source File: DamageMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onTarget(EntityTargetEvent event) {
  if (!(event.getEntity() instanceof ExperienceOrb)) {
    ParticipantState victimState = null;
    if (event.getTarget() instanceof Player) {
      // Don't target allies
      MatchPlayer victim = getVictim(event.getTarget());
      if (victim == null) return;
      victimState = victim.getParticipantState();
    } else if (event.getTarget() != null) {
      // Don't target other mobs owned by allies
      victimState = tracker().getOwner(event.getTarget());
    }
    if (victimState == null) return;

    DamageInfo damageInfo =
        tracker()
            .resolveDamage(
                EntityDamageEvent.DamageCause.ENTITY_ATTACK,
                event.getTarget(),
                event.getEntity());
    if (queryHostile(victimState, damageInfo).isDenied()) {
      event.setCancelled(true);
    }
  }
}
 
Example #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: EntityListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldNotCancelEntityTargetEvent() {
    // given
    EntityTargetEvent event = mock(EntityTargetEvent.class);
    Entity target = mock(Entity.class);
    given(event.getTarget()).willReturn(target);
    given(listenerService.shouldCancelEvent(target)).willReturn(false);

    // when
    listener.onEntityTarget(event);

    // then
    verify(listenerService).shouldCancelEvent(target);
    verify(event, only()).getTarget();
}
 
Example #16
Source File: EntityListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldCancelEntityTargetEvent() {
    // given
    EntityTargetEvent event = mock(EntityTargetEvent.class);
    Entity target = mock(Entity.class);
    given(event.getTarget()).willReturn(target);
    given(listenerService.shouldCancelEvent(target)).willReturn(true);

    // when
    listener.onEntityTarget(event);

    // then
    verify(listenerService).shouldCancelEvent(target);
    verify(event).setCancelled(true);
}
 
Example #17
Source File: EntityListener.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityTarget(EntityTargetEvent event) {
    if (listenerService.shouldCancelEvent(event.getTarget())) {
        event.setTarget(null);
        event.setCancelled(true);
    }
}
 
Example #18
Source File: Yobo.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onTarget(EntityTargetEvent event) {
	super.onTarget(event);
	
	if (event.getReason().equals(TargetReason.FORGOT_TARGET) ||
	    event.getReason().equals(TargetReason.TARGET_DIED)) {
		this.angry = false;
		for (Entity e : minions) {
			e.getBukkitEntity().remove();
		}
		
	}
	
}
 
Example #19
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);
    b.set(this.goalSelector, new ArrayList<>());
    this.getAttributeInstance(GenericAttributes.b).setValue(128D);
    this.getAttributeInstance(GenericAttributes.d)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, EntityHuman.class, 1D, false));
  this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
      EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, false);
  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #20
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);
    b.set(this.goalSelector, new ArrayList<>());
    this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
    this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, EntityHuman.class, 1D, false));
  this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
      EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, false);
  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #21
Source File: AngryYobo.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onTarget(EntityTargetEvent event) {
	super.onTarget(event);
	
	if (event.getReason().equals(TargetReason.FORGOT_TARGET) ||
	    event.getReason().equals(TargetReason.TARGET_DIED)) {
		event.getEntity().remove();
	}
	
}
 
Example #22
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);
    b.set(this.goalSelector, new ArrayList<>());
    this.getAttributeInstance(GenericAttributes.b).setValue(128D);
    this.getAttributeInstance(GenericAttributes.d)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, EntityHuman.class, 1D, false));
  this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
      EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, false);
  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #23
Source File: EntityTarget.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTarget(EntityTargetEvent event)
{
	if(event.getTarget() instanceof Player)
	{
		Player player = (Player) event.getTarget();
		
		if(userManager.get(player.getUniqueId()).getVanishType() != VanishType.TOTAL)
		{
			return;
		}
		
		event.setCancelled(true);
	}
}
 
Example #24
Source File: GolemListener.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onGolemTarget(EntityTargetEvent event) {
	if (!(event.getEntity() instanceof IronGolem)) {
        return;
    }

    IronGolem ironGolem = (IronGolem) event.getEntity();
    for (String name : Main.getGameNames()) {
        Game game = Main.getGame(name);
        if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) {
            List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class);
            for (SpecialItem item : golems) {
                if (item instanceof Golem) {
                    Golem golem = (Golem) item;
                    if (golem.getEntity().equals(ironGolem)) {
                        if (event.getTarget() instanceof Player) {
                            final Player player = (Player) event.getTarget();
                            if (game.isProtectionActive(player)) {
                                event.setCancelled(true);
                                return;
                            }

                            if (Main.isPlayerInGame(player)) {
                                if (golem.getTeam() == game.getTeamOfPlayer(player)) {
                                	event.setCancelled(true);
                                    // Try to find enemy
                                    Player playerTarget = MiscUtils.findTarget(game, player, golem.getFollowRange());
                                    if (playerTarget != null) {
                                    	// Oh. We found enemy!
                                        ironGolem.setTarget(playerTarget);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example #25
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 #26
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityTrack(final EntityTargetEvent event) {
  // Handles mobs and XP orbs
  if (event.getTarget() != null) cancelUnlessInteracting(event, event.getTarget());
}
 
Example #27
Source File: GolemListener.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onGolemTarget(EntityTargetEvent event) {
	if (!(event.getEntity() instanceof IronGolem)) {
        return;
    }

    IronGolem ironGolem = (IronGolem) event.getEntity();
    for (String name : Main.getGameNames()) {
        Game game = Main.getGame(name);
        if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) {
            List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class);
            for (SpecialItem item : golems) {
                if (item instanceof Golem) {
                    Golem golem = (Golem) item;
                    if (golem.getEntity().equals(ironGolem)) {
                        if (event.getTarget() instanceof Player) {
                            final Player player = (Player) event.getTarget();
                            if (game.isProtectionActive(player)) {
                                event.setCancelled(true);
                                return;
                            }

                            if (Main.isPlayerInGame(player)) {
                                if (golem.getTeam() == game.getTeamOfPlayer(player)) {
                                	event.setCancelled(true);
                                    // Try to find enemy
                                    Player playerTarget = MiscUtils.findTarget(game, player, golem.getFollowRange());
                                    if (playerTarget != null) {
                                    	// Oh. We found enemy!
                                        ironGolem.setTarget(playerTarget);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example #28
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 #29
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityTrack(final EntityTargetEvent event) {
    // Handles mobs and XP orbs
    if(event.getTarget() != null) cancelUnlessInteracting(event, event.getTarget());
}
 
Example #30
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;
        }
    }
}