diff --git a/changelog.md b/changelog.md index a22cb5c..314c4eb 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,8 @@ These changes will (most likely) be included in the next version. ## [Unreleased] +### Fixed +- MobArena no longer throws errors when handling block explosions on Minecraft 1.21. ## [0.108] - 2024-01-01 ### Added diff --git a/src/main/java/com/garbagemule/MobArena/ArenaListener.java b/src/main/java/com/garbagemule/MobArena/ArenaListener.java index 3475dc5..9269bd4 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaListener.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaListener.java @@ -48,6 +48,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockEvent; +import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockIgniteEvent; @@ -453,6 +454,32 @@ public class ArenaListener handleExplodeEventBlocks(event.blockList()); } + public void onBlockExplode(BlockExplodeEvent event) { + if (!arena.getRegion().contains(event.getBlock().getLocation(), 10)) + return; + + // Cancel if the arena isn't running + if (!arena.isRunning()) { + event.setCancelled(true); + return; + } + + // Uncancel, just in case. + event.setCancelled(false); + + // If the arena isn't destructible, just clear the blocklist. + if (!softRestore && protect) { + List blocks = new LinkedList<>(arena.getBlocks()); + event.blockList().retainAll(blocks); + return; + } + + if (!softRestoreDrops) + event.setYield(0); + + handleExplodeEventBlocks(event.blockList()); + } + private void handleExplodeEventBlocks(List blocks) { // Handle all the blocks in the block list. for (Block b : blocks) { diff --git a/src/main/java/com/garbagemule/MobArena/listeners/MAGlobalListener.java b/src/main/java/com/garbagemule/MobArena/listeners/MAGlobalListener.java index 2e486a1..ee01523 100644 --- a/src/main/java/com/garbagemule/MobArena/listeners/MAGlobalListener.java +++ b/src/main/java/com/garbagemule/MobArena/listeners/MAGlobalListener.java @@ -198,19 +198,8 @@ public class MAGlobalListener implements Listener @EventHandler(priority = EventPriority.HIGHEST) public void blockExplode(BlockExplodeEvent event) { - // Create a copy of the block list so we can clear and re-add - List blocks = new ArrayList<>(event.blockList()); - - // Account for Spigot's messy extra event - EntityExplodeEvent fake = new EntityExplodeEvent(null, event.getBlock().getLocation(), blocks, event.getYield()); - fake.setCancelled(event.isCancelled()); - entityExplode(fake); - - // Copy the values over - event.setCancelled(fake.isCancelled()); - event.blockList().clear(); - event.blockList().addAll(fake.blockList()); - event.setYield(fake.getYield()); + for (Arena arena : am.getArenas()) + arena.getEventListener().onBlockExplode(event); } @EventHandler(priority = EventPriority.NORMAL)