Search in sources :

Example 76 with World

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

the class clearMain method run.

public void run(Boolean[] configoptions, List<EntityType> listEntityType, CommandSource src) {
    int removedEntities = 0;
    Map<UUID, Entity> entityData = new ConcurrentHashMap<>();
    for (World world : Sponge.getServer().getWorlds()) {
        for (Entity entity : world.getEntities()) {
            entityData.put(entity.getUniqueId(), entity);
        }
        for (Entity entity : entityData.values()) {
            if (!entity.isRemoved()) {
                if (entity instanceof Player) {
                } else if (entity.get(DisplayNameData.class).isPresent()) {
                // Checks if entity has nametag and ignores it.
                } else if (configoptions[1] == true && entity instanceof Monster) {
                    // KillAllMonsters
                    removedEntities++;
                    entity.remove();
                } else if (configoptions[2] == true && entity instanceof Item) {
                    // KillDrops
                    if (ClearItems.run(entity, plugin.getListItemType(), plugin.getitemWB())) {
                        removedEntities++;
                    }
                } else if (configoptions[3] == true && entity instanceof Animal) {
                    // KillAnimalGroups
                    removedEntities = removedEntities + animals.run(entity);
                } else {
                    if (wl.clear(entity, plugin.getListEntityType()) == true) {
                        removedEntities++;
                    }
                }
            }
        }
    }
    ClearTileEntity.run(plugin, plugin.getListTileEntityType(), plugin.getWorlds(), src);
    feedback(src, removedEntities);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Item(org.spongepowered.api.entity.Item) Player(org.spongepowered.api.entity.living.player.Player) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) World(org.spongepowered.api.world.World)

Example 77 with World

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

the class CommandClearChunks method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext arguments) throws CommandException {
    if (!Util.playerPermCheck(src, "clearmob.admin")) {
        return CommandResult.empty();
    } else {
        int unloaded = 0;
        for (World w : plugin.getWorlds()) {
            for (Chunk c : w.getLoadedChunks()) {
                if (c.unloadChunk()) {
                    unloaded++;
                }
            }
        }
        src.sendMessage(Text.of(TextColors.AQUA, "[ClearMob] Unloaded: " + unloaded + " chunks"));
        return CommandResult.empty();
    }
}
Also used : World(org.spongepowered.api.world.World) Chunk(org.spongepowered.api.world.Chunk)

Example 78 with World

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

the class CommandDump method entityDump.

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

Example 79 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, List<EntityType> list, Collection<World> worlds, CommandSource src) {
    int removedentities = 0;
    //Collection<Entity> e = new ArrayList<Entity>();
    Map<UUID, Entity> entityData = new ConcurrentHashMap<>();
    for (World world : worlds) {
        for (Entity entity : world.getEntities()) {
            entityData.put(entity.getUniqueId(), entity);
            plugin.getLogger().info("Test");
        //e.add(entity);
        }
    }
    for (Entity en : entityData.values()) {
        for (int i = 0; i <= list.size() - 1; i++) {
            if ((en.getType().equals(list.get(i)))) {
                en.remove();
                entityData.remove(en.getUniqueId());
                removedentities++;
            }
        }
    }
    /*if (!e.isEmpty()) {
			for (Entity entity : e) {
				for (int i = 0; i <= list.size() - 1; i++) {
					if ((entity.getType().equals(list.get(i)))) {
						entity.remove();
						removedentities++;

					}
				}
			}
		}*/
    feedback(plugin, src, removedentities);
}
Also used : Entity(org.spongepowered.api.entity.Entity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) World(org.spongepowered.api.world.World)

Example 80 with World

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

the class ClearTileEntity method run.

public static void run(ClearMob plugin, TileEntityType tile, Collection<World> worlds, CommandSource src) {
    int removedentities = 0;
    Collection<TileEntity> e = new ArrayList<TileEntity>();
    for (World world : worlds) {
        for (TileEntity entity : world.getTileEntities()) {
            e.add(entity);
        }
    }
    if (!e.isEmpty()) {
        for (TileEntity entity : e) {
            if ((entity.getType().equals(tile))) {
                entity.getLocation().removeBlock(Cause.source(Sponge.getPluginManager().fromInstance(plugin).get()).build());
                removedentities++;
            }
        }
    }
    feedback(plugin, src, removedentities);
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ArrayList(java.util.ArrayList) 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