From a69395e0c656c3ba40a993aca95d112a9519b358 Mon Sep 17 00:00:00 2001 From: LlmDl Date: Mon, 10 Jun 2024 16:38:59 -0500 Subject: [PATCH] Add protection for BlockExplosionEvents to Cenotaphs. BlockExplosions are made primarily by Beds and Respawn Anchors, Cenotaphs will be protected from those if it is configured. Matches up with how EntityExplodeEvents are handled. --- pom.xml | 20 ++++++++------ .../Minecraft/Cenotaph/CenotaphUtil.java | 2 +- .../Listeners/CenotaphBlockListener.java | 27 +++++++++++++++++++ 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index be469d2..c0cae6a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ MoofIT Cenotaph jar - 6.3 + 6.4 1.14 @@ -18,13 +18,17 @@ spigot-repo https://hub.spigotmc.org/nexus/content/groups/public/ + + glaremasters repo + https://repo.glaremasters.me/repository/towny/ + vault-repo http://nexus.hc.to/content/repositories/pub_releases - sk89q-repo - http://maven.sk89q.com/repo/ + enginehub-maven + https://maven.enginehub.org/repo/ dynamap @@ -45,13 +49,13 @@ org.spigotmc spigot-api - 1.18-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT provided us.dynmap dynmap-api - 2.1-SNAPSHOT + 2.5 net.milkbowl.vault @@ -68,7 +72,7 @@ com.sk89q.worldedit worldedit-bukkit - 7.1.0-SNAPSHOT + 7.2.9 provided @@ -90,9 +94,9 @@ provided - com.github.TownyAdvanced + com.palmergames.bukkit.towny Towny - 0.96.2.0 + 0.100.1.0 provided diff --git a/src/main/java/com/MoofIT/Minecraft/Cenotaph/CenotaphUtil.java b/src/main/java/com/MoofIT/Minecraft/Cenotaph/CenotaphUtil.java index 6981e8b..06e9cc5 100644 --- a/src/main/java/com/MoofIT/Minecraft/Cenotaph/CenotaphUtil.java +++ b/src/main/java/com/MoofIT/Minecraft/Cenotaph/CenotaphUtil.java @@ -288,7 +288,7 @@ public static Boolean canReplace(Material mat) { mat == Material.SUGAR_CANE || mat == Material.GRAVEL || mat == Material.SAND || - mat == Material.GRASS || + mat == Material.SHORT_GRASS || mat == Material.TALL_GRASS || (mat.createBlockData() instanceof Ageable) || (Tag.SMALL_FLOWERS.isTagged(mat) && mat != Material.WITHER_ROSE) || diff --git a/src/main/java/com/MoofIT/Minecraft/Cenotaph/Listeners/CenotaphBlockListener.java b/src/main/java/com/MoofIT/Minecraft/Cenotaph/Listeners/CenotaphBlockListener.java index 0ea5b7f..d2f16ba 100644 --- a/src/main/java/com/MoofIT/Minecraft/Cenotaph/Listeners/CenotaphBlockListener.java +++ b/src/main/java/com/MoofIT/Minecraft/Cenotaph/Listeners/CenotaphBlockListener.java @@ -10,12 +10,14 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import com.MoofIT.Minecraft.Cenotaph.Cenotaph; import com.MoofIT.Minecraft.Cenotaph.CenotaphDatabase; import com.MoofIT.Minecraft.Cenotaph.CenotaphMessaging; +import com.MoofIT.Minecraft.Cenotaph.CenotaphSettings; import com.MoofIT.Minecraft.Cenotaph.CenotaphUtil; import com.MoofIT.Minecraft.Cenotaph.TombBlock; import com.MoofIT.Minecraft.Cenotaph.Config.Lang; @@ -144,4 +146,29 @@ public void onBlockBurnMonitor(BlockBurnEvent event) { return; CenotaphDatabase.removeTomb(CenotaphUtil.getTombBlock(block), true); } + + @EventHandler + public void onBlockExplode(BlockExplodeEvent event) { + if (event.isCancelled()) + return; + for (Block block : event.blockList()) { + if (CenotaphUtil.isTombBlock(block)) { + if (CenotaphUtil.getTombBlock(block).isSecured()) + event.setCancelled(true); + else if (CenotaphSettings.explosionProtection()) + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onBlockExplodeMonitor(BlockExplodeEvent event) { + if (event.isCancelled()) + return; + for (Block block : event.blockList()) { + if (CenotaphUtil.isTombBlock(block)) + if (!event.isCancelled()) + CenotaphDatabase.removeTomb(CenotaphUtil.getTombBlock(block), true); + } + } }