Animals exceptions are working. Time to refactor. seriously.

This commit is contained in:
Eric Stokes 2011-06-29 19:21:07 -06:00
parent 69c23980e1
commit 535dcded34
2 changed files with 83 additions and 59 deletions

View File

@ -5,7 +5,6 @@ import org.bukkit.entity.Animals;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Monster;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.event.entity.CreatureSpawnEvent;
@ -44,6 +43,7 @@ public class MVEntityListener extends EntityListener {
*/
@Override
public void onCreatureSpawn(CreatureSpawnEvent event) {
World world = event.getEntity().getWorld();
if (event.isCancelled())
return;
@ -56,6 +56,16 @@ public class MVEntityListener extends EntityListener {
MVWorld mvworld = this.plugin.getMVWorld(world.getName());
System.out.print("A creature spawned: " + event.getEntity());
System.out.print("Type: " + event.getCreatureType());
System.out.print("Reason: " + event.getSpawnReason());
System.out.print("Instanceof Animal: " + (event.getEntity() instanceof Animals));
System.out.print("Instanceof Monster: " + (event.getEntity() instanceof Monster));
System.out.print("Animal Allowed: " + mvworld.allowAnimalSpawning());
System.out.print("Monster Allowed: " + mvworld.allowMonsterSpawning());
System.out.print("Animal list: " + mvworld.getAnimalList());
System.out.print("Monster list: " + mvworld.getMonsterList());
// TODO: Look of this and see if there's a cleaner/better method of doing so...
/**
@ -63,22 +73,31 @@ public class MVEntityListener extends EntityListener {
*/
if (event.getEntity() instanceof Animals) {
// If we have no exceptions for Animals then we just follow the Spawn setting.
if (mvworld.getAnimalList().isEmpty()) {
if (mvworld.allowAnimalSpawning()) {
return;
} else {
event.setCancelled(true);
return;
}
}
// The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is...
if (mvworld.getAnimalList().contains(creature.toString().toUpperCase())) {
if (mvworld.allowAnimalSpawning()) {
event.setCancelled(true);
return;
} else {
return;
}
if (mvworld.getAnimalList().isEmpty() && mvworld.allowAnimalSpawning()) {
System.out.print("1. There are no exceptions and animals are allowd.");
return;
} else if (mvworld.getAnimalList().isEmpty()) {
System.out.print("2. There are no exceptions and animals are NOT allowed. Kill the " + creature.toString().toUpperCase());
event.setCancelled(true);
System.out.print("MV is killing a " + event.getCreatureType());
return;
} else if (mvworld.getAnimalList().contains(creature.toString().toUpperCase()) && mvworld.allowAnimalSpawning()) {
System.out.print("3. There ARE exceptions and animals ARE allowed. Kill the " + creature.toString().toUpperCase());
event.setCancelled(true);
System.out.print("MV is killing a " + event.getCreatureType());
return;
} else if (!mvworld.getAnimalList().contains(creature.toString().toUpperCase()) && mvworld.allowAnimalSpawning()) {
System.out.print("4. There ARE exceptions and animals ARE NOT allowed. SAVE the " + creature.toString().toUpperCase());
return;
} else if (mvworld.getAnimalList().contains(creature.toString().toUpperCase()) && !mvworld.allowAnimalSpawning()) {
System.out.print("5. No animals are allowed to be spawned, BUT this one can stay... " + creature.toString().toUpperCase());
return;
} else if (!mvworld.getAnimalList().contains(creature.toString().toUpperCase()) && !mvworld.allowAnimalSpawning()) {
System.out.print("6. Animals are NOT allowd to spawn, and this creature is not in the save list... KILL IT " + creature.toString().toUpperCase());
event.setCancelled(true);
System.out.print("MV is killing a " + event.getCreatureType());
return;
}
}
/**
@ -91,6 +110,7 @@ public class MVEntityListener extends EntityListener {
return;
} else {
event.setCancelled(true);
System.out.print("MV is killing a " + event.getCreatureType());
return;
}
}
@ -98,6 +118,7 @@ public class MVEntityListener extends EntityListener {
if (mvworld.getMonsterList().contains(creature.toString().toUpperCase())) {
if (mvworld.allowMonsterSpawning()) {
event.setCancelled(true);
System.out.print("MV is killing a " + event.getCreatureType());
return;
} else {
return;

View File

@ -10,6 +10,38 @@ import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.util.config.Configuration;
enum EnglishChatColor {
AQUA(ChatColor.AQUA),
BLACK(ChatColor.BLACK),
BLUE(ChatColor.BLUE),
DARKAQUA(ChatColor.DARK_AQUA),
DARKBLUE(ChatColor.DARK_BLUE),
DARKGRAY(ChatColor.DARK_GRAY),
DARKGREEN(ChatColor.DARK_GREEN),
DARKPURPLE(ChatColor.DARK_PURPLE),
DARKRED(ChatColor.DARK_RED),
GOLD(ChatColor.GOLD),
GRAY(ChatColor.GRAY),
GREEN(ChatColor.GREEN),
LIGHTPURPLE(ChatColor.LIGHT_PURPLE),
RED(ChatColor.RED),
YELLOW(ChatColor.YELLOW),
WHITE(ChatColor.WHITE);
private ChatColor color;
EnglishChatColor(ChatColor color) {
this.color = color;
}
public String getText() {
return this.toString();
}
public ChatColor getColor() {
return this.color;
}
}
public class MVWorld {
private MultiverseCore plugin; // Hold the Plugin Instance.
@ -189,11 +221,13 @@ public class MVWorld {
} catch (Exception e) {
}
} else if (this.masterList.keySet().contains(list)) {
this.masterList.get(list).add(value);
if (list.equalsIgnoreCase("animals") || list.equalsIgnoreCase("monsters")) {
this.masterList.get(list).add(value.toUpperCase());
this.config.setProperty("worlds." + this.name + "." + list.toLowerCase() + ".exceptions", this.masterList.get(list));
this.syncMobs();
} else {
this.masterList.get(list).add(value);
this.config.setProperty("worlds." + this.name + "." + list.toLowerCase(), this.masterList.get(list));
}
this.config.save();
@ -211,11 +245,13 @@ public class MVWorld {
}
}
if (this.masterList.keySet().contains(list)) {
this.masterList.get(list).remove(value);
if (list.equalsIgnoreCase("animals") || list.equalsIgnoreCase("monsters")) {
this.masterList.get(list).remove(value.toUpperCase());
this.config.setProperty("worlds." + this.name + "." + list.toLowerCase() + ".exceptions", this.masterList.get(list));
this.syncMobs();
} else {
this.masterList.get(list).remove(value);
this.config.setProperty("worlds." + this.name + "." + list.toLowerCase(), this.masterList.get(list));
}
this.config.save();
@ -429,7 +465,11 @@ public class MVWorld {
}
public void setAliasColor(String aliasColor) {
this.aliasColor = translateStringToChatColor(aliasColor);
try {
this.aliasColor = EnglishChatColor.valueOf(aliasColor).getColor();
} catch (Exception e) {
this.aliasColor = ChatColor.WHITE;
}
if (this.aliasColor != null) {
this.config.setProperty("worlds." + this.name + ".alias.color", aliasColor);
this.config.save();
@ -445,50 +485,13 @@ public class MVWorld {
return this.aliasColor;
}
// I disgust myself. Seriously is there not a better way?
private ChatColor translateStringToChatColor(String color) {
if (color.equalsIgnoreCase("aqua"))
return ChatColor.AQUA;
if (color.equalsIgnoreCase("black"))
return ChatColor.BLACK;
if (color.equalsIgnoreCase("blue"))
return ChatColor.BLUE;
if (color.equalsIgnoreCase("darkaqua"))
return ChatColor.DARK_AQUA;
if (color.equalsIgnoreCase("darkblue"))
return ChatColor.DARK_BLUE;
if (color.equalsIgnoreCase("darkgray"))
return ChatColor.DARK_GRAY;
if (color.equalsIgnoreCase("darkgreen"))
return ChatColor.DARK_GREEN;
if (color.equalsIgnoreCase("darkpurple"))
return ChatColor.DARK_PURPLE;
if (color.equalsIgnoreCase("darkred"))
return ChatColor.DARK_RED;
if (color.equalsIgnoreCase("gold"))
return ChatColor.GOLD;
if (color.equalsIgnoreCase("gray"))
return ChatColor.GRAY;
if (color.equalsIgnoreCase("green"))
return ChatColor.GREEN;
if (color.equalsIgnoreCase("lightpurple"))
return ChatColor.LIGHT_PURPLE;
if (color.equalsIgnoreCase("red"))
return ChatColor.RED;
if (color.equalsIgnoreCase("yellow"))
return ChatColor.YELLOW;
if (color.equalsIgnoreCase("white"))
return ChatColor.WHITE;
return null;
}
public boolean clearList(String property) {
if(property.equalsIgnoreCase("blockblacklist")) {
if (property.equalsIgnoreCase("blockblacklist")) {
this.blockBlacklist.clear();
this.config.setProperty("worlds." + this.name + ".blockblacklist", this.blockBlacklist);
this.config.save();
return true;
} else if(this.masterList.containsKey(property)) {
} else if (this.masterList.containsKey(property)) {
this.masterList.get(property).clear();
this.config.setProperty("worlds." + this.name + "." + property.toLowerCase(), this.masterList.get(property));
this.config.save();