From fe68d57b23d20b6e33aa2b77d46031f6e9e82684 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 9 Sep 2015 08:40:35 +0200 Subject: [PATCH] Fix bug. Nothing spawning. --- .../factions/engine/EngineMain.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index 35d488d1..a6d214f2 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -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 // -------------------------------------------- //