Put your commits in the air like you just don't care!

But seriously, working on MVPurge
This commit is contained in:
Eric Stokes 2011-06-28 19:11:12 -06:00
parent 7271e5cfb8
commit 3124a5c678
5 changed files with 109 additions and 55 deletions

View File

@ -16,29 +16,29 @@ import org.bukkit.event.entity.EntityListener;
//import org.bukkit.event.entity.ExplosionPrimedEvent; //import org.bukkit.event.entity.ExplosionPrimedEvent;
public class MVEntityListener extends EntityListener { public class MVEntityListener extends EntityListener {
MultiverseCore plugin; MultiverseCore plugin;
public MVEntityListener(MultiverseCore plugin) { public MVEntityListener(MultiverseCore plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
// Need to find a way to stop the Ghast Fireballs damaging // Need to find a way to stop the Ghast Fireballs damaging
// surroundings but still doing damage to players. // surroundings but still doing damage to players.
@Override @Override
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
} }
@Override @Override
public void onEntityDeath(EntityDeathEvent event) { public void onEntityDeath(EntityDeathEvent event) {
if(event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
Player p = (Player)event.getEntity(); Player p = (Player) event.getEntity();
p.sendMessage("You died!"); p.sendMessage("You died!");
} }
super.onEntityDeath(event); super.onEntityDeath(event);
} }
/** /**
* Handle Animal/Monster Spawn settings, seems like a more concrete method than using CraftBukkit. * Handle Animal/Monster Spawn settings, seems like a more concrete method than using CraftBukkit.
*/ */
@ -47,24 +47,26 @@ public class MVEntityListener extends EntityListener {
World world = event.getEntity().getWorld(); World world = event.getEntity().getWorld();
if (event.isCancelled()) if (event.isCancelled())
return; return;
// Check if it's a world which we are meant to be managing.
if (!(this.plugin.isMVWorld(world.getName()))) if (!(this.plugin.isMVWorld(world.getName())))
return; // Check if it's a world which we are meant to be managing. return;
CreatureType creature = event.getCreatureType(); CreatureType creature = event.getCreatureType();
// event.getEntity().getWorld().spawnCreature(arg0, arg1); // event.getEntity().getWorld().spawnCreature(arg0, arg1);
MVWorld mvworld = this.plugin.getMVWorld(world.getName()); MVWorld mvworld = this.plugin.getMVWorld(world.getName());
// TODO: Look of this and see if there's a cleaner/better method of doing so... // TODO: Look of this and see if there's a cleaner/better method of doing so...
/** /**
* Animal Handling * Animal Handling
*/ */
if (event.getEntity() instanceof Animals) { if (event.getEntity() instanceof Animals) {
// If we have no exceptions for Animals then we just follow the Spawn setting. // If we have no exceptions for Animals then we just follow the Spawn setting.
if (mvworld.getAnimalList().isEmpty()) { if (mvworld.getAnimalList().isEmpty()) {
if (mvworld.hasAnimals()) { if (mvworld.allowAnimalSpawning()) {
return; return;
} else { } else {
event.setCancelled(true); event.setCancelled(true);
@ -72,8 +74,8 @@ public class MVEntityListener extends EntityListener {
} }
} }
// The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is... // The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is...
if (mvworld.getAnimalList().contains(creature.toString())) { if (mvworld.getAnimalList().contains(creature.toString().toUpperCase())) {
if (mvworld.hasAnimals()) { if (mvworld.allowAnimalSpawning()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} else { } else {
@ -84,10 +86,10 @@ public class MVEntityListener extends EntityListener {
/** /**
* Monster Handling * Monster Handling
*/ */
if (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof PigZombie || event.getEntity() instanceof Slime) { if (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || event.getEntity() instanceof Slime) {
// If we have no exceptions for Monsters then we just follow the Spawn setting. // If we have no exceptions for Monsters then we just follow the Spawn setting.
if (mvworld.getMonsterList().isEmpty()) { if (mvworld.getMonsterList().isEmpty()) {
if (mvworld.hasMonsters()) { if (mvworld.allowMonsterSpawning()) {
return; return;
} else { } else {
event.setCancelled(true); event.setCancelled(true);
@ -95,8 +97,8 @@ public class MVEntityListener extends EntityListener {
} }
} }
// The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is... // The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is...
if (mvworld.getMonsterList().contains(creature.toString())) { if (mvworld.getMonsterList().contains(creature.toString().toUpperCase())) {
if (mvworld.hasMonsters()) { if (mvworld.allowMonsterSpawning()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} else { } else {
@ -105,5 +107,5 @@ public class MVEntityListener extends EntityListener {
} }
} }
} }
} }

View File

@ -342,7 +342,7 @@ public class MVWorld {
this.config.save(); this.config.save();
} }
public Boolean hasAnimals() { public Boolean allowAnimalSpawning() {
return this.allowAnimals; return this.allowAnimals;
} }
@ -360,7 +360,7 @@ public class MVWorld {
return this.masterList.get("animals"); return this.masterList.get("animals");
} }
public Boolean hasMonsters() { public Boolean allowMonsterSpawning() {
return this.allowMonsters; return this.allowMonsters;
} }

View File

@ -220,7 +220,7 @@ public class MultiverseCore extends JavaPlugin {
/** /**
* Purge the Worlds of Entities that are disallowed. * Purge the Worlds of Entities that are disallowed.
*/ */
private void purgeWorlds() { public void purgeWorlds() {
if (this.worlds.size() <= 0) if (this.worlds.size() <= 0)
return; return;
@ -236,40 +236,41 @@ public class MultiverseCore extends JavaPlugin {
List<String> animals = mvworld.getAnimalList(); List<String> animals = mvworld.getAnimalList();
System.out.print("Monster Size:" + monsters.size() + " - " + "Animal Size: " + animals.size()); System.out.print("Monster Size:" + monsters.size() + " - " + "Animal Size: " + animals.size());
for (Entity e : world.getEntities()) { for (Entity e : world.getEntities()) {
String creatureName = e.toString().replaceAll("Craft", "").toLowerCase();
// Check against Monsters // Check against Monsters
if (e instanceof Creeper || e instanceof Skeleton || e instanceof Spider || e instanceof Zombie || e instanceof Ghast || e instanceof PigZombie || e instanceof Giant || e instanceof Slime || e instanceof Monster) { if (e instanceof Slime || e instanceof Monster) {
// If Monsters are disabled and there's no exceptions we can simply remove them. // If Monsters are disabled and there's no exceptions we can simply remove them.
if (mvworld.hasMonsters() == false && !(monsters.size() > 0)) { if (mvworld.allowMonsterSpawning() == false && !(monsters.size() > 0)) {
e.remove(); e.remove();
continue; continue;
} }
// If monsters are enabled and there's no exceptions we can continue to the next set. // If monsters are enabled and there's no exceptions we can continue to the next set.
if (mvworld.hasMonsters() == true && !(monsters.size() > 0)) { if (mvworld.allowMonsterSpawning() == true && !(monsters.size() > 0)) {
continue; continue;
} }
String creature = e.toString().replaceAll("Craft", "");
if (monsters.contains(creature.toUpperCase())) { if (monsters.contains(creatureName.toUpperCase())) {
if (mvworld.hasMonsters()) { if (mvworld.allowMonsterSpawning()) {
System.out.print(creature + " - Removed"); System.out.print(creatureName + " - Removed");
e.remove(); e.remove();
continue; continue;
} }
} }
} }
// Check against Animals // Check against Animals
if (e instanceof Chicken || e instanceof Cow || e instanceof Sheep || e instanceof Pig || e instanceof Squid || e instanceof Animals) { if (e instanceof Squid || e instanceof Animals) {
// If Monsters are disabled and there's no exceptions we can simply remove them. // If Animals are disabled and there's no exceptions we can simply remove them.
if (mvworld.hasAnimals() == false && !(animals.size() > 0)) { if (mvworld.allowAnimalSpawning() == false && !(animals.size() > 0)) {
e.remove(); e.remove();
continue; continue;
} }
// If monsters are enabled and there's no exceptions we can continue to the next set. // If Animals are enabled and there's no exceptions we can continue to the next set.
if (mvworld.hasAnimals() == true && !(animals.size() > 0)) { if (mvworld.allowAnimalSpawning() == true && !(animals.size() > 0)) {
continue; continue;
} }
String creature = e.toString().replaceAll("Craft", ""); if (animals.contains(creatureName.toUpperCase())) {
if (animals.contains(creature.toUpperCase())) { if (mvworld.allowAnimalSpawning()) {
if (mvworld.hasAnimals()) { System.out.print(creatureName + " - Removed");
e.remove(); e.remove();
continue; continue;
} }
@ -301,6 +302,7 @@ public class MultiverseCore extends JavaPlugin {
this.commandManager.addCommand(new ReloadCommand(this)); this.commandManager.addCommand(new ReloadCommand(this));
this.commandManager.addCommand(new ModifyCommand(this)); this.commandManager.addCommand(new ModifyCommand(this));
this.commandManager.addCommand(new EnvironmentCommand(this)); this.commandManager.addCommand(new EnvironmentCommand(this));
this.commandManager.addCommand(new PurgeCommand(this));
} }
/** /**

View File

@ -36,14 +36,8 @@ public class PurgeCommand extends BaseCommand {
sender.sendMessage(this.usage); sender.sendMessage(this.usage);
return; return;
} }
System.out.println("Purged");
List<String> creatures = new ArrayList<String>(); this.plugin.purgeWorlds();
for (String creature : args[0].toUpperCase().split(",")) {
creatures.add(creature);
}
new PurgeWorlds(plugin).purge(sender, p.getWorld(), creatures);
return; return;
} }

View File

@ -1,15 +1,18 @@
package com.onarandombox.utils; package com.onarandombox.utils;
import java.util.List; import java.util.List;
import java.util.Set;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Chicken; import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cow; import org.bukkit.entity.Cow;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Ghast; import org.bukkit.entity.Ghast;
import org.bukkit.entity.Giant; import org.bukkit.entity.Giant;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Pig; import org.bukkit.entity.Pig;
import org.bukkit.entity.PigZombie; import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Sheep; import org.bukkit.entity.Sheep;
@ -19,25 +22,26 @@ import org.bukkit.entity.Spider;
import org.bukkit.entity.Squid; import org.bukkit.entity.Squid;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
public class PurgeWorlds { public class PurgeWorlds {
MultiverseCore plugin; MultiverseCore plugin;
public PurgeWorlds(MultiverseCore plugin) { public PurgeWorlds(MultiverseCore plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
public void purge(World w, List<String> creatures) { public void purge(World w, List<String> creatures) {
purge(null, w, creatures); purge(null, w, creatures);
} }
public void purge(CommandSender sender, World w, List<String> creatures) { public void purge(CommandSender sender, World w, List<String> creatures) {
List<Entity> entities = w.getEntities(); List<Entity> entities = w.getEntities();
int count = 0; int count = 0;
for (Entity e : entities) { for (Entity e : entities) {
if ((((e instanceof Creeper)) && (creatures.contains("CREEPER"))) || (((e instanceof Skeleton)) && (creatures.contains("SKELETON"))) || (((e instanceof Spider)) && (creatures.contains("SPIDER"))) 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 Zombie)) && (creatures.contains("ZOMBIE"))) || (((e instanceof Ghast)) && (creatures.contains("GHAST"))) || (((e instanceof PigZombie)) && (creatures.contains("PIGZOMBIE")))
@ -48,10 +52,62 @@ public class PurgeWorlds {
count++; count++;
} }
} }
if (sender != null) { if (sender != null) {
sender.sendMessage(count + " Entities Purged from " + w.getName()); 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())
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);
}
}
}
private boolean killCreature(MVWorld mvworld, Entity e, String creatureName) {
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;
}
}
return false;
}
private boolean killMonster(MVWorld mvworld, Entity e, String creatureName) {
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;
}
}
return false;
}
} }