use of com.magmaguy.elitemobs.api.EliteMobRemoveEvent 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