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);
}
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);
}
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;
}
Aggregations