From f612ac34abfc125e659598333ae9bc485206678e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 11 Dec 2015 13:34:36 +0100 Subject: [PATCH] Add zombiegrief flag --- .../factions/engine/EngineMain.java | 24 ++++++++++++++- .../factions/entity/FactionColl.java | 3 ++ .../massivecraft/factions/entity/MFlag.java | 29 ++++++++++--------- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index 98dd9910..ee5a02de 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -26,6 +26,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Wither; +import org.bukkit.entity.Zombie; import org.bukkit.event.Cancellable; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -48,6 +49,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityBreakDoorEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingPlaceEvent; @@ -1275,7 +1277,27 @@ public class EngineMain extends EngineAbstract // ... stop the block alteration. event.setCancelled(true); } - + + // -------------------------------------------- // + // FLAG: ZOMBIEGRIEF + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void denyZombieGrief(EntityBreakDoorEvent event) + { + // If a zombie is breaking a door ... + Entity entity = event.getEntity(); + if (!(entity instanceof Zombie)) return; + + // ... and the faction there has zombiegrief disabled ... + PS ps = PS.valueOf(event.getBlock()); + Faction faction = BoardColl.get().getFactionAt(ps); + if (faction.getFlag(MFlag.getFlagZombiegrief())) return; + + // ... stop the door breakage. + event.setCancelled(true); + } + // -------------------------------------------- // // FLAG: FIRE SPREAD // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index ed6b5f7f..3ef4c15d 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -113,6 +113,7 @@ public class FactionColl extends Coll faction.setFlag(MFlag.getFlagOfflineexplosions(), true); faction.setFlag(MFlag.getFlagFirespread(), true); faction.setFlag(MFlag.getFlagEndergrief(), true); + faction.setFlag(MFlag.getFlagZombiegrief(), true); faction.setPermittedRelations(MPerm.getPermBuild(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); faction.setPermittedRelations(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); @@ -148,6 +149,7 @@ public class FactionColl extends Coll faction.setFlag(MFlag.getFlagOfflineexplosions(), false); faction.setFlag(MFlag.getFlagFirespread(), false); faction.setFlag(MFlag.getFlagEndergrief(), false); + faction.setFlag(MFlag.getFlagZombiegrief(), false); faction.setPermittedRelations(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); faction.setPermittedRelations(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); @@ -182,6 +184,7 @@ public class FactionColl extends Coll faction.setFlag(MFlag.getFlagOfflineexplosions(), true); faction.setFlag(MFlag.getFlagFirespread(), true); faction.setFlag(MFlag.getFlagEndergrief(), true); + faction.setFlag(MFlag.getFlagZombiegrief(), true); faction.setPermittedRelations(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); faction.setPermittedRelations(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); diff --git a/src/com/massivecraft/factions/entity/MFlag.java b/src/com/massivecraft/factions/entity/MFlag.java index 1ab5a956..f05f1629 100644 --- a/src/com/massivecraft/factions/entity/MFlag.java +++ b/src/com/massivecraft/factions/entity/MFlag.java @@ -28,23 +28,25 @@ public class MFlag extends Entity implements Prioritized, Registerable, N public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions"; public final static transient String ID_FIRESPREAD = "firespread"; public final static transient String ID_ENDERGRIEF = "endergrief"; + public final static transient String ID_ZOMBIEGRIEF = "zombiegrief"; public final static transient String ID_PERMANENT = "permanent"; public final static transient String ID_PEACEFUL = "peaceful"; public final static transient String ID_INFPOWER = "infpower"; - 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; - public final static transient int PRIORITY_EXPLOSIONS = 6000; - public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 7000; - public final static transient int PRIORITY_FIRESPREAD = 8000; - public final static transient int PRIORITY_ENDERGRIEF = 9000; - public final static transient int PRIORITY_PERMANENT = 10000; - public final static transient int PRIORITY_PEACEFUL = 11000; - public final static transient int PRIORITY_INFPOWER = 12000; + public final static transient int PRIORITY_OPEN = 1_000; + public final static transient int PRIORITY_MONSTERS = 2_000; + public final static transient int PRIORITY_ANIMALS = 3_000; + public final static transient int PRIORITY_POWERLOSS = 4_000; + public final static transient int PRIORITY_PVP = 5_000; + public final static transient int PRIORITY_FRIENDLYFIRE = 6_000; + public final static transient int PRIORITY_EXPLOSIONS = 7_000; + public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 8_000; + public final static transient int PRIORITY_FIRESPREAD = 9_000; + public final static transient int PRIORITY_ENDERGRIEF = 10_000; + public final static transient int PRIORITY_ZOMBIEGRIEF = 11_000; + public final static transient int PRIORITY_PERMANENT = 12_000; + public final static transient int PRIORITY_PEACEFUL = 13_000; + public final static transient int PRIORITY_INFPOWER = 14_000; // -------------------------------------------- // // META: CORE @@ -94,6 +96,7 @@ public class MFlag extends Entity implements Prioritized, Registerable, N public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions if faction is offline.", "No explosions if faction is offline.", false, false, true); } public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", "Fire can spread in this territory.", "Fire can NOT spread in this territory.", true, false, true); } public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", "Endermen can grief in this territory.", "Endermen can NOT grief in this territory.", false, false, true); } + public static MFlag getFlagZombiegrief() { return getCreative(PRIORITY_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, "Can zombies break doors in this territory?", "Zombies can break doors in this territory.", "Zombies can NOT break doors in this territory.", false, false, true); } public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); } public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Is the faction in truce with everyone?", "The faction is in truce with everyone.", "The faction relations work as usual.", false, false, true); } public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "Does the faction have infinite power?", "The faction has infinite power.", "The faction power works as usual.", false, false, true); }