Fix bug. Nothing spawning.

This commit is contained in:
Olof Larsson 2015-09-09 08:40:35 +02:00
parent 0728f0cfd2
commit fe68d57b23

View File

@ -1137,27 +1137,47 @@ public class EngineMain extends EngineAbstract
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockMonstersAndAnimals(CreatureSpawnEvent event)
{
// First check that it's a natural spawn ..
// If this is a natural spawn ..
if ( ! NATURAL_SPAWN_REASONS.contains(event.getSpawnReason())) return;
// .. and if they can spawn here ..
// ... get the spawn location ...
Location location = event.getLocation();
if (location == null) return;
PS ps = PS.valueOf(location);
// ... get the faction there ...
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction == null) return;
// ... get the entity type ...
EntityType type = event.getEntityType();
if ((faction.getFlag(MFlag.getFlagMonsters()) && MConf.get().entityTypesMonsters.contains(type)) &&
(faction.getFlag(MFlag.getFlagAnimals()) && MConf.get().entityTypesAnimals.contains(type))) return;
// ... block the spawn.
// ... and if this type can't spawn in the faction ...
if (canSpawn(faction, type)) return;
// ... then cancel.
event.setCancelled(true);
}
public static boolean canSpawn(Faction faction, EntityType type)
{
if (MConf.get().entityTypesMonsters.contains(type))
{
// Monster
return faction.getFlag(MFlag.getFlagMonsters());
}
else if (MConf.get().entityTypesAnimals.contains(type))
{
// Animal
return faction.getFlag(MFlag.getFlagAnimals());
}
else
{
// Other
return true;
}
}
// -------------------------------------------- //
// FLAG: EXPLOSIONS
// -------------------------------------------- //