mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-02 16:59:56 +01:00
Think I've finished the Purge Command. It's untested. o.O
This commit is contained in:
parent
3124a5c678
commit
ce3e203bc1
@ -54,8 +54,6 @@ public class MVEntityListener extends EntityListener {
|
||||
|
||||
CreatureType creature = event.getCreatureType();
|
||||
|
||||
// event.getEntity().getWorld().spawnCreature(arg0, arg1);
|
||||
|
||||
MVWorld mvworld = this.plugin.getMVWorld(world.getName());
|
||||
|
||||
// TODO: Look of this and see if there's a cleaner/better method of doing so...
|
||||
|
@ -49,6 +49,7 @@ import com.onarandombox.MultiverseCore.command.QueuedCommand;
|
||||
import com.onarandombox.MultiverseCore.command.commands.*;
|
||||
import com.onarandombox.MultiverseCore.configuration.DefaultConfiguration;
|
||||
import com.onarandombox.utils.DebugLog;
|
||||
import com.onarandombox.utils.PurgeWorlds;
|
||||
import com.onarandombox.utils.UpdateChecker;
|
||||
|
||||
public class MultiverseCore extends JavaPlugin {
|
||||
@ -93,7 +94,7 @@ public class MultiverseCore extends JavaPlugin {
|
||||
|
||||
// HashMap to contain information relating to the Players.
|
||||
public HashMap<String, MVPlayerSession> playerSessions = new HashMap<String, MVPlayerSession>();
|
||||
|
||||
private PurgeWorlds worldPurger;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@ -115,8 +116,10 @@ public class MultiverseCore extends JavaPlugin {
|
||||
this.registerEvents();
|
||||
// Setup Permissions, we'll do an initial check for the Permissions plugin then fall back on isOP().
|
||||
this.setupPermissions();
|
||||
// Setup thte command manager
|
||||
// Setup the command manager
|
||||
this.commandManager = new CommandManager(this);
|
||||
// Setup the world purger
|
||||
this.worldPurger = new PurgeWorlds(this);
|
||||
// Setup iConomy.
|
||||
this.setupEconomy();
|
||||
// Call the Function to assign all the Commands to their Class.
|
||||
@ -129,9 +132,6 @@ public class MultiverseCore extends JavaPlugin {
|
||||
// When called with null, it tries to load ALL
|
||||
// this function will be called every time a plugin registers a new envtype with MV
|
||||
this.loadWorlds(true);
|
||||
|
||||
// Purge Worlds of old Monsters/Animals which don't adhere to the setup.
|
||||
this.purgeWorlds();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,69 +217,6 @@ public class MultiverseCore extends JavaPlugin {
|
||||
this.debug = this.configMV.getBoolean("debug", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge the Worlds of Entities that are disallowed.
|
||||
*/
|
||||
public void purgeWorlds() {
|
||||
if (this.worlds.size() <= 0)
|
||||
return;
|
||||
|
||||
// TODO: Need a better method than this... too messy and atm it's not complete.
|
||||
|
||||
Set<String> worldKeys = this.worlds.keySet();
|
||||
for (String key : worldKeys) {
|
||||
World world = getServer().getWorld(key);
|
||||
if (world == null)
|
||||
continue;
|
||||
MVWorld mvworld = this.worlds.get(key);
|
||||
List<String> monsters = mvworld.getMonsterList();
|
||||
List<String> animals = mvworld.getAnimalList();
|
||||
System.out.print("Monster Size:" + monsters.size() + " - " + "Animal Size: " + animals.size());
|
||||
for (Entity e : world.getEntities()) {
|
||||
String creatureName = e.toString().replaceAll("Craft", "").toLowerCase();
|
||||
// Check against Monsters
|
||||
if (e instanceof Slime || e instanceof Monster) {
|
||||
// If Monsters are disabled and there's no exceptions we can simply remove them.
|
||||
if (mvworld.allowMonsterSpawning() == false && !(monsters.size() > 0)) {
|
||||
e.remove();
|
||||
continue;
|
||||
}
|
||||
// If monsters are enabled and there's no exceptions we can continue to the next set.
|
||||
if (mvworld.allowMonsterSpawning() == true && !(monsters.size() > 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (monsters.contains(creatureName.toUpperCase())) {
|
||||
if (mvworld.allowMonsterSpawning()) {
|
||||
System.out.print(creatureName + " - Removed");
|
||||
e.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check against Animals
|
||||
if (e instanceof Squid || e instanceof Animals) {
|
||||
// If Animals are disabled and there's no exceptions we can simply remove them.
|
||||
if (mvworld.allowAnimalSpawning() == false && !(animals.size() > 0)) {
|
||||
e.remove();
|
||||
continue;
|
||||
}
|
||||
// If Animals are enabled and there's no exceptions we can continue to the next set.
|
||||
if (mvworld.allowAnimalSpawning() == true && !(animals.size() > 0)) {
|
||||
continue;
|
||||
}
|
||||
if (animals.contains(creatureName.toUpperCase())) {
|
||||
if (mvworld.allowAnimalSpawning()) {
|
||||
System.out.print(creatureName + " - Removed");
|
||||
e.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Multiverse-Core commands to DThielke's Command Manager.
|
||||
*/
|
||||
@ -430,7 +367,9 @@ public class MultiverseCore extends JavaPlugin {
|
||||
log(Level.INFO, "Loading World & Settings - '" + name + "' - " + env);
|
||||
}
|
||||
}
|
||||
this.worlds.put(name, new MVWorld(world, this.configWorlds, this, seed, generator));
|
||||
MVWorld mvworld = new MVWorld(world, this.configWorlds, this, seed, generator);
|
||||
this.worldPurger.purgeWorld(null, mvworld);
|
||||
this.worlds.put(name, mvworld);
|
||||
return true;
|
||||
|
||||
}
|
||||
@ -569,6 +508,10 @@ public class MultiverseCore extends JavaPlugin {
|
||||
return this.ph;
|
||||
}
|
||||
|
||||
public PurgeWorlds getWorldPurger() {
|
||||
return this.worldPurger;
|
||||
}
|
||||
|
||||
/**
|
||||
* onCommand
|
||||
*/
|
||||
@ -662,8 +605,6 @@ public class MultiverseCore extends JavaPlugin {
|
||||
|
||||
// TODO: Find out where to put these next 3 methods! I just stuck them here for now --FF
|
||||
|
||||
|
||||
|
||||
public Collection<MVWorld> getMVWorlds() {
|
||||
return this.worlds.values();
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
package com.onarandombox.MultiverseCore.command.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import sun.tools.tree.ArrayAccessExpression;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
||||
import com.onarandombox.utils.PurgeWorlds;
|
||||
@ -36,8 +39,32 @@ public class PurgeCommand extends BaseCommand {
|
||||
sender.sendMessage(this.usage);
|
||||
return;
|
||||
}
|
||||
String worldName = null;
|
||||
String deathName = null;
|
||||
if(args.length == 1) {
|
||||
worldName = p.getWorld().getName();
|
||||
deathName = args[0];
|
||||
} else {
|
||||
worldName = args[0];
|
||||
deathName = args[1];
|
||||
}
|
||||
|
||||
if(!this.plugin.isMVWorld(worldName)) {
|
||||
sender.sendMessage("Multiverse doesn't know about " + worldName);
|
||||
sender.sendMessage("... so It cannot be purged");
|
||||
return;
|
||||
}
|
||||
MVWorld world = this.plugin.getMVWorld(worldName);
|
||||
|
||||
System.out.println("Purged");
|
||||
this.plugin.purgeWorlds();
|
||||
PurgeWorlds purger = this.plugin.getWorldPurger();
|
||||
ArrayList<String> thingsToKill = new ArrayList<String>();
|
||||
if(deathName.equalsIgnoreCase("all") || deathName.equalsIgnoreCase("animals") || deathName.equalsIgnoreCase("monsters")) {
|
||||
thingsToKill.add(deathName.toUpperCase());
|
||||
} else {
|
||||
Collections.addAll(thingsToKill, deathName.split(","));
|
||||
}
|
||||
purger.purgeWorld(sender, world, thingsToKill, false, false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1,26 +1,12 @@
|
||||
package com.onarandombox.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Chicken;
|
||||
import org.bukkit.entity.Cow;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Ghast;
|
||||
import org.bukkit.entity.Giant;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.PigZombie;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.entity.Skeleton;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Spider;
|
||||
import org.bukkit.entity.Squid;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
|
||||
import com.onarandombox.MultiverseCore.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
@ -33,78 +19,101 @@ public class PurgeWorlds {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void purge(World w, List<String> creatures) {
|
||||
purge(null, w, creatures);
|
||||
}
|
||||
|
||||
public void purge(CommandSender sender, World w, List<String> creatures) {
|
||||
|
||||
List<Entity> entities = w.getEntities();
|
||||
int count = 0;
|
||||
|
||||
for (Entity e : entities) {
|
||||
if ((((e instanceof Creeper)) && (creatures.contains("CREEPER"))) || (((e instanceof Skeleton)) && (creatures.contains("SKELETON"))) || (((e instanceof Spider)) && (creatures.contains("SPIDER")))
|
||||
|| (((e instanceof Zombie)) && (creatures.contains("ZOMBIE"))) || (((e instanceof Ghast)) && (creatures.contains("GHAST"))) || (((e instanceof PigZombie)) && (creatures.contains("PIGZOMBIE")))
|
||||
|| (((e instanceof Giant)) && (creatures.contains("GIANT"))) || (((e instanceof Slime)) && (creatures.contains("SLIME"))) || (((e instanceof Chicken)) && (creatures.contains("CHICKEN")))
|
||||
|| (((e instanceof Cow)) && (creatures.contains("COW"))) || (((e instanceof Sheep)) && (creatures.contains("SHEEP"))) || (((e instanceof Pig)) && (creatures.contains("PIG")))
|
||||
|| (((e instanceof Squid)) && (creatures.contains("SQUID"))) || creatures.contains("*")) {
|
||||
e.remove();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (sender != null) {
|
||||
sender.sendMessage(count + " Entities Purged from " + w.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizes the given world with it's settings
|
||||
*/
|
||||
public void purgeWorlds(MVWorld world) {
|
||||
|
||||
}
|
||||
|
||||
public void purgeWorlds(CommandSender sender, List<MVWorld> worlds, List<String> whatToKill) {
|
||||
if (worlds.isEmpty())
|
||||
public void purgeWorlds(CommandSender sender, List<MVWorld> worlds) {
|
||||
if (worlds == null || worlds.isEmpty()) {
|
||||
return;
|
||||
|
||||
for (MVWorld mvworld : worlds) {
|
||||
World world = this.plugin.getServer().getWorld(mvworld.getName());
|
||||
if (world == null)
|
||||
continue;
|
||||
List<String> monsters = mvworld.getMonsterList();
|
||||
List<String> animals = mvworld.getAnimalList();
|
||||
System.out.print("Monster Size:" + monsters.size() + " - " + "Animal Size: " + animals.size());
|
||||
for (Entity e : world.getEntities()) {
|
||||
String creatureName = e.toString().replaceAll("Craft", "").toLowerCase();
|
||||
// Check against Monsters
|
||||
killMonster(mvworld, e, creatureName);
|
||||
// Check against Animals
|
||||
killCreature(mvworld, e, creatureName);
|
||||
}
|
||||
}
|
||||
for (MVWorld world : worlds) {
|
||||
this.purgeWorld(sender, world);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Convince method for clearing all the animals that do not belong according to the config.
|
||||
* @param sender
|
||||
* @param world
|
||||
*/
|
||||
public void purgeWorld(CommandSender sender, MVWorld world) {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
ArrayList<String> allMobs = new ArrayList<String>(world.getAnimalList());
|
||||
allMobs.addAll(world.getMonsterList());
|
||||
purgeWorld(sender, world, allMobs, world.allowAnimalSpawning(), world.allowMonsterSpawning());
|
||||
}
|
||||
|
||||
private boolean killCreature(MVWorld mvworld, Entity e, String creatureName) {
|
||||
public void purgeWorld(CommandSender sender, MVWorld mvworld, List<String> thingsToKill, boolean negateAnimals, boolean negateMonsters) {
|
||||
if (mvworld == null)
|
||||
return;
|
||||
World world = this.plugin.getServer().getWorld(mvworld.getName());
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
int entitiesKilled = 0;
|
||||
//System.out.print("Monster Size:" + monstersToKill.size() + " - " + "Animal Size: " + creaturesToKill.size());
|
||||
for (Entity e : world.getEntities()) {
|
||||
|
||||
// Check against Monsters
|
||||
if (killMonster(mvworld, e, thingsToKill, negateMonsters)) {
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
// Check against Animals
|
||||
if (this.killCreature(mvworld, e, thingsToKill, negateAnimals)) {
|
||||
entitiesKilled++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
System.out.print(entitiesKilled + " entities killed in " + mvworld.getName());
|
||||
entitiesKilled = 0;
|
||||
}
|
||||
|
||||
private boolean killCreature(MVWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
String entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
if (e instanceof Squid || e instanceof Animals) {
|
||||
if (entityName.contains(creatureName.toUpperCase())) {
|
||||
System.out.print(creatureName + " - Removed");
|
||||
e.remove();
|
||||
return true;
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("CREATURES")) {
|
||||
if (!negate) {
|
||||
System.out.print(entityName + " - Removed");
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (negate) {
|
||||
System.out.print(entityName + " - Removed");
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean killMonster(MVWorld mvworld, Entity e, String creatureName) {
|
||||
/**
|
||||
* Will kill the monster if it's in the list UNLESS the NEGATE boolean is set, then it will kill it if it's NOT
|
||||
*
|
||||
* @param mvworld
|
||||
* @param e
|
||||
* @param creaturesToKill
|
||||
* @param negate
|
||||
* @return
|
||||
*/
|
||||
private boolean killMonster(MVWorld mvworld, Entity e, List<String> creaturesToKill, boolean negate) {
|
||||
String entityName = e.toString().replaceAll("Craft", "").toUpperCase();
|
||||
if (e instanceof Slime || e instanceof Monster) {
|
||||
if (entityName.contains(creatureName.toUpperCase())) {
|
||||
System.out.print(creatureName + " - Removed");
|
||||
e.remove();
|
||||
return true;
|
||||
if (creaturesToKill.contains(entityName) || creaturesToKill.contains("ALL") || creaturesToKill.contains("MONSTERS")) {
|
||||
if (!negate) {
|
||||
System.out.print(entityName + " - Removed");
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (negate) {
|
||||
System.out.print(entityName + " - Removed");
|
||||
e.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user