Search in sources :

Example 1 with Mob

use of com.earth2me.essentials.Mob in project Essentials by drtshock.

the class Commandremove method removeHandler.

private void removeHandler(CommandSource sender, List<String> types, List<String> customTypes, World world, int radius) {
    int removed = 0;
    if (radius > 0) {
        radius *= radius;
    }
    ArrayList<ToRemove> removeTypes = new ArrayList<>();
    ArrayList<Mob> customRemoveTypes = new ArrayList<>();
    for (String s : types) {
        removeTypes.add(ToRemove.valueOf(s));
    }
    boolean warnUser = false;
    for (String s : customTypes) {
        Mob mobType = Mob.fromName(s);
        if (mobType == null) {
            warnUser = true;
        } else {
            customRemoveTypes.add(mobType);
        }
    }
    if (warnUser) {
        sender.sendMessage(tl("invalidMob"));
    }
    for (Chunk chunk : world.getLoadedChunks()) {
        for (Entity e : chunk.getEntities()) {
            if (radius > 0) {
                if (sender.getPlayer().getLocation().distanceSquared(e.getLocation()) > radius) {
                    continue;
                }
            }
            if (e instanceof HumanEntity) {
                continue;
            }
            for (ToRemove toRemove : removeTypes) {
                // We should skip any TAMED animals unless we are specifially targetting them.
                if (e instanceof Tameable && ((Tameable) e).isTamed() && !removeTypes.contains(ToRemove.TAMED)) {
                    continue;
                }
                // We should skip any NAMED animals unless we are specifially targetting them.
                if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
                    continue;
                }
                switch(toRemove) {
                    case TAMED:
                        if (e instanceof Tameable && ((Tameable) e).isTamed()) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case NAMED:
                        if (e instanceof LivingEntity && e.getCustomName() != null) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case DROPS:
                        if (e instanceof Item) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ARROWS:
                        if (e instanceof Projectile) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case BOATS:
                        if (e instanceof Boat) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case MINECARTS:
                        if (e instanceof Minecart) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case XP:
                        if (e instanceof ExperienceOrb) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case PAINTINGS:
                        if (e instanceof Painting) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ITEMFRAMES:
                        if (e instanceof ItemFrame) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ENDERCRYSTALS:
                        if (e instanceof EnderCrystal) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case AMBIENT:
                        if (e instanceof Flying) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case HOSTILE:
                    case MONSTERS:
                        if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case PASSIVE:
                    case ANIMALS:
                        if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case MOBS:
                        if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ENTITIES:
                    case ALL:
                        if (e instanceof Entity) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case CUSTOM:
                        for (Mob type : customRemoveTypes) {
                            if (e.getType() == type.getType()) {
                                e.remove();
                                removed++;
                            }
                        }
                        break;
                }
            }
        }
    }
    sender.sendMessage(tl("removed", removed));
}
Also used : ArrayList(java.util.ArrayList) Mob(com.earth2me.essentials.Mob) Chunk(org.bukkit.Chunk)

Example 2 with Mob

use of com.earth2me.essentials.Mob in project Essentials by drtshock.

the class Commandkittycannon method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final Mob cat = Mob.OCELOT;
    final Ocelot ocelot = (Ocelot) cat.spawn(user.getWorld(), server, user.getBase().getEyeLocation());
    if (ocelot == null) {
        return;
    }
    final int i = random.nextInt(Ocelot.Type.values().length);
    ocelot.setCatType(Ocelot.Type.values()[i]);
    ocelot.setTamed(true);
    ocelot.setBaby();
    ocelot.setVelocity(user.getBase().getEyeLocation().getDirection().multiply(2));
    class KittyCannonExplodeTask implements Runnable {

        @Override
        public void run() {
            final Location loc = ocelot.getLocation();
            ocelot.remove();
            loc.getWorld().createExplosion(loc, 0F);
        }
    }
    ess.scheduleSyncDelayedTask(new KittyCannonExplodeTask(), 20);
}
Also used : Mob(com.earth2me.essentials.Mob) Ocelot(org.bukkit.entity.Ocelot) Location(org.bukkit.Location)

Example 3 with Mob

use of com.earth2me.essentials.Mob in project Essentials by EssentialsX.

the class Commandkittycannon method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final Mob cat = Mob.OCELOT;
    final Ocelot ocelot = (Ocelot) cat.spawn(user.getWorld(), server, user.getBase().getEyeLocation());
    if (ocelot == null) {
        return;
    }
    final int i = random.nextInt(Ocelot.Type.values().length);
    ocelot.setCatType(Ocelot.Type.values()[i]);
    ocelot.setTamed(true);
    ocelot.setBaby();
    ocelot.setVelocity(user.getBase().getEyeLocation().getDirection().multiply(2));
    class KittyCannonExplodeTask implements Runnable {

        @Override
        public void run() {
            final Location loc = ocelot.getLocation();
            ocelot.remove();
            loc.getWorld().createExplosion(loc, 0F);
        }
    }
    ess.scheduleSyncDelayedTask(new KittyCannonExplodeTask(), 20);
}
Also used : Mob(com.earth2me.essentials.Mob) Ocelot(org.bukkit.entity.Ocelot) Location(org.bukkit.Location)

Example 4 with Mob

use of com.earth2me.essentials.Mob in project Essentials by EssentialsX.

the class Commandspawner method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 1 || args[0].length() < 2) {
        throw new NotEnoughArgumentsException(tl("mobsAvailable", StringUtil.joinList(Mob.getMobList())));
    }
    final Location target = LocationUtil.getTarget(user.getBase());
    if (target == null || target.getBlock().getType() != Material.MOB_SPAWNER) {
        throw new Exception(tl("mobSpawnTarget"));
    }
    String name = args[0];
    int delay = 0;
    Mob mob = null;
    mob = Mob.fromName(name);
    if (mob == null) {
        throw new Exception(tl("invalidMob"));
    }
    if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) {
        throw new Exception(tl("disabledToSpawnMob"));
    }
    if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase(Locale.ENGLISH))) {
        throw new Exception(tl("noPermToSpawnMob"));
    }
    if (args.length > 1) {
        if (NumberUtil.isInt(args[1])) {
            delay = Integer.parseInt(args[1]);
        }
    }
    final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess);
    charge.isAffordableFor(user);
    try {
        CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState();
        spawner.setSpawnedType(mob.getType());
        spawner.setDelay(delay);
        spawner.update();
    } catch (Throwable ex) {
        throw new Exception(tl("mobSpawnError"), ex);
    }
    charge.charge(user);
    user.sendMessage(tl("setSpawner", mob.name));
}
Also used : Mob(com.earth2me.essentials.Mob) Trade(com.earth2me.essentials.Trade) Location(org.bukkit.Location) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 5 with Mob

use of com.earth2me.essentials.Mob in project Essentials by drtshock.

the class Commandspawner method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 1 || args[0].length() < 2) {
        throw new NotEnoughArgumentsException(tl("mobsAvailable", StringUtil.joinList(Mob.getMobList())));
    }
    final Location target = LocationUtil.getTarget(user.getBase());
    if (target == null || target.getBlock().getType() != Material.MOB_SPAWNER) {
        throw new Exception(tl("mobSpawnTarget"));
    }
    String name = args[0];
    int delay = 0;
    Mob mob = null;
    mob = Mob.fromName(name);
    if (mob == null) {
        throw new Exception(tl("invalidMob"));
    }
    if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) {
        throw new Exception(tl("disabledToSpawnMob"));
    }
    if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase(Locale.ENGLISH))) {
        throw new Exception(tl("noPermToSpawnMob"));
    }
    if (args.length > 1) {
        if (NumberUtil.isInt(args[1])) {
            delay = Integer.parseInt(args[1]);
        }
    }
    final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess);
    charge.isAffordableFor(user);
    try {
        CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState();
        spawner.setSpawnedType(mob.getType());
        spawner.setDelay(delay);
        spawner.update();
    } catch (Throwable ex) {
        throw new Exception(tl("mobSpawnError"), ex);
    }
    charge.charge(user);
    user.sendMessage(tl("setSpawner", mob.name));
}
Also used : Mob(com.earth2me.essentials.Mob) Trade(com.earth2me.essentials.Trade) Location(org.bukkit.Location) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Aggregations

Mob (com.earth2me.essentials.Mob)6 Location (org.bukkit.Location)4 Trade (com.earth2me.essentials.Trade)2 ArrayList (java.util.ArrayList)2 Chunk (org.bukkit.Chunk)2 CreatureSpawner (org.bukkit.block.CreatureSpawner)2 Ocelot (org.bukkit.entity.Ocelot)2