From 7564798836e02c439112912a7efcc4ccbdd106a2 Mon Sep 17 00:00:00 2001 From: Joseph DeSimpliciis Date: Sat, 19 Apr 2014 00:28:40 -0400 Subject: [PATCH] Tnt flag now prevents explosions from TntMinecarts. --- .../landlord/landFlags/TntDamage.java | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/com/jcdesimp/landlord/landFlags/TntDamage.java b/src/com/jcdesimp/landlord/landFlags/TntDamage.java index e1d4f07..99db020 100644 --- a/src/com/jcdesimp/landlord/landFlags/TntDamage.java +++ b/src/com/jcdesimp/landlord/landFlags/TntDamage.java @@ -73,9 +73,10 @@ public TntDamage() { */ @EventHandler(priority = EventPriority.HIGH) public void tntExplode( EntityExplodeEvent event ){ - if(!event.getEntityType().equals(EntityType.PRIMED_TNT)){ + if(!(event.getEntityType().equals(EntityType.PRIMED_TNT))){ return; } + TNTPrimed tnt = (TNTPrimed)event.getEntity(); OwnedLand land = OwnedLand.getApplicableLand(event.getLocation()); if(land == null){ @@ -98,13 +99,7 @@ public void tntExplode( EntityExplodeEvent event ){ Block block = it.next(); OwnedLand lnd = OwnedLand.getApplicableLand(block.getLocation()); if (lnd != null && !lnd.canEveryone(this) ) { - if(tnt.getSource()!=null){ - Player p = (Player)tnt.getSource(); - if(!lnd.hasPermTo(p, this)){ - it.remove(); - } - - } else { + if (!(tnt.getSource() instanceof Player) || !lnd.hasPermTo((Player) tnt.getSource(), this)) { it.remove(); } @@ -114,6 +109,35 @@ public void tntExplode( EntityExplodeEvent event ){ } + @EventHandler(priority = EventPriority.HIGH) + public void tntMinecartExplode( EntityExplodeEvent event ){ + if(!event.getEntityType().equals(EntityType.MINECART_TNT)){ + return; + } + + OwnedLand land = OwnedLand.getApplicableLand(event.getLocation()); + if (land != null) { + if(!land.canEveryone(this)){ + event.setCancelled(true); + return; + } + + } + + List destroyed = event.blockList(); + Iterator it = destroyed.iterator(); + while (it.hasNext()) { + Block block = it.next(); + OwnedLand lnd = OwnedLand.getApplicableLand(block.getLocation()); + if (lnd != null && !lnd.canEveryone(this)) { + it.remove(); + } + + } + + + } + @EventHandler(priority = EventPriority.HIGH) public void igniteTnt(PlayerInteractEvent event){