Search in sources :

Example 1 with EliteMobExitCombatEvent

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);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) LivingEntity(org.bukkit.entity.LivingEntity) CustomBossEntity(com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity) Mob(org.bukkit.entity.Mob) PotionEffect(org.bukkit.potion.PotionEffect) EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Vector(org.bukkit.util.Vector) EliteMobExitCombatEvent(com.magmaguy.elitemobs.api.EliteMobExitCombatEvent)

Example 2 with EliteMobExitCombatEvent

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());
}
Also used : Setter(lombok.Setter) DefaultConfig(com.magmaguy.elitemobs.config.DefaultConfig) ElitePlayerInventory(com.magmaguy.elitemobs.playerdata.ElitePlayerInventory) Getter(lombok.Getter) CustomBossesConfig(com.magmaguy.elitemobs.config.custombosses.CustomBossesConfig) CustomEvent(com.magmaguy.elitemobs.events.CustomEvent) CustomBossesConfigFields(com.magmaguy.elitemobs.config.custombosses.CustomBossesConfigFields) EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) Player(org.bukkit.entity.Player) MobCombatSettingsConfig(com.magmaguy.elitemobs.config.MobCombatSettingsConfig) CustomSummonPower(com.magmaguy.elitemobs.powers.meta.CustomSummonPower) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler) HashSet(java.util.HashSet) EliteMobProperties(com.magmaguy.elitemobs.mobconstructor.mobdata.aggressivemobs.EliteMobProperties) DisguiseEntity(com.magmaguy.elitemobs.thirdparty.libsdisguises.DisguiseEntity) Location(org.bukkit.Location) Minidungeon(com.magmaguy.elitemobs.dungeons.Minidungeon) MetadataHandler(com.magmaguy.elitemobs.MetadataHandler) com.magmaguy.elitemobs.utils(com.magmaguy.elitemobs.utils) Material(org.bukkit.Material) Nullable(javax.annotation.Nullable) EliteMobEnterCombatEvent(com.magmaguy.elitemobs.api.EliteMobEnterCombatEvent) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) EventsConfig(com.magmaguy.elitemobs.config.EventsConfig) RemovalReason(com.magmaguy.elitemobs.api.internal.RemovalReason) Entity(org.bukkit.entity.Entity) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) EliteMobExitCombatEvent(com.magmaguy.elitemobs.api.EliteMobExitCombatEvent) ElitePower(com.magmaguy.elitemobs.powers.meta.ElitePower) SimplePersistentEntityInterface(com.magmaguy.elitemobs.mobconstructor.SimplePersistentEntityInterface) EntityTracker(com.magmaguy.elitemobs.entitytracker.EntityTracker) LivingEntity(org.bukkit.entity.LivingEntity) SimplePersistentEntity(com.magmaguy.elitemobs.mobconstructor.SimplePersistentEntity) TransitiveBlock(com.magmaguy.elitemobs.mobconstructor.custombosses.transitiveblocks.TransitiveBlock) Objects(java.util.Objects) List(java.util.List) CustomModel(com.magmaguy.elitemobs.thirdparty.modelengine.CustomModel) DiscordSRVAnnouncement(com.magmaguy.elitemobs.thirdparty.discordsrv.DiscordSRVAnnouncement) BukkitTask(org.bukkit.scheduler.BukkitTask) CustomSpawn(com.magmaguy.elitemobs.mobconstructor.CustomSpawn) ChatColorConverter(com.magmaguy.elitemobs.ChatColorConverter) EliteMobRemoveEvent(com.magmaguy.elitemobs.api.EliteMobRemoveEvent) PotionEffectType(org.bukkit.potion.PotionEffectType) SimplePersistentEntity(com.magmaguy.elitemobs.mobconstructor.SimplePersistentEntity) EliteMobRemoveEvent(com.magmaguy.elitemobs.api.EliteMobRemoveEvent) EliteMobExitCombatEvent(com.magmaguy.elitemobs.api.EliteMobExitCombatEvent)

Aggregations

EliteMobExitCombatEvent (com.magmaguy.elitemobs.api.EliteMobExitCombatEvent)2 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 ChatColorConverter (com.magmaguy.elitemobs.ChatColorConverter)1 MetadataHandler (com.magmaguy.elitemobs.MetadataHandler)1 EliteMobEnterCombatEvent (com.magmaguy.elitemobs.api.EliteMobEnterCombatEvent)1 EliteMobRemoveEvent (com.magmaguy.elitemobs.api.EliteMobRemoveEvent)1 RemovalReason (com.magmaguy.elitemobs.api.internal.RemovalReason)1 DefaultConfig (com.magmaguy.elitemobs.config.DefaultConfig)1 EventsConfig (com.magmaguy.elitemobs.config.EventsConfig)1 MobCombatSettingsConfig (com.magmaguy.elitemobs.config.MobCombatSettingsConfig)1 CustomBossesConfig (com.magmaguy.elitemobs.config.custombosses.CustomBossesConfig)1 CustomBossesConfigFields (com.magmaguy.elitemobs.config.custombosses.CustomBossesConfigFields)1 Minidungeon (com.magmaguy.elitemobs.dungeons.Minidungeon)1 EntityTracker (com.magmaguy.elitemobs.entitytracker.EntityTracker)1 CustomEvent (com.magmaguy.elitemobs.events.CustomEvent)1 CustomSpawn (com.magmaguy.elitemobs.mobconstructor.CustomSpawn)1 SimplePersistentEntity (com.magmaguy.elitemobs.mobconstructor.SimplePersistentEntity)1 SimplePersistentEntityInterface (com.magmaguy.elitemobs.mobconstructor.SimplePersistentEntityInterface)1