From 1d26e189165b36c36fc5e9f29b50329b7a848c4d Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 6 Mar 2011 14:13:48 -0600 Subject: [PATCH] Added option ("territoryBlockCreepers") to prevent creepers from destroying blocks if they explode inside faction owned territory, which defaults to disabled; if enabled, it prevents griefing by way of luring creepers into a faction's territory note that creepers will still explode and hurt nearby players and mobs, they just won't destroy blocks --- src/com/bukkit/mcteam/factions/Factions.java | 1 + .../bukkit/mcteam/factions/entities/Conf.java | 1 + .../listeners/FactionsEntityListener.java | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/com/bukkit/mcteam/factions/Factions.java b/src/com/bukkit/mcteam/factions/Factions.java index cd17d27f..98597c63 100644 --- a/src/com/bukkit/mcteam/factions/Factions.java +++ b/src/com/bukkit/mcteam/factions/Factions.java @@ -42,6 +42,7 @@ public class Factions extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGED, this.entityListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_DAMAGED, this.blockListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PLACED, this.blockListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_INTERACT, this.blockListener, Event.Priority.Normal, this); diff --git a/src/com/bukkit/mcteam/factions/entities/Conf.java b/src/com/bukkit/mcteam/factions/entities/Conf.java index 29456bb4..410382f8 100644 --- a/src/com/bukkit/mcteam/factions/entities/Conf.java +++ b/src/com/bukkit/mcteam/factions/entities/Conf.java @@ -42,6 +42,7 @@ public class Conf { public static int mapWidth = 49; public static double territoryShieldFactor = 0.5; + public static boolean territoryBlockCreepers = false; public static List territoryProtectedMaterials = new ArrayList(); // Command names / aliases diff --git a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java index 8ff28041..b0f4e5d2 100644 --- a/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java @@ -4,15 +4,19 @@ import java.text.DecimalFormat; import org.bukkit.ChatColor; import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByProjectileEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityListener; import com.bukkit.mcteam.factions.Factions; +import com.bukkit.mcteam.factions.entities.Board; import com.bukkit.mcteam.factions.entities.Conf; +import com.bukkit.mcteam.factions.entities.Coord; import com.bukkit.mcteam.factions.entities.Follower; import com.bukkit.mcteam.factions.struct.Relation; @@ -59,7 +63,20 @@ public class FactionsEntityListener extends EntityListener { } } } - + + @Override + public void onEntityExplode(EntityExplodeEvent event) + { + if (Conf.territoryBlockCreepers && event.getEntity() instanceof LivingEntity) + { // creeper which might need prevention, if inside faction territory + if (Board.get(event.getLocation().getWorld()).getFactionIdAt(Coord.from(event.getLocation())) > 0) + { + event.setCancelled(true); + return; + } + } + } + public boolean canDamagerHurtDamagee(Entity damager, Entity damagee, int damage) { if ( ! (damager instanceof Player)) { return true;