Search in sources :

Example 6 with EnderDragon

use of org.bukkit.entity.EnderDragon in project TotalFreedomMod by TotalFreedom.

the class MobBlocker method onCreatureSpawn.

@EventHandler(priority = EventPriority.NORMAL)
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (!ConfigEntry.MOB_LIMITER_ENABLED.getBoolean()) {
        return;
    }
    final Entity spawned = event.getEntity();
    if (spawned instanceof EnderDragon) {
        if (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean()) {
            event.setCancelled(true);
            return;
        }
    } else if (spawned instanceof Ghast) {
        if (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean()) {
            event.setCancelled(true);
            return;
        }
    } else if (spawned instanceof Slime) {
        if (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean()) {
            event.setCancelled(true);
            return;
        }
    } else if (spawned instanceof Giant) {
        if (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean()) {
            event.setCancelled(true);
            return;
        }
    } else if (spawned instanceof Bat) {
        event.setCancelled(true);
        return;
    }
    int mobLimiterMax = ConfigEntry.MOB_LIMITER_MAX.getInteger();
    if (mobLimiterMax <= 0) {
        return;
    }
    int mobcount = 0;
    for (Entity entity : event.getLocation().getWorld().getLivingEntities()) {
        if (!(entity instanceof HumanEntity)) {
            mobcount++;
        }
    }
    if (mobcount > mobLimiterMax) {
        event.setCancelled(true);
    }
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) EnderDragon(org.bukkit.entity.EnderDragon) Bat(org.bukkit.entity.Bat) Ghast(org.bukkit.entity.Ghast) HumanEntity(org.bukkit.entity.HumanEntity) Slime(org.bukkit.entity.Slime) Giant(org.bukkit.entity.Giant) EventHandler(org.bukkit.event.EventHandler)

Example 7 with EnderDragon

use of org.bukkit.entity.EnderDragon in project Glowstone by GlowstoneMC.

the class GlowEnderCrystal method damage.

@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
    if (source instanceof EnderDragon) {
        return;
    }
    if (cause != DamageCause.ENTITY_EXPLOSION) {
        ExplosionPrimeEvent event = EventFactory.getInstance().callEvent(new ExplosionPrimeEvent(this, Explosion.POWER_ENDER_CRYSTAL, true));
        if (!event.isCancelled()) {
            Location location = getLocation();
            double x = location.getX();
            double y = location.getY();
            double z = location.getZ();
            world.createExplosion(this, x, y, z, event.getRadius(), event.getFire(), true);
        }
    }
    remove();
}
Also used : EnderDragon(org.bukkit.entity.EnderDragon) ExplosionPrimeEvent(org.bukkit.event.entity.ExplosionPrimeEvent) Location(org.bukkit.Location)

Example 8 with EnderDragon

use of org.bukkit.entity.EnderDragon in project modules-extra by CubeEngine.

the class ListenerDeath method onEntityDeath.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    // TODO handle when there is no reference on lookup of dependent actions
    DeathKill killAction = this.newAction(DeathKill.class, event.getEntity().getWorld());
    if (killAction != null) {
        // TODO check config for killer type
        killAction.setLocation(event.getEntity().getLocation());
        EntityDamageEvent cause = event.getEntity().getLastDamageCause();
        if (cause == null) {
            killAction.otherKiller = DamageCause.CUSTOM;
        } else if (cause instanceof EntityDamageByEntityEvent) {
            Entity damager = ((EntityDamageByEntityEvent) cause).getDamager();
            if (damager instanceof Player) {
                killAction.playerKiller = new PlayerSection((Player) damager);
            } else if (damager instanceof Projectile) {
                killAction.projectile = true;
                if (((Projectile) damager).getShooter() instanceof Entity) {
                    if (((Projectile) damager).getShooter() instanceof Player) {
                        killAction.playerKiller = new PlayerSection((Player) ((Projectile) damager).getShooter());
                    } else {
                        killAction.entityKiller = new EntitySection((Entity) ((Projectile) damager).getShooter());
                    }
                } else {
                    killAction.entityKiller = new EntitySection(damager);
                }
            } else {
                killAction.entityKiller = new EntitySection(damager);
            }
        } else {
            killAction.otherKiller = cause.getCause();
        }
        this.logAction(killAction);
    }
    Reference<DeathKill> reference = this.reference(killAction);
    LivingEntity killed = event.getEntity();
    if (killed instanceof Player) {
        DeathPlayer action = this.newAction(DeathPlayer.class, killed.getWorld());
        if (action != null) {
            action.killer = reference;
            action.setPlayer((Player) killed);
            this.logAction(action);
        }
        if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
            Reference<DeathPlayer> deathRef = this.reference(action);
            for (ItemStack itemStack : event.getDrops()) {
                PlayerDeathDrop dropAction = newAction(PlayerDeathDrop.class);
                dropAction.item = itemStack;
                dropAction.death = deathRef;
                this.logAction(dropAction);
            }
        }
        return;
    }
    Class<? extends EntityDeathAction> actionType;
    if (killed instanceof Wither || killed instanceof EnderDragon) {
        actionType = DeathBoss.class;
    } else if (killed instanceof Animals) {
        if (killed instanceof Tameable && ((Tameable) killed).isTamed()) {
            actionType = DeathPet.class;
        } else {
            actionType = DeathAnimal.class;
        }
    } else if (killed instanceof Villager) {
        actionType = DeathNpc.class;
    } else if (killed instanceof Monster) {
        actionType = DeathMonster.class;
    } else {
        actionType = DeathOther.class;
    }
    EntityDeathAction action = this.newAction(actionType, killed.getWorld());
    if (action != null) {
        action.setKilled(killed);
        action.setLocation(killed.getLocation());
        action.killer = reference;
        this.logAction(action);
    }
    Reference<EntityDeathAction> deathRef = this.reference(action);
    if (this.isActive(DeathDrop.class, event.getEntity().getWorld())) {
        for (ItemStack itemStack : event.getDrops()) {
            DeathDrop dropAction = newAction(DeathDrop.class);
            dropAction.item = itemStack;
            dropAction.death = deathRef;
            this.logAction(dropAction);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) PlayerSection(org.cubeengine.module.log.action.block.player.ActionPlayerBlock.PlayerSection) LivingEntity(org.bukkit.entity.LivingEntity) EnderDragon(org.bukkit.entity.EnderDragon) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) EntitySection(org.cubeengine.module.log.action.block.entity.ActionEntityBlock.EntitySection) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Wither(org.bukkit.entity.Wither) Player(org.spongepowered.api.entity.player.Player) Tameable(org.bukkit.entity.Tameable) Projectile(org.bukkit.entity.Projectile) Animals(org.bukkit.entity.Animals) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) ItemStack(org.spongepowered.api.item.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EnderDragon (org.bukkit.entity.EnderDragon)8 Entity (org.bukkit.entity.Entity)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 Location (org.bukkit.Location)2 Ghast (org.bukkit.entity.Ghast)2 Slime (org.bukkit.entity.Slime)2 EventHandler (org.bukkit.event.EventHandler)2 Vector (org.bukkit.util.Vector)2 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)1 World (org.bukkit.World)1 Ambient (org.bukkit.entity.Ambient)1 Animals (org.bukkit.entity.Animals)1 Bat (org.bukkit.entity.Bat)1 Creature (org.bukkit.entity.Creature)1 Giant (org.bukkit.entity.Giant)1 HumanEntity (org.bukkit.entity.HumanEntity)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Monster (org.bukkit.entity.Monster)1 Projectile (org.bukkit.entity.Projectile)1 Tameable (org.bukkit.entity.Tameable)1