Search in sources :

Example 96 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.

the class ZombieBloat method bloatEffect.

private void bloatEffect(LivingEntity eventZombie) {
    /*
        Spawn giant for "bloat" effect
         */
    Giant giant = (Giant) eventZombie.getWorld().spawnEntity(eventZombie.getLocation(), EntityType.GIANT);
    giant.setAI(false);
    /*
        Apply knockback to all living entities around the giant except for the original zombie entity
         */
    List<Entity> nearbyEntities = giant.getNearbyEntities(4, 15, 4);
    List<LivingEntity> nearbyValidLivingEntities = new ArrayList<>();
    if (nearbyEntities.size() > 0)
        for (Entity entity : nearbyEntities) if (entity instanceof LivingEntity && !entity.equals(eventZombie))
            nearbyValidLivingEntities.add((LivingEntity) entity);
    Location entityLocation = eventZombie.getLocation();
    for (LivingEntity livingEntity : nearbyValidLivingEntities) {
        Location livingEntityLocation = livingEntity.getLocation();
        Vector toLivingEntityVector = livingEntityLocation.subtract(entityLocation).toVector();
        /*
            Normalize vector to apply powers uniformly
             */
        Vector normalizedVector = toLivingEntityVector.normalize();
        normalizedVector = normalizedVector.multiply(new Vector(2, 0, 2)).add(new Vector(0, 1, 0));
        try {
            livingEntity.setVelocity(normalizedVector);
        } catch (Exception e) {
            livingEntity.setVelocity(new Vector(0, 1.5, 0));
        }
    }
    livingEntityEffect(nearbyValidLivingEntities);
    /*
        Effect is done, start task to remove giant
         */
    new BukkitRunnable() {

        @Override
        public void run() {
            giant.remove();
            eventZombie.setAI(true);
        }
    }.runTaskLater(MetadataHandler.PLUGIN, 10);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Giant(org.bukkit.entity.Giant) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 97 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.

the class ZombieBloat method onHit.

@EventHandler
public void onHit(EliteMobDamagedByPlayerEvent event) {
    ZombieBloat zombieBloat = (ZombieBloat) event.getEliteMobEntity().getPower(this);
    if (zombieBloat == null)
        return;
    if (zombieBloat.isInGlobalCooldown())
        return;
    if (ThreadLocalRandom.current().nextDouble() > 0.20)
        return;
    zombieBloat.doGlobalCooldown(20 * 10);
    /*
        Create early warning that entity is about to bloat
         */
    new BukkitRunnable() {

        final LivingEntity eventZombie = (LivingEntity) event.getEntity();

        int timer = 0;

        @Override
        public void run() {
            if (timer > 40) {
                bloatEffect(eventZombie);
                cancel();
            }
            if (timer == 21)
                eventZombie.setAI(false);
            if (MobCombatSettingsConfig.isEnableWarningVisualEffects())
                eventZombie.getWorld().spawnParticle(Particle.TOTEM, new Location(eventZombie.getWorld(), eventZombie.getLocation().getX(), eventZombie.getLocation().getY() + eventZombie.getHeight(), eventZombie.getLocation().getZ()), 20, timer / 24, timer / 9d, timer / 24d, 0.1);
            timer++;
        }
    }.runTaskTimer(MetadataHandler.PLUGIN, 0, 1);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 98 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.

the class ZombieNecronomicon method spawnReinforcements.

private void spawnReinforcements(EliteEntity eliteEntity, LivingEntity targetted, ZombieNecronomicon zombieNecronomicon) {
    LivingEntity targetter = eliteEntity.getLivingEntity();
    new BukkitRunnable() {

        final ArrayList<Entity> entityList = new ArrayList<>();

        @Override
        public void run() {
            if (!eliteEntity.isValid() || !targetted.isValid() || !targetter.isValid() || targetted.getWorld() != targetter.getWorld() || targetted.getLocation().distance(targetter.getLocation()) > 30) {
                for (Entity entity : entityList) if (entity.isValid())
                    entity.remove();
                if (eliteEntity.isValid())
                    targetter.setAI(true);
                cancel();
                return;
            }
            int randomizedNumber = ThreadLocalRandom.current().nextInt(5) + 1;
            entityList.removeIf(currentEntity -> !currentEntity.isValid());
            if (entityList.size() < 11) {
                targetter.setAI(false);
                if (!zombieNecronomicon.isFiring())
                    necronomiconVisualEffect(eliteEntity, zombieNecronomicon);
                if (randomizedNumber < 5) {
                    CustomBossEntity customBossEntity = CustomBossEntity.createCustomBossEntity("necronomicon_zombie.yml");
                    if (customBossEntity == null) {
                        new WarningMessage("necronomicon_zombie.yml is not valid!");
                        return;
                    }
                    customBossEntity.spawn(targetter.getLocation(), eliteEntity.getLevel(), false);
                    if (!customBossEntity.getLivingEntity().isValid()) {
                        targetter.setAI(true);
                        cancel();
                        targetter.setAI(true);
                        cancel();
                        return;
                    }
                    customBossEntity.getLivingEntity().setVelocity(new Vector((ThreadLocalRandom.current().nextDouble() - 0.5) / 30, 0.5, (ThreadLocalRandom.current().nextDouble() - 0.5) / 30));
                    eliteEntity.addReinforcement(customBossEntity);
                    entityList.add(customBossEntity.getLivingEntity());
                } else {
                    CustomBossEntity customBossEntity = CustomBossEntity.createCustomBossEntity("necronomicon_skeleton.yml");
                    if (customBossEntity == null) {
                        new WarningMessage("necronomicon_skeleton.yml is not valid!");
                        targetter.setAI(true);
                        cancel();
                        return;
                    }
                    customBossEntity.spawn(targetter.getLocation(), eliteEntity.getLevel(), false);
                    if (!customBossEntity.getLivingEntity().isValid()) {
                        targetter.setAI(true);
                        cancel();
                        return;
                    }
                    customBossEntity.getLivingEntity().setVelocity(new Vector((ThreadLocalRandom.current().nextDouble() - 0.5) / 30, 0.5, (ThreadLocalRandom.current().nextDouble() - 0.5) / 30));
                    eliteEntity.addReinforcement(customBossEntity);
                    entityList.add(customBossEntity.getLivingEntity());
                }
            } else
                targetter.setAI(true);
        }
    }.runTaskTimer(MetadataHandler.PLUGIN, 20 * 3L, 20 * 3L);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) Item(org.bukkit.entity.Item) HashMap(java.util.HashMap) EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) MobCombatSettingsConfig(com.magmaguy.elitemobs.config.MobCombatSettingsConfig) MajorPower(com.magmaguy.elitemobs.powers.meta.MajorPower) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler) Location(org.bukkit.Location) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MetadataHandler(com.magmaguy.elitemobs.MetadataHandler) ChatColorConverter.convert(com.magmaguy.elitemobs.ChatColorConverter.convert) GenericRotationMatrixMath(com.magmaguy.elitemobs.powerstances.GenericRotationMatrixMath) EliteMobDamagedByPlayerEvent(com.magmaguy.elitemobs.api.EliteMobDamagedByPlayerEvent) Material(org.bukkit.Material) Listener(org.bukkit.event.Listener) Entity(org.bukkit.entity.Entity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) VisualItemInitializer(com.magmaguy.elitemobs.powerstances.VisualItemInitializer) EntityTracker(com.magmaguy.elitemobs.entitytracker.EntityTracker) LivingEntity(org.bukkit.entity.LivingEntity) CustomBossEntity(com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) List(java.util.List) PowersConfig(com.magmaguy.elitemobs.config.powers.PowersConfig) EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) CustomBossEntity(com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity) WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CustomBossEntity(com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity) Vector(org.bukkit.util.Vector)

Example 99 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.

the class Bombardment method activate.

public void activate(EliteEntity eliteEntity) {
    if (isActive)
        return;
    isActive = true;
    task = new BukkitRunnable() {

        int counter = 0;

        @Override
        public void run() {
            counter++;
            if (stopCondition(eliteEntity))
                return;
            if (firing || isInCooldown(eliteEntity))
                return;
            if (ThreadLocalRandom.current().nextDouble() > 0.1)
                return;
            if (eliteEntity.getLivingEntity().getType().equals(EntityType.ENDER_DRAGON)) {
                EnderDragon.Phase phase = ((EnderDragon) eliteEntity.getLivingEntity()).getPhase();
                if (phase.equals(EnderDragon.Phase.DYING) || phase.equals(EnderDragon.Phase.HOVER) || phase.equals(EnderDragon.Phase.ROAR_BEFORE_ATTACK) || phase.equals(EnderDragon.Phase.FLY_TO_PORTAL) || phase.equals(EnderDragon.Phase.SEARCH_FOR_BREATH_ATTACK_TARGET)) {
                    return;
                }
            }
            for (Entity entity : eliteEntity.getLivingEntity().getNearbyEntities(10, 100, 10)) {
                if (entity.getType().equals(EntityType.PLAYER)) {
                    firing = true;
                    fire(eliteEntity);
                    return;
                }
            }
        }
    }.runTaskTimer(MetadataHandler.PLUGIN, 0, 5);
}
Also used : Entity(org.bukkit.entity.Entity) EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) EnderDragon(org.bukkit.entity.EnderDragon) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 100 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.

the class ZombieFriends method onHit.

@EventHandler
public void onHit(EliteMobDamagedByPlayerEvent event) {
    ZombieFriends zombieFriendConfig = (ZombieFriends) event.getEliteMobEntity().getPower(this);
    if (zombieFriendConfig == null)
        return;
    if (zombieFriendConfig.isFiring())
        return;
    if (ThreadLocalRandom.current().nextDouble() > 0.01)
        return;
    zombieFriendConfig.setFiring(true);
    CustomBossEntity reinforcement1 = CustomBossEntity.createCustomBossEntity("zombie_friends_friend.yml");
    reinforcement1.spawn(event.getEntity().getLocation(), event.getEliteMobEntity().getLevel(), false);
    CustomBossEntity reinforcement2 = CustomBossEntity.createCustomBossEntity("zombie_friends_friend.yml");
    reinforcement2.spawn(event.getEntity().getLocation(), event.getEliteMobEntity().getLevel(), false);
    new BukkitRunnable() {

        @Override
        public void run() {
            if (!event.getEliteMobEntity().isValid() || !reinforcement1.isValid() && !reinforcement2.isValid()) {
                if (reinforcement1 != null && reinforcement1.isValid()) {
                    nameClearer(reinforcement1);
                    reinforcement1.getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.friendDeathMessage.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.friendDeathMessage.size()))));
                }
                if (reinforcement2 != null && reinforcement2.isValid()) {
                    nameClearer(reinforcement2);
                    reinforcement2.getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.friendDeathMessage.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.friendDeathMessage.size()))));
                }
                cancel();
                return;
            } else {
                if (ThreadLocalRandom.current().nextDouble() < 0.5) {
                    nameClearer(event.getEliteMobEntity());
                    event.getEliteMobEntity().getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.originalEntityDialog.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.originalEntityDialog.size()))));
                }
                if (ThreadLocalRandom.current().nextDouble() < 0.5 && reinforcement1.isValid()) {
                    nameClearer(reinforcement1);
                    reinforcement1.getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.reinforcementDialog.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.reinforcementDialog.size()))));
                }
                if (ThreadLocalRandom.current().nextDouble() < 0.5 && reinforcement2.isValid()) {
                    nameClearer(reinforcement2);
                    reinforcement2.getLivingEntity().setCustomName(ChatColorConverter.convert(ZombieFriendsConfig.reinforcementDialog.get(ThreadLocalRandom.current().nextInt(ZombieFriendsConfig.reinforcementDialog.size()))));
                }
            }
        }
    }.runTaskTimer(MetadataHandler.PLUGIN, 20, 20 * 8);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CustomBossEntity(com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)316 Player (org.bukkit.entity.Player)85 EventHandler (org.bukkit.event.EventHandler)52 Location (org.bukkit.Location)46 Vector (org.bukkit.util.Vector)45 Entity (org.bukkit.entity.Entity)29 ItemStack (org.bukkit.inventory.ItemStack)26 List (java.util.List)25 UUID (java.util.UUID)25 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)18 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)17 LivingEntity (org.bukkit.entity.LivingEntity)16 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)15 HashMap (java.util.HashMap)12 MyPetFeedEvent (de.Keyle.MyPet.api.event.MyPetFeedEvent)11 Material (org.bukkit.Material)11 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)10 File (java.io.File)10 PotionEffect (org.bukkit.potion.PotionEffect)10