mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 12:05:14 +01:00
Don't prevent plugins from spawning creatures.
This commit is contained in:
parent
2ff10d0882
commit
6858c878d3
@ -10,6 +10,7 @@ import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
@ -17,20 +18,20 @@ import org.bukkit.event.entity.EntityListener;
|
||||
//import org.bukkit.event.entity.ExplosionPrimedEvent;
|
||||
|
||||
public class MVEntityListener extends EntityListener {
|
||||
|
||||
|
||||
MultiverseCore plugin;
|
||||
|
||||
|
||||
public MVEntityListener(MultiverseCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
// Need to find a way to stop the Ghast Fireballs damaging
|
||||
// surroundings but still doing damage to players.
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
@ -39,25 +40,30 @@ public class MVEntityListener extends EntityListener {
|
||||
}
|
||||
super.onEntityDeath(event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle Animal/Monster Spawn settings, seems like a more concrete method than using CraftBukkit.
|
||||
*/
|
||||
@Override
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
|
||||
|
||||
// Check to see if the Creature is spawned by a plugin, we don't want to prevent this behaviour.
|
||||
if (event.getSpawnReason() == SpawnReason.CUSTOM) {
|
||||
return;
|
||||
}
|
||||
|
||||
World world = event.getEntity().getWorld();
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
|
||||
// Check if it's a world which we are meant to be managing.
|
||||
if (!(this.plugin.isMVWorld(world.getName())))
|
||||
return;
|
||||
|
||||
|
||||
CreatureType creature = event.getCreatureType();
|
||||
|
||||
|
||||
MVWorld mvworld = this.plugin.getMVWorld(world.getName());
|
||||
|
||||
|
||||
/**
|
||||
* Animal Handling
|
||||
*/
|
||||
@ -71,7 +77,7 @@ public class MVEntityListener extends EntityListener {
|
||||
event.setCancelled(this.shouldWeKillThisCreature(mvworld.getMonsterList(), mvworld.allowMonsterSpawning(), creature.toString().toUpperCase()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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.
|
||||
@ -86,14 +92,14 @@ public class MVEntityListener extends EntityListener {
|
||||
// 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...
|
||||
// 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
|
||||
// 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