From 1a8a601357b3a0cc1ebd75c34861eb4a145da4e8 Mon Sep 17 00:00:00 2001 From: Connor 'Birb' McCormick Date: Sat, 20 Jan 2018 00:59:26 +1300 Subject: [PATCH] Fix for Burning Armor stands exploit Fix for issue where Burning Arrows could ignite Armor Stands regardless of Build Permissions. --- .../factions/engine/EnginePermBuild.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/com/massivecraft/factions/engine/EnginePermBuild.java b/src/com/massivecraft/factions/engine/EnginePermBuild.java index 25cf1f4a..1b4c3d09 100644 --- a/src/com/massivecraft/factions/engine/EnginePermBuild.java +++ b/src/com/massivecraft/factions/engine/EnginePermBuild.java @@ -19,6 +19,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; @@ -31,13 +32,16 @@ import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.projectiles.ProjectileSource; import java.util.Map; @@ -209,6 +213,26 @@ public class EnginePermBuild extends Engine build(player, entity.getLocation().getBlock(), event); } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void combustEntity(EntityCombustByEntityEvent event) { + + // If a burning projectile ... + if (!(event.getCombuster() instanceof Projectile)) return; + Projectile entityProjectile = (Projectile)event.getCombuster(); + + // ... fired by a player ... + ProjectileSource projectileSource = entityProjectile.getShooter(); + if (MUtil.isntPlayer(projectileSource)) return; + + // ... and hits an entity which is edited on damage (and thus likely to burn) ... + Entity entityTarget = event.getEntity(); + if (entityTarget == null || !EnumerationUtil.isEntityTypeEditOnDamage(entityTarget.getType())) return; + + // ... and the player can't build there, cancel the event + Block block = entityTarget.getLocation().getBlock(); + protect(ProtectCase.BUILD, false, projectileSource, PS.valueOf(block), block, event); + } + // -------------------------------------------- // // BUILD > PISTON // -------------------------------------------- //