From 0ddf4b743560b0776ab4912b2b7580e8282a0d57 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 1 Nov 2020 11:41:53 -0500 Subject: [PATCH] Stop explosions breaking reinforced hanging entities --- .../mc/citadel/listener/EntityListener.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/vg/civcraft/mc/citadel/listener/EntityListener.java b/src/main/java/vg/civcraft/mc/citadel/listener/EntityListener.java index 4702c501..70f94caa 100644 --- a/src/main/java/vg/civcraft/mc/citadel/listener/EntityListener.java +++ b/src/main/java/vg/civcraft/mc/citadel/listener/EntityListener.java @@ -26,6 +26,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; +import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerJoinEvent; @@ -129,7 +130,7 @@ private List getGolemBlocks(EntityType type, Block base) { public void playerJoinEvent(PlayerJoinEvent event) { Player p = event.getPlayer(); final UUID uuid = p.getUniqueId(); - + new BukkitRunnable() { @Override @@ -228,6 +229,26 @@ public void hangingEntityBreakEvent(HangingBreakByEntityEvent event) { event.setCancelled(true); } + @EventHandler(priority = EventPriority.HIGHEST) + public void HangingBreakEvent(HangingBreakEvent event) { + if (!Citadel.getInstance().getConfigManager().doHangersInheritReinforcements()) { + return; + } + if (event.getCause() != HangingBreakEvent.RemoveCause.EXPLOSION){ + return; + } + Hanging entity = event.getEntity(); + Block host = entity.getLocation().getBlock().getRelative(entity.getAttachedFace()); + Reinforcement reinforcement = ReinforcementLogic.getReinforcementProtecting(host); + if (reinforcement == null) { + return; + } + if (reinforcement.isInsecure()) { + return; + } + event.setCancelled(true); + } + @EventHandler(priority = EventPriority.HIGHEST) public void entityDamageEvent(EntityDamageByEntityEvent event) { if (!Citadel.getInstance().getConfigManager().doHangersInheritReinforcements()) {