use of org.bukkit.entity.Mob in project EliteMobs by MagmaGuy.
the class AdvancedAggroManager method onHit.
@EventHandler(priority = EventPriority.HIGH)
public void onHit(EliteMobDamagedByPlayerEvent event) {
if (event.isCancelled())
return;
if (!event.getEliteMobEntity().hasDamagers())
return;
if (event.getEliteMobEntity().getDamagers().size() < 2)
return;
if (!(event.getEliteMobEntity().getLivingEntity() instanceof Mob))
return;
List<Player> nearbyPlayers = new ArrayList<>();
for (Entity entity : event.getEliteMobEntity().getLivingEntity().getNearbyEntities(35, 35, 35)) if (entity.getType().equals(EntityType.PLAYER))
nearbyPlayers.add((Player) entity);
Player player = null;
double damage = 0;
for (Player iteratedPlayer : event.getEliteMobEntity().getDamagers().keySet()) {
if (event.getEliteMobEntity().getDamagers().get(iteratedPlayer) > damage && nearbyPlayers.contains(iteratedPlayer)) {
player = iteratedPlayer;
damage = event.getEliteMobEntity().getDamagers().get(iteratedPlayer);
}
}
if (player == null)
return;
if (((Mob) event.getEliteMobEntity().getLivingEntity()).getTarget() == null || !((Mob) event.getEliteMobEntity().getLivingEntity()).getTarget().getUniqueId().equals(player.getUniqueId())) {
((Mob) event.getEliteMobEntity().getLivingEntity()).setTarget(player);
}
}
use of org.bukkit.entity.Mob in project EliteMobs by MagmaGuy.
the class SpiritWalk method spiritWalkRegionalBossAnimation.
public static void spiritWalkRegionalBossAnimation(EliteEntity eliteEntity, Location entityLocation, Location finalLocation) {
eliteEntity.getLivingEntity().setAI(false);
eliteEntity.getLivingEntity().setInvulnerable(true);
Vector toDestination = finalLocation.clone().subtract(entityLocation.clone()).toVector().normalize().divide(new Vector(2, 2, 2));
Entity vehicle = null;
if (eliteEntity.getLivingEntity().isInsideVehicle()) {
vehicle = eliteEntity.getLivingEntity().getVehicle();
if (vehicle instanceof LivingEntity)
((LivingEntity) vehicle).setAI(false);
vehicle.setInvulnerable(true);
if (((CustomBossEntity) eliteEntity).getPhaseBossEntity() != null)
vehicle.remove();
}
new BukkitRunnable() {
final Entity vehicle = eliteEntity.getLivingEntity().getVehicle();
int counter = 0;
@Override
public void run() {
if (!eliteEntity.isValid()) {
cancel();
return;
}
if (eliteEntity.getLivingEntity().isInsideVehicle())
eliteEntity.getLivingEntity().leaveVehicle();
if (eliteEntity.getLivingEntity().getLocation().clone().distance(finalLocation) < 2 || counter > 20 * 10) {
eliteEntity.getLivingEntity().setAI(true);
eliteEntity.getLivingEntity().setInvulnerable(false);
if (vehicle != null && !vehicle.isDead())
vehicle.teleport(finalLocation);
eliteEntity.getLivingEntity().teleport(finalLocation);
if (vehicle != null && !vehicle.isDead()) {
if (vehicle instanceof LivingEntity) {
((LivingEntity) vehicle).setAI(true);
EliteEntity vehicleBoss = EntityTracker.getEliteMobEntity(vehicle);
if (vehicleBoss != null)
Bukkit.getServer().getPluginManager().callEvent(new EliteMobExitCombatEvent(vehicleBoss, EliteMobExitCombatEvent.EliteMobExitCombatReason.SPIRIT_WALK));
}
vehicle.setInvulnerable(false);
new BukkitRunnable() {
@Override
public void run() {
PreventMountExploit.bypass = true;
vehicle.addPassenger(eliteEntity.getLivingEntity());
}
}.runTaskLater(MetadataHandler.PLUGIN, 1);
}
cancel();
Bukkit.getServer().getPluginManager().callEvent(new EliteMobExitCombatEvent(eliteEntity, EliteMobExitCombatEvent.EliteMobExitCombatReason.SPIRIT_WALK));
if (eliteEntity.getLivingEntity() instanceof Mob)
if (((Mob) eliteEntity.getLivingEntity()).getTarget() == null)
eliteEntity.getLivingEntity().addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 2));
}
if (vehicle != null && !vehicle.isDead()) {
vehicle.teleport(eliteEntity.getLivingEntity().getLocation().clone().add(toDestination.clone()));
}
eliteEntity.getLivingEntity().teleport(eliteEntity.getLivingEntity().getLocation().clone().add(toDestination.clone()));
counter++;
}
}.runTaskTimer(MetadataHandler.PLUGIN, 0, 1);
}
use of org.bukkit.entity.Mob in project EliteMobs by MagmaGuy.
the class KeepNeutralsAngry method showMeYouWarFace.
public static void showMeYouWarFace(EliteEntity eliteEntity) {
// might already contain
EntityType entityType = eliteEntity.getLivingEntity().getType();
if (angryMobs.contains(eliteEntity))
return;
new BukkitRunnable() {
@Override
public void run() {
// It is possible for entities to change type during combat, in which case they need to be wiped
if (!eliteEntity.isValid() || !entityType.equals(eliteEntity.getLivingEntity().getType()) || entityType.equals(EntityType.WOLF) && ((Wolf) eliteEntity.getLivingEntity()).isTamed()) {
cancel();
angryMobs.remove(eliteEntity);
return;
}
if (!eliteEntity.getLivingEntity().getType().equals(EntityType.LLAMA) && ((Mob) eliteEntity.getLivingEntity()).getTarget() != null)
return;
for (Player player : Bukkit.getOnlinePlayers()) if (!player.getGameMode().equals(GameMode.SPECTATOR) && !player.getGameMode().equals(GameMode.CREATIVE) && Objects.equals(player.getLocation().getWorld(), eliteEntity.getLocation().getWorld()) && player.getLocation().distance(eliteEntity.getLocation()) < Objects.requireNonNull(eliteEntity.getLivingEntity().getAttribute(Attribute.GENERIC_FOLLOW_RANGE)).getBaseValue()) {
((Mob) eliteEntity.getLivingEntity()).setTarget(player);
return;
}
((Mob) eliteEntity.getLivingEntity()).setTarget(null);
}
}.runTaskTimer(MetadataHandler.PLUGIN, 0, 20);
}
Aggregations