Search in sources :

Example 1 with Slime

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

the class Command_mobpurge method purgeMobs.

public static int purgeMobs() {
    int removed = 0;
    for (World world : Bukkit.getWorlds()) {
        for (Entity ent : world.getLivingEntities()) {
            if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime || ent instanceof EnderDragon || ent instanceof Ambient) {
                ent.remove();
                removed++;
            }
        }
    }
    return removed;
}
Also used : Entity(org.bukkit.entity.Entity) Creature(org.bukkit.entity.Creature) EnderDragon(org.bukkit.entity.EnderDragon) Ambient(org.bukkit.entity.Ambient) Ghast(org.bukkit.entity.Ghast) World(org.bukkit.World) Slime(org.bukkit.entity.Slime)

Example 2 with Slime

use of org.bukkit.entity.Slime 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)

Aggregations

EnderDragon (org.bukkit.entity.EnderDragon)2 Entity (org.bukkit.entity.Entity)2 Ghast (org.bukkit.entity.Ghast)2 Slime (org.bukkit.entity.Slime)2 World (org.bukkit.World)1 Ambient (org.bukkit.entity.Ambient)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 EventHandler (org.bukkit.event.EventHandler)1