use of org.bukkit.event.entity.EntityTargetLivingEntityEvent in project IridiumSkyblock by Iridium-Development.
the class EntityTargetListener method onEntityTargetEntity.
@EventHandler
public void onEntityTargetEntity(EntityTargetLivingEntityEvent event) {
if (IridiumSkyblock.getInstance().getConfiguration().pvpSettings.mobsVisitorTargeting)
return;
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getEntity().getLocation());
if (!island.isPresent())
return;
if (event.getTarget() == null || !(event.getTarget() instanceof Player))
return;
Player targetPlayer = (Player) event.getTarget();
User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
Optional<IslandTrusted> targetTrusted = IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser);
if (island.get().equals(targetUser.getIsland().orElse(null)) || targetTrusted.isPresent())
return;
if (!canSearchTarget(event.getEntity())) {
return;
}
List<Player> nextTargets = event.getEntity().getNearbyEntities(8, 8, 8).stream().filter(entity -> entity instanceof Player).filter(entity -> island.get().isInIsland(entity.getLocation())).map(entity -> (Player) entity).filter(player -> player != targetPlayer).filter(player -> island.get().equals(IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland().orElse(null))).filter(player -> IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player)).isPresent()).filter(player -> player.hasLineOfSight(event.getEntity())).collect(Collectors.toList());
if (nextTargets.isEmpty()) {
event.setCancelled(true);
return;
}
Player nextTarget = nextTargets.get(ThreadLocalRandom.current().nextInt(nextTargets.size()));
event.setTarget(nextTarget);
}
use of org.bukkit.event.entity.EntityTargetLivingEntityEvent in project WindSpigot by Wind-Development.
the class EntityInsentient method setGoalTarget.
public void setGoalTarget(EntityLiving entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
if (getGoalTarget() == entityliving) {
return;
}
if (fireEvent) {
if (reason == EntityTargetEvent.TargetReason.UNKNOWN && getGoalTarget() != null && entityliving == null) {
reason = getGoalTarget().isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
}
if (reason == EntityTargetEvent.TargetReason.UNKNOWN) {
world.getServer().getLogger().log(java.util.logging.Level.WARNING, "Unknown target reason, please report on the issue tracker", new Exception());
}
CraftLivingEntity ctarget = null;
if (entityliving != null) {
ctarget = (CraftLivingEntity) entityliving.getBukkitEntity();
}
EntityTargetLivingEntityEvent event = new EntityTargetLivingEntityEvent(this.getBukkitEntity(), ctarget, reason);
world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
if (event.getTarget() != null) {
entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
} else {
entityliving = null;
}
}
// KigPaper - WeakReference
this.goalTarget = new WeakReference<>(entityliving);
// CraftBukkit end
}
use of org.bukkit.event.entity.EntityTargetLivingEntityEvent in project BentoBox by BentoBoxWorld.
the class ExperiencePickupListenerTest method setUp.
/**
* @throws java.lang.Exception
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
when(island.isAllowed(any(), any())).thenReturn(true);
// Set up as valid
entity = mock(ExperienceOrb.class);
when(entity.getLocation()).thenReturn(location);
TargetReason reason = TargetReason.CLOSEST_PLAYER;
e = new EntityTargetLivingEntityEvent(entity, player, reason);
epl = new ExperiencePickupListener();
}
use of org.bukkit.event.entity.EntityTargetLivingEntityEvent in project NachoSpigot by CobbleSword.
the class EntityExperienceOrb method t_.
public void t_() {
super.t_();
// CraftBukkit - store old target
EntityHuman prevTarget = this.targetPlayer;
if (this.c > 0) {
--this.c;
}
this.lastX = this.locX;
this.lastY = this.locY;
this.lastZ = this.locZ;
this.motY -= 0.029999999329447746D;
if (this.world.getType(new BlockPosition(this)).getBlock().getMaterial() == Material.LAVA) {
this.motY = 0.20000000298023224D;
this.motX = (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F);
this.motZ = (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F);
this.makeSound("random.fizz", 0.4F, 2.0F + this.random.nextFloat() * 0.4F);
}
this.j(this.locX, (this.getBoundingBox().b + this.getBoundingBox().e) / 2.0D, this.locZ);
double d0 = 8.0D;
if (this.targetTime < this.a - 20 + this.getId() % 100) {
if (this.targetPlayer == null || this.targetPlayer.h(this) > d0 * d0) {
this.targetPlayer = this.world.findNearbyPlayer(this, d0);
}
this.targetTime = this.a;
}
if (this.targetPlayer != null && this.targetPlayer.isSpectator()) {
this.targetPlayer = null;
}
if (this.targetPlayer != null) {
// CraftBukkit start
boolean cancelled = false;
if (this.targetPlayer != prevTarget) {
EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(this, targetPlayer, EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
EntityLiving target = event.getTarget() == null ? null : ((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getTarget()).getHandle();
targetPlayer = target instanceof EntityHuman ? (EntityHuman) target : null;
cancelled = event.isCancelled();
}
if (!cancelled && targetPlayer != null) {
double d1 = (this.targetPlayer.locX - this.locX) / d0;
double d2 = (this.targetPlayer.locY + (double) this.targetPlayer.getHeadHeight() - this.locY) / d0;
double d3 = (this.targetPlayer.locZ - this.locZ) / d0;
double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
double d5 = 1.0D - d4;
if (d5 > 0.0D) {
d5 *= d5;
this.motX += d1 / d4 * d5 * 0.1D;
this.motY += d2 / d4 * d5 * 0.1D;
this.motZ += d3 / d4 * d5 * 0.1D;
}
}
// CraftBukkit end
}
this.move(this.motX, this.motY, this.motZ);
float f = 0.98F;
if (this.onGround) {
f = this.world.getType(new BlockPosition(MathHelper.floor(this.locX), MathHelper.floor(this.getBoundingBox().b) - 1, MathHelper.floor(this.locZ))).getBlock().frictionFactor * 0.98F;
}
this.motX *= (double) f;
this.motY *= 0.9800000190734863D;
this.motZ *= (double) f;
if (this.onGround) {
this.motY *= -0.8999999761581421D;
}
++this.a;
++this.b;
if (this.b >= 6000) {
this.die();
}
}
use of org.bukkit.event.entity.EntityTargetLivingEntityEvent in project NachoSpigot by CobbleSword.
the class EntityInsentient method setGoalTarget.
public void setGoalTarget(EntityLiving entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
if (getGoalTarget() == entityliving)
return;
if (fireEvent) {
if (reason == EntityTargetEvent.TargetReason.UNKNOWN && getGoalTarget() != null && entityliving == null) {
reason = getGoalTarget().isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
}
if (reason == EntityTargetEvent.TargetReason.UNKNOWN) {
world.getServer().getLogger().log(java.util.logging.Level.WARNING, "Unknown target reason, please report on the issue tracker", new Exception());
}
CraftLivingEntity ctarget = null;
if (entityliving != null) {
ctarget = (CraftLivingEntity) entityliving.getBukkitEntity();
}
EntityTargetLivingEntityEvent event = new EntityTargetLivingEntityEvent(this.getBukkitEntity(), ctarget, reason);
world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
if (event.getTarget() != null) {
entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
} else {
entityliving = null;
}
}
// KigPaper - WeakReference
this.goalTarget = new WeakReference<>(entityliving);
// CraftBukkit end
}
Aggregations