diff --git a/src/main/java/dev/espi/protectionstones/ListenerClass.java b/src/main/java/dev/espi/protectionstones/ListenerClass.java index 87175a00..5cc4f2a5 100644 --- a/src/main/java/dev/espi/protectionstones/ListenerClass.java +++ b/src/main/java/dev/espi/protectionstones/ListenerClass.java @@ -37,6 +37,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.entity.WindCharge; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -50,7 +51,6 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import java.util.List; @@ -372,7 +372,7 @@ public void onSpongeAbsorb(SpongeAbsorbEvent event) { event.setCancelled(true); } } - + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockFade(BlockFadeEvent e) { if (ProtectionStones.isProtectBlock(e.getBlock())) { @@ -437,12 +437,13 @@ private void pistonUtil(List pushedBlocks, BlockPistonEvent e) { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockExplode(BlockExplodeEvent e) { - explodeUtil(e.blockList(), e.getBlock().getLocation().getWorld()); + explodeUtil(e.blockList(), e.getBlock().getLocation().getWorld(), false); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent e) { - explodeUtil(e.blockList(), e.getLocation().getWorld()); + boolean isWindCharge = e.getEntity() instanceof WindCharge; + explodeUtil(e.blockList(), e.getLocation().getWorld(), isWindCharge); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @@ -450,13 +451,13 @@ public void onEntityChangeBlock(EntityChangeBlockEvent e) { if (!ProtectionStones.isProtectBlock(e.getBlock())) return; // events like ender dragon block break, wither running into block break, etc. - if (!blockExplodeUtil(e.getBlock().getWorld(), e.getBlock())) { + if (!blockExplodeUtil(e.getBlock().getWorld(), e.getBlock(), false)) { // if block shouldn't be exploded, cancel the event e.setCancelled(true); } } - private void explodeUtil(List blockList, World w) { + private void explodeUtil(List blockList, World w, boolean isWindCharge) { // loop through exploded blocks for (int i = 0; i < blockList.size(); i++) { Block b = blockList.get(i); @@ -467,12 +468,12 @@ private void explodeUtil(List blockList, World w) { i--; } - blockExplodeUtil(w, b); + blockExplodeUtil(w, b, isWindCharge); } } // returns whether the block is exploded - private boolean blockExplodeUtil(World w, Block b) { + private boolean blockExplodeUtil(World w, Block b, boolean isWindCharge) { if (ProtectionStones.isProtectBlock(b)) { String id = WGUtils.createPSID(b.getLocation()); PSProtectBlock blockOptions = ProtectionStones.getBlockOptions(b); @@ -482,6 +483,10 @@ private boolean blockExplodeUtil(World w, Block b) { return false; } + if (isWindCharge && blockOptions.preventWindChargeExplode) { + return false; + } + // manually set to air if exploded so there is no natural item drop b.setType(Material.AIR); diff --git a/src/main/java/dev/espi/protectionstones/PSProtectBlock.java b/src/main/java/dev/espi/protectionstones/PSProtectBlock.java index fb2e214a..1262e418 100644 --- a/src/main/java/dev/espi/protectionstones/PSProtectBlock.java +++ b/src/main/java/dev/espi/protectionstones/PSProtectBlock.java @@ -137,6 +137,8 @@ public class PSProtectBlock { public boolean preventPistonPush; @Path("behaviour.prevent_explode") public boolean preventExplode; + @Path("behaviour.prevent_wind_charge_explode") + public boolean preventWindChargeExplode; @Path("behaviour.destroy_region_when_explode") public boolean destroyRegionWhenExplode; @Path("behaviour.prevent_silk_touch") diff --git a/src/main/java/dev/espi/protectionstones/placeholders/ConfigPlaceholders.java b/src/main/java/dev/espi/protectionstones/placeholders/ConfigPlaceholders.java index 845e5a35..8c4b364d 100644 --- a/src/main/java/dev/espi/protectionstones/placeholders/ConfigPlaceholders.java +++ b/src/main/java/dev/espi/protectionstones/placeholders/ConfigPlaceholders.java @@ -218,6 +218,8 @@ static String resolveBlockConfig(PSProtectBlock b, String identifier) { return b.preventPistonPush + ""; case "behaviour_prevent_explode": return b.preventExplode + ""; + case "behaviour_prevent_wind_charge_explode": + return b.preventWindChargeExplode + ""; case "behaviour_destroy_region_when_explode": return b.destroyRegionWhenExplode + ""; case "behaviour_prevent_silk_touch": diff --git a/src/main/resources/block1.toml b/src/main/resources/block1.toml index c4dee39d..4abb4c55 100644 --- a/src/main/resources/block1.toml +++ b/src/main/resources/block1.toml @@ -224,6 +224,10 @@ placing_bypasses_wg_passthrough = true # Recommended to keep true to prevent players from exploiting more protection stones with /ps unhide (when the block is destroyed) prevent_explode = true + # Prevents the block from being destroyed when exploded wind charge. + # Recommended to keep true if you don't want to ban all explosions, but don't want the region to explode using this method + prevent_wind_charge_explode = true + # Destroys the protection stone region when block is exploded. Can be useful for PVP/Factions servers. # prevent_explode must be false for this to work. destroy_region_when_explode = false