use of com.magmaguy.elitemobs.api.EliteMobExitCombatEvent 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 com.magmaguy.elitemobs.api.EliteMobExitCombatEvent in project EliteMobs by MagmaGuy.
the class CustomBossEntity method remove.
@Override
public void remove(RemovalReason removalReason) {
bossTrace.setRemove(removalReason);
if (DebugMessage.isDebugMode())
if (this instanceof RegionalBossEntity && this.phaseBossEntity != null)
new DebugMessage("Regional + Phase boss removal. Reason: " + removalReason);
if (livingEntity != null)
persistentLocation = livingEntity.getLocation();
// Remove the living entity
super.remove(removalReason);
// Remove things tied to the living entity
if (customBossTrail != null)
customBossTrail.terminateTrails();
if (livingEntityMount != null)
livingEntityMount.remove();
if (customBossMount != null)
customBossMount.remove(RemovalReason.REINFORCEMENT_CULL);
if (customBossesConfigFields.isCullReinforcements() || removalReason.equals(RemovalReason.PHASE_BOSS_RESET))
cullReinforcements(false);
if (removalReason.equals(RemovalReason.PHASE_BOSS_PHASE_END))
if (inCombat)
new EventCaller(new EliteMobExitCombatEvent(this, EliteMobExitCombatEvent.EliteMobExitCombatReason.PHASE_SWITCH));
boolean bossInstanceEnd = removalReason.equals(RemovalReason.KILL_COMMAND) || removalReason.equals(RemovalReason.DEATH) || removalReason.equals(RemovalReason.BOSS_TIMEOUT) || removalReason.equals(RemovalReason.WORLD_UNLOAD) || removalReason.equals(RemovalReason.SHUTDOWN);
if (!isPersistent)
bossInstanceEnd = true;
if (bossInstanceEnd) {
if (!(this instanceof RegionalBossEntity))
EntityTracker.getEliteMobEntities().remove(super.eliteUUID);
new EventCaller(new EliteMobRemoveEvent(this, removalReason));
if (escapeMechanism != null)
Bukkit.getScheduler().cancelTask(escapeMechanism);
trackableCustomBosses.remove(this);
if (simplePersistentEntity != null) {
simplePersistentEntity.remove();
simplePersistentEntity = null;
}
if (customBossBossBar != null)
customBossBossBar.remove();
if (!removalReason.equals(RemovalReason.SHUTDOWN) && !removalReason.equals(RemovalReason.DEATH))
if (phaseBossEntity != null)
phaseBossEntity.silentReset();
globalReinforcements.forEach((bukkitTask -> {
if (bukkitTask != null)
bukkitTask.cancel();
}));
globalReinforcements.clear();
if (!removalReason.equals(RemovalReason.REINFORCEMENT_CULL)) {
if (summoningEntity != null)
summoningEntity.removeReinforcement(this);
if (customSpawn != null)
customSpawn.setKeepTrying(false);
}
if (isPersistent && removalReason.equals(RemovalReason.WORLD_UNLOAD)) {
// if the world unloads, the location objects cease to be valid
spawnLocation.setWorld(null);
persistentLocation = spawnLocation;
simplePersistentEntity = new SimplePersistentEntity(this, spawnLocation);
}
if (customBossesConfigFields.isCullReinforcements())
cullReinforcements(true);
} else if (removalReason.equals(RemovalReason.CHUNK_UNLOAD))
// when bosses get removed due to chunk unloads and are persistent they should remain stored
simplePersistentEntity = new SimplePersistentEntity(this, getLocation());
}
Aggregations