mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-26 04:25:37 +01:00
Fix Monster/Animals Spawning
This commit is contained in:
parent
535dcded34
commit
4f7c2d507a
@ -1,5 +1,7 @@
|
|||||||
package com.onarandombox.MultiverseCore;
|
package com.onarandombox.MultiverseCore;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Animals;
|
import org.bukkit.entity.Animals;
|
||||||
import org.bukkit.entity.CreatureType;
|
import org.bukkit.entity.CreatureType;
|
||||||
@ -56,75 +58,42 @@ public class MVEntityListener extends EntityListener {
|
|||||||
|
|
||||||
MVWorld mvworld = this.plugin.getMVWorld(world.getName());
|
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...
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getAnimalList(), mvworld.allowAnimalSpawning(), creature.toString().toUpperCase()));
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Monster Handling
|
* Monster Handling
|
||||||
*/
|
*/
|
||||||
if (event.getEntity() instanceof Monster || event.getEntity() instanceof Ghast || 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.
|
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getMonsterList(), mvworld.allowMonsterSpawning(), creature.toString().toUpperCase()));
|
||||||
if (mvworld.getMonsterList().isEmpty()) {
|
|
||||||
if (mvworld.allowMonsterSpawning()) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
event.setCancelled(true);
|
|
||||||
System.out.print("MV is killing a " + event.getCreatureType());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// The idea of the Exceptions is they do the OPPOSITE of what the Spawn setting is...
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldWeKillThisCreature(List<String> creatureList, boolean allowCreatureSpawning, String creature) {
|
||||||
|
if (creatureList.isEmpty() && allowCreatureSpawning) {
|
||||||
|
// 1. There are no exceptions and animals are allowd. Save it.
|
||||||
|
return false;
|
||||||
|
} else if (creatureList.isEmpty()) {
|
||||||
|
// 2. There are no exceptions and animals are NOT allowed. Kill it.
|
||||||
|
return true;
|
||||||
|
} else if (creatureList.contains(creature) && allowCreatureSpawning) {
|
||||||
|
// 3. There ARE exceptions and animals ARE allowed. Kill it.
|
||||||
|
return true;
|
||||||
|
} else if (!creatureList.contains(creature.toString().toUpperCase()) && allowCreatureSpawning) {
|
||||||
|
// 4. There ARE exceptions and animals ARE NOT allowed. SAVE it.
|
||||||
|
return false;
|
||||||
|
} else if (creatureList.contains(creature.toString().toUpperCase()) && !allowCreatureSpawning) {
|
||||||
|
// 5. No animals are allowed to be spawned, BUT this one can stay...
|
||||||
|
return false;
|
||||||
|
} else if (!creatureList.contains(creature.toString().toUpperCase()) && !allowCreatureSpawning) {
|
||||||
|
// 6. Animals are NOT allowd to spawn, and this creature is not in the save list... KILL IT
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// This code should NEVER execute. I just left the verbose conditions in right now.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user