Search in sources :

Example 1 with Mob

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);
    }
}
Also used : Mob(org.bukkit.entity.Mob) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Mob

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);
}
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 3 with Mob

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);
}
Also used : EntityType(org.bukkit.entity.EntityType) Mob(org.bukkit.entity.Mob) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Aggregations

Mob (org.bukkit.entity.Mob)3 Entity (org.bukkit.entity.Entity)2 Player (org.bukkit.entity.Player)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 EliteMobExitCombatEvent (com.magmaguy.elitemobs.api.EliteMobExitCombatEvent)1 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)1 CustomBossEntity (com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity)1 ArrayList (java.util.ArrayList)1 EntityType (org.bukkit.entity.EntityType)1 LivingEntity (org.bukkit.entity.LivingEntity)1 EventHandler (org.bukkit.event.EventHandler)1 PotionEffect (org.bukkit.potion.PotionEffect)1 Vector (org.bukkit.util.Vector)1