Search in sources :

Example 36 with World

use of org.spongepowered.api.world.World in project ClearMob by axle2005.

the class CommandDump method tileEntityDump.

private void tileEntityDump() {
    List<String> listdump = new ArrayList<String>();
    List<Integer> count = new ArrayList<Integer>();
    for (World world : Sponge.getServer().getWorlds()) {
        for (TileEntity entity : world.getTileEntities()) {
            if (!listdump.contains("Tile Entity: " + entity.getType()) && !plugin.getListEntityType().contains(entity.getType())) {
                listdump.add("Tile Entity: " + entity.getType());
                count.add(1);
            } else if (listdump.contains("Tile Entity: " + entity.getType())) {
                count.set(listdump.indexOf("Tile Entity: " + entity.getType()), count.get(listdump.indexOf("Tile Entity: " + entity.getType())) + 1);
            }
        }
    }
    if (listdump.isEmpty()) {
        plugin.getLogger().info("No Tile Entities to Add");
    } else {
        for (String s : listdump) {
            plugin.getLogger().info(s);
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World)

Example 37 with World

use of org.spongepowered.api.world.World in project ClearMob by axle2005.

the class CommandDump method entityAllDump.

private void entityAllDump() {
    List<String> listentitydump = new ArrayList<String>();
    List<String> listtiledump = new ArrayList<String>();
    List<Integer> listentitycount = new ArrayList<Integer>();
    List<Integer> listtilecount = new ArrayList<Integer>();
    for (World world : Sponge.getServer().getWorlds()) {
        for (Entity entity : world.getEntities()) {
            if (!listentitydump.contains("Entity: " + entity.getType().getId())) {
                listentitydump.add("Entity: " + entity.getType().getId());
                listentitycount.add(1);
            } else if (listentitydump.contains("Entity: " + entity.getType().getId())) {
                listentitycount.set(listentitydump.indexOf("Entity: " + entity.getType().getId()), listentitycount.get(listentitydump.indexOf("Entity: " + entity.getType().getId())) + 1);
            }
        }
        for (TileEntity entity : world.getTileEntities()) {
            if (!listtiledump.contains("Tile Entity: " + entity.getType().getId())) {
                listtiledump.add("Tile Entity: " + entity.getType().getId());
                listtilecount.add(1);
            } else if (listtiledump.contains("Tile Entity: " + entity.getType().getId())) {
                listtilecount.set(listtiledump.indexOf("Tile Entity: " + entity.getType().getId()), listtilecount.get(listtiledump.indexOf("Tile Entity: " + entity.getType().getId())) + 1);
            }
        }
    }
    if (listentitydump.isEmpty()) {
        plugin.getLogger().info("No Entities to Add");
    } else {
        for (int i = 0; i <= listentitydump.size() - 1; i++) {
            plugin.getLogger().info(listentitydump.get(i) + ": (" + listentitycount.get(i) + ")");
        }
    }
    if (listtiledump.isEmpty()) {
        plugin.getLogger().info("No Tile Entities to Add");
    } else {
        for (int i = 0; i <= listtiledump.size() - 1; i++) {
            plugin.getLogger().info(listtiledump.get(i) + ": (" + listtilecount.get(i) + ")");
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Entity(org.spongepowered.api.entity.Entity) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World)

Example 38 with World

use of org.spongepowered.api.world.World in project ClearMob by axle2005.

the class CommandStats method execute.

public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!Util.playerPermCheck(src, "clearmob.tps")) {
        return CommandResult.empty();
    } else {
        src.sendMessage(this.HEADER);
        double tps = Sponge.getServer().getTicksPerSecond();
        src.sendMessage(Text.builder("Current TPS (" + tps + "):").color(TextColors.GOLD).build());
        src.sendMessage(constructTickbar(tps));
        src.sendMessage(Text.EMPTY);
        src.sendMessage(Text.builder("Worlds:").color(TextColors.GOLD).build());
        for (World w : Sponge.getServer().getWorlds()) {
            src.sendMessage(Text.of("- " + w.getName() + " (" + w.getEntities().size() + " entities, " + w.getTileEntities().size() + " tile, " + +Iterables.size(w.getLoadedChunks()) + " loaded chunks)"));
        }
        src.sendMessage(this.HEADER);
        return CommandResult.success();
    }
}
Also used : World(org.spongepowered.api.world.World)

Example 39 with World

use of org.spongepowered.api.world.World in project ClearMob by axle2005.

the class EntityLimiter method handle.

@Listener(beforeModifications = true)
public void handle(SpawnEntityEvent event) throws Exception {
    List<Entity> entity = event.getEntities();
    Integer count = 0;
    Integer xpcount = 0;
    for (World w : plugin.getWorlds()) {
        for (Entity e : w.getEntities()) {
            if (e instanceof Monster && !(e instanceof Boss)) {
                count++;
            }
            if (e instanceof ExperienceOrb) {
                xpcount++;
            }
        }
    }
    for (int i = 0; i < entity.size(); i++) {
        if (entity.get(i) instanceof Monster && (count > plugin.getMobLimit()) && !(entity.get(i) instanceof Boss)) {
            event.setCancelled(true);
        }
        if ((entity.get(i) instanceof ExperienceOrb && entity.get(i).getNearbyEntities(10).size() > 20)) {
            event.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Boss(org.spongepowered.api.entity.living.monster.Boss) Monster(org.spongepowered.api.entity.living.monster.Monster) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 40 with World

use of org.spongepowered.api.world.World in project ClearMob by axle2005.

the class ClearEntity method run.

public static void run(ClearMob plugin, EntityType tile, Collection<World> worlds, CommandSource src) {
    int removedentities = 0;
    Collection<Entity> e = new ArrayList<Entity>();
    for (World world : worlds) {
        for (Entity entity : world.getEntities()) {
            e.add(entity);
        }
    }
    if (!e.isEmpty()) {
        for (Entity entity : e) {
            if (!(entity instanceof Item) && !(entity instanceof Player) && !(entity instanceof ExperienceOrb)) {
                if ((entity.getType().equals(tile))) {
                    entity.getLocation().removeBlock(Cause.source(Sponge.getPluginManager().fromInstance(plugin).get()).build());
                    removedentities++;
                }
            }
        }
    }
    feedback(plugin, src, removedentities);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Item(org.spongepowered.api.entity.Item) Player(org.spongepowered.api.entity.living.player.Player) ArrayList(java.util.ArrayList) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) World(org.spongepowered.api.world.World)

Aggregations

World (org.spongepowered.api.world.World)81 Listener (org.spongepowered.api.event.Listener)24 Location (org.spongepowered.api.world.Location)23 Entity (org.spongepowered.api.entity.Entity)18 Player (org.spongepowered.api.entity.living.player.Player)18 Vector3i (com.flowpowered.math.vector.Vector3i)11 WorldService (com.skelril.skree.service.WorldService)11 BlockType (org.spongepowered.api.block.BlockType)10 ItemStack (org.spongepowered.api.item.inventory.ItemStack)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)8 ArrayList (java.util.ArrayList)7 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)7 BlockState (org.spongepowered.api.block.BlockState)7 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)6 Living (org.spongepowered.api.entity.living.Living)5 Monster (org.spongepowered.api.entity.living.monster.Monster)5 ItemDropper (com.skelril.nitro.item.ItemDropper)4 ModifierService (com.skelril.skree.service.ModifierService)4 IOException (java.io.IOException)4