From 0728f0cfd28f77e298363479fad5d83318764c45 Mon Sep 17 00:00:00 2001 From: Mark Hughes Date: Tue, 8 Sep 2015 13:06:57 +1000 Subject: [PATCH] Adds new Animals flag --- .../factions/engine/EngineMain.java | 36 ++++++++++++------- .../factions/entity/FactionColl.java | 3 ++ .../massivecraft/factions/entity/MConf.java | 13 +++++++ .../massivecraft/factions/entity/MFlag.java | 4 +++ 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index aab040cd..35d488d1 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -87,6 +87,7 @@ import com.massivecraft.factions.spigot.SpigotFeatures; import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.PriorityLines; +import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.money.Money; @@ -117,6 +118,19 @@ public class EngineMain extends EngineAbstract return Factions.get(); } + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final Set NATURAL_SPAWN_REASONS = new MassiveSet( + SpawnReason.NATURAL, + SpawnReason.JOCKEY, + SpawnReason.CHUNK_GEN, + SpawnReason.OCELOT_BABY, + SpawnReason.NETHER_PORTAL, + SpawnReason.MOUNT + ); + // -------------------------------------------- // // FACTION SHOW // -------------------------------------------- // @@ -1117,23 +1131,16 @@ public class EngineMain extends EngineAbstract } // -------------------------------------------- // - // FLAG: MONSTERS + // FLAG: MONSTERS & ANIMALS // -------------------------------------------- // @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockMonsters(CreatureSpawnEvent event) + public void blockMonstersAndAnimals(CreatureSpawnEvent event) { - // If a creature is spawning ... - EntityType type = event.getEntityType(); + // First check that it's a natural spawn .. + if ( ! NATURAL_SPAWN_REASONS.contains(event.getSpawnReason())) return; - // ... and that creature is a monster ... - if ( ! MConf.get().entityTypesMonsters.contains(type)) return; - - // ... and the reason for the spawn is natural ... - SpawnReason reason = event.getSpawnReason(); - if (reason != SpawnReason.NATURAL && reason != SpawnReason.JOCKEY && reason != SpawnReason.NETHER_PORTAL) return; - - // ... and monsters are forbidden at the location ... + // .. and if they can spawn here .. Location location = event.getLocation(); if (location == null) return; @@ -1142,8 +1149,11 @@ public class EngineMain extends EngineAbstract Faction faction = BoardColl.get().getFactionAt(ps); if (faction == null) return; - if (faction.getFlag(MFlag.getFlagMonsters())) return; + 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. event.setCancelled(true); } diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index 2012d57c..ed6b5f7f 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -108,6 +108,7 @@ public class FactionColl extends Coll faction.setFlag(MFlag.getFlagPvp(), true); faction.setFlag(MFlag.getFlagFriendlyire(), false); faction.setFlag(MFlag.getFlagMonsters(), true); + faction.setFlag(MFlag.getFlagAnimals(), true); faction.setFlag(MFlag.getFlagExplosions(), true); faction.setFlag(MFlag.getFlagOfflineexplosions(), true); faction.setFlag(MFlag.getFlagFirespread(), true); @@ -142,6 +143,7 @@ public class FactionColl extends Coll faction.setFlag(MFlag.getFlagPvp(), false); faction.setFlag(MFlag.getFlagFriendlyire(), false); faction.setFlag(MFlag.getFlagMonsters(), false); + faction.setFlag(MFlag.getFlagAnimals(), true); faction.setFlag(MFlag.getFlagExplosions(), false); faction.setFlag(MFlag.getFlagOfflineexplosions(), false); faction.setFlag(MFlag.getFlagFirespread(), false); @@ -175,6 +177,7 @@ public class FactionColl extends Coll faction.setFlag(MFlag.getFlagPvp(), true); faction.setFlag(MFlag.getFlagFriendlyire(), true); faction.setFlag(MFlag.getFlagMonsters(), true); + faction.setFlag(MFlag.getFlagAnimals(), true); faction.setFlag(MFlag.getFlagExplosions(), true); faction.setFlag(MFlag.getFlagOfflineexplosions(), true); faction.setFlag(MFlag.getFlagFirespread(), true); diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index 22ca876a..97b45ed7 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -596,6 +596,19 @@ public class MConf extends Entity "ZOMBIE" // Minecraft 1.? ); + // List of entities considered to be animals. + public BackstringEnumSet entityTypesAnimals = new BackstringEnumSet(EntityType.class, + "CHICKEN", // Minecraft 1.? + "COW", // Minecraft 1.? + "HORSE", // Minecraft 1.? + "MUSHROOM_COW", // Minecraft 1.? + "OCELOT", // Minecraft 1.? + "PIG", // Minecraft 1.? + "RABBIT", // Minecraft 1.? + "SHEEP", // Minecraft 1.? + "SQUID" // Minecraft 1.? + ); + // -------------------------------------------- // // INTEGRATION: HeroChat // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/MFlag.java b/src/com/massivecraft/factions/entity/MFlag.java index 569ff7d3..b3f91705 100644 --- a/src/com/massivecraft/factions/entity/MFlag.java +++ b/src/com/massivecraft/factions/entity/MFlag.java @@ -19,6 +19,7 @@ public class MFlag extends Entity implements Prioritized, Registerable public final static transient String ID_OPEN = "open"; public final static transient String ID_MONSTERS = "monsters"; + public final static transient String ID_ANIMALS = "animals"; public final static transient String ID_POWERLOSS = "powerloss"; public final static transient String ID_PVP = "pvp"; public final static transient String ID_FRIENDLYFIRE = "friendlyfire"; @@ -32,6 +33,7 @@ public class MFlag extends Entity implements Prioritized, Registerable public final static transient int PRIORITY_OPEN = 1000; public final static transient int PRIORITY_MONSTERS = 2000; + public final static transient int PRIORITY_ANIMALS = 2500; public final static transient int PRIORITY_POWERLOSS = 3000; public final static transient int PRIORITY_PVP = 4000; public final static transient int PRIORITY_FRIENDLYFIRE = 5000; @@ -68,6 +70,7 @@ public class MFlag extends Entity implements Prioritized, Registerable { getFlagOpen(); getFlagMonsters(); + getFlagAnimals(); getFlagPowerloss(); getFlagPvp(); getFlagFriendlyire(); @@ -82,6 +85,7 @@ public class MFlag extends Entity implements Prioritized, Registerable public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "Anyone can join. No invite required.", "An invite is required to join.", false, true, true); } public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); } + public static MFlag getFlagAnimals() { return getCreative(PRIORITY_ANIMALS, ID_ANIMALS, ID_ANIMALS, "Can animals spawn in this territory?", "Animals can spawn in this territory.", "Animals can NOT spawn in this territory.", true, true, true); } public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); } public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); } public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); }