Search in sources :

Example 1 with ClearMob

use of io.github.axle2005.clearmob.ClearMob in project ClearMob by axle2005.

the class ClearTileEntity method run.

public static void run(CommandSource src) {
    ClearMob instance = ClearMob.getInstance();
    entityData = new ConcurrentHashMap<>();
    index = 0;
    for (World world : Sponge.getServer().getWorlds()) {
        for (TileEntity entity : world.getTileEntities()) {
            entityData.put(index, entity);
            index++;
        }
    }
    for (TileEntity entity : entityData.values()) {
        if (Util.getTileEntityType(instance.getGlobalConfig().options.get(0).listTileEntitys).contains(entity.getType())) {
            entity.getLocation().removeBlock();
            removedEntities++;
        }
    }
    Util.feedback("Tile Entity", src, removedEntities);
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ClearMob(io.github.axle2005.clearmob.ClearMob) World(org.spongepowered.api.world.World)

Example 2 with ClearMob

use of io.github.axle2005.clearmob.ClearMob in project ClearMob by axle2005.

the class ClearEntity method run.

public static void run(CommandSource src) {
    ClearMob instance = ClearMob.getInstance();
    removedEntities = 0;
    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()) {
                // Skip players and Nametags
                if (!(entity instanceof Player || entity.get(DisplayNameData.class).isPresent())) {
                    // Kills all Monsters
                    if (instance.getGlobalConfig().options.get(0).killAllMonsters && entity instanceof Monster && !(entity instanceof Boss)) {
                        removedEntities++;
                        entity.remove();
                    }
                    // Kills all Bosses
                    if (instance.getGlobalConfig().options.get(0).killAllBosses && entity instanceof Boss) {
                        removedEntities++;
                        entity.remove();
                    }
                    // Removes all Drops
                    if (instance.getGlobalConfig().options.get(0).killAllDrops && entity instanceof Item) {
                        if (!Util.getItemType(instance.getGlobalConfig().options.get(0).listItemEntitys).contains(((Item) entity).getItemType())) {
                            entity.remove();
                            removedEntities++;
                        }
                    // ClearItems.run(entity,Util.getItemType(instance.getGlobalConfig().options.get(0).listItemEntitys),"WhiteList");
                    }
                    // Kills grouped Animals.
                    if (instance.getGlobalConfig().options.get(0).killAnimalGroups && entity instanceof Animal) {
                        removedEntities = removedEntities + ClearAnimals.run(entity);
                    }
                    if (ClearWhiteList.clear(entity, Util.getEntityType(instance.getGlobalConfig().options.get(0).listEntitys))) {
                        removedEntities++;
                    }
                }
            }
        }
    }
    Util.feedback("Entity", src, removedEntities);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Item(org.spongepowered.api.entity.Item) Player(org.spongepowered.api.entity.living.player.Player) Boss(org.spongepowered.api.entity.living.monster.Boss) ClearMob(io.github.axle2005.clearmob.ClearMob) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) World(org.spongepowered.api.world.World)

Example 3 with ClearMob

use of io.github.axle2005.clearmob.ClearMob in project ClearMob by axle2005.

the class ConfigHandler method loadConfiguration.

public static GlobalConfig loadConfiguration() throws ObjectMappingException, IOException {
    ClearMob instance = ClearMob.getInstance();
    Path configDir = instance.getConfigDir();
    // Creates ClearMob folder in the 'plugins' directory defined in sponge global.conf
    if (!Files.exists(configDir)) {
        Files.createDirectories(configDir);
    }
    Path configFile = Paths.get(configDir + "/ClearMob.json");
    GsonConfigurationLoader configLoader = GsonConfigurationLoader.builder().setPath(configFile).build();
    ConfigurationNode configNode = configLoader.load();
    GlobalConfig config = configNode.getValue(TypeToken.of(GlobalConfig.class), new GlobalConfig());
    // Creates Clearmob.json if it does not exist
    if (!Files.exists(configFile)) {
        Files.createFile(configFile);
        instance.getLogger().info("Created default configuration!");
    }
    // Adds default entries for Options
    if (config.options.isEmpty()) {
        OptionsConfig options = new OptionsConfig();
        options.initializeDefaults();
        config.options.add(options);
    }
    // Adds default entries for Mob Limiter
    if (config.mobLimiter.isEmpty()) {
        MobLimiterConfig mobLimiter = new MobLimiterConfig();
        mobLimiter.initializeDefaults();
        config.mobLimiter.add(mobLimiter);
    }
    // Adds default entries for Compression mode
    if (config.compressEntities.isEmpty()) {
        CompressEntities compressEntities = new CompressEntities();
        compressEntities.initializeDefault();
        config.compressEntities.add(compressEntities);
    }
    // Adds default entries for Passive mode
    if (config.passive.isEmpty()) {
        PassiveConfig passive = new PassiveConfig();
        passive.initializeDefault();
        config.passive.add(passive);
    }
    // Adds default entries for Warning Message
    if (config.warning.isEmpty()) {
        WarningConfig warning = new WarningConfig();
        warning.initializeDefaults();
        config.warning.add(warning);
    }
    configNode.setValue(TypeToken.of(GlobalConfig.class), config);
    configLoader.save(configNode);
    instance.getLogger().info("Configuration loaded.");
    return config;
}
Also used : Path(java.nio.file.Path) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ClearMob(io.github.axle2005.clearmob.ClearMob) GsonConfigurationLoader(ninja.leaping.configurate.gson.GsonConfigurationLoader)

Aggregations

ClearMob (io.github.axle2005.clearmob.ClearMob)3 World (org.spongepowered.api.world.World)2 Path (java.nio.file.Path)1 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)1 GsonConfigurationLoader (ninja.leaping.configurate.gson.GsonConfigurationLoader)1 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)1 Entity (org.spongepowered.api.entity.Entity)1 Item (org.spongepowered.api.entity.Item)1 Animal (org.spongepowered.api.entity.living.animal.Animal)1 Boss (org.spongepowered.api.entity.living.monster.Boss)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1 Player (org.spongepowered.api.entity.living.player.Player)1