From 34e4afee2c1f376830b6c62bf561ec4afc1f232a Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 22 Sep 2011 06:22:01 -0500 Subject: [PATCH] Four new conf.json settings to prevent Endermen from removing or placing blocks. "territoryDenyEndermanBlocks" (default true) for claimed territory. "safeZoneDenyEndermanBlocks" (default true) for Safe Zones. "warZoneDenyEndermanBlocks" (default true) for War Zones. "wildernessDenyEndermanBlocks" (default false) for unclaimed wilderness areas. --- src/com/massivecraft/factions/Conf.java | 4 ++ src/com/massivecraft/factions/Factions.java | 2 + .../listeners/FactionsEntityListener.java | 56 +++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index a9e38b97..49257bab 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -126,11 +126,13 @@ public class Conf { public static boolean territoryBlockFireballsWhenOffline = false; public static boolean territoryBlockTNT = false; public static boolean territoryBlockTNTWhenOffline = false; + public static boolean territoryDenyEndermanBlocks = true; public static boolean safeZoneDenyBuild = true; public static boolean safeZoneDenyUseage = true; public static boolean safeZoneBlockTNT = true; public static boolean safeZonePreventAllDamageToPlayers = false; + public static boolean safeZoneDenyEndermanBlocks = true; public static boolean warZoneDenyBuild = true; public static boolean warZoneDenyUseage = true; @@ -139,6 +141,7 @@ public class Conf { public static boolean warZoneBlockTNT = true; public static boolean warZonePowerLoss = true; public static boolean warZoneFriendlyFire = false; + public static boolean warZoneDenyEndermanBlocks = true; public static boolean wildernessDenyBuild = false; public static boolean wildernessDenyUseage = false; @@ -146,6 +149,7 @@ public class Conf { public static boolean wildernessBlockFireballs = false; public static boolean wildernessBlockTNT = false; public static boolean wildernessPowerLoss = true; + public static boolean wildernessDenyEndermanBlocks = false; // for claimed areas where further faction-member ownership can be defined public static boolean ownedAreasEnabled = true; diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index bd976317..d61eb460 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -168,6 +168,8 @@ public class Factions extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Event.Priority.High, this); pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this.playerListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.ENDERMAN_PICKUP, this.entityListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.ENDERMAN_PLACE, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal, this); diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index c263d099..3b1a8bc2 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -10,6 +10,8 @@ import org.bukkit.entity.Fireball; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EndermanPickupEvent; +import org.bukkit.event.entity.EndermanPlaceEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; @@ -389,4 +391,58 @@ public class FactionsEntityListener extends EntityListener { return true; } + + @Override + public void onEndermanPickup(EndermanPickupEvent event) { + if (event.isCancelled()) { + return; + } + + if (stopEndermanBlockManipulation(event.getBlock().getLocation())) { + event.setCancelled(true); + } + } + + @Override + public void onEndermanPlace(EndermanPlaceEvent event) { + if (event.isCancelled()) { + return; + } + + if (stopEndermanBlockManipulation(event.getLocation())) { + event.setCancelled(true); + } + } + + private boolean stopEndermanBlockManipulation(Location loc) { + if (loc == null) { + return false; + } + // quick check to see if all Enderman deny options are enabled; if so, no need to check location + if ( Conf.wildernessDenyEndermanBlocks + && Conf.territoryDenyEndermanBlocks + && Conf.safeZoneDenyEndermanBlocks + && Conf.warZoneDenyEndermanBlocks + ) { + return true; + } + + FLocation fLoc = new FLocation(loc); + Faction claimFaction = Board.getFactionAt(fLoc); + + if (claimFaction.isNone()) { + return Conf.wildernessDenyEndermanBlocks; + } + else if (claimFaction.isNormal()) { + return Conf.territoryDenyEndermanBlocks; + } + else if (claimFaction.isSafeZone()) { + return Conf.safeZoneDenyEndermanBlocks; + } + else if (claimFaction.isWarZone()) { + return Conf.warZoneDenyEndermanBlocks; + } + + return false; + } }