From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: SageSphinx63920 Date: Mon, 26 Dec 2022 23:42:37 +0100 Subject: [PATCH] Add PreExplodeEvents diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java index d7cd063240a2799996cf7efa3f766ee748702db1..5248e32e2109494904bc16839b2f202dab3d96c9 100644 --- a/src/main/java/net/minecraft/world/level/Explosion.java +++ b/src/main/java/net/minecraft/world/level/Explosion.java @@ -407,6 +407,25 @@ public class Explosion { return; } // CraftBukkit end + + // Purpur start - add PreExplodeEvents + if(this.source != null){ + Location location = new Location(this.level.getWorld(), this.x, this.y, this.z); + if(!new org.purpurmc.purpur.event.entity.PreEntityExplodeEvent(this.source.getBukkitEntity(), location, this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F).callEvent()) { + this.wasCanceled = true; + return; + } + }else { + Location location = new Location(this.level.getWorld(), this.x, this.y, this.z); + org.bukkit.block.Block block = location.getBlock(); + org.bukkit.block.BlockState blockState = (this.damageSource.getDirectBlockState() != null) ? this.damageSource.getDirectBlockState() : block.getState(); + if(!new org.purpurmc.purpur.event.PreBlockExplodeEvent(location.getBlock(), this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F, blockState).callEvent()) { + this.wasCanceled = true; + return; + } + } + //Purpur end + this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, new Vec3(this.x, this.y, this.z)); // Paper start - collision optimisations