Skip to content
Prev Previous commit
Apply suggestions by granny
  • Loading branch information
SageSphinx63920 committed Mar 1, 2023
commit 6e2fa8005ac2b752772ba4808e9cc0691177470e
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@ Subject: [PATCH] Add PreExplodeEvents

diff --git a/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java b/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..e4bfca1ca2f1cba73244819af6340951498cf4af
index 0000000000000000000000000000000000000000..b7db0db7f3afbccdb07390d1bcada109e9e6b30b
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java
@@ -0,0 +1,51 @@
@@ -0,0 +1,52 @@
+package org.purpurmc.purpur.event;
+
+import org.bukkit.block.Block;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.block.BlockEvent;
+import org.bukkit.event.block.BlockExplodeEvent;
+import org.jetbrains.annotations.NotNull;
+import java.util.Collections;
+
+/**
+ * Called before a block's explosion is processed
+ */
+public class PreBlockExplodeEvent extends BlockEvent implements Cancellable {
+public class PreBlockExplodeEvent extends BlockExplodeEvent implements Cancellable {
+ private static final HandlerList handlers = new HandlerList();
+ private boolean cancelled;
+ private final float yield;
+
+ public PreBlockExplodeEvent(@NotNull final Block what, final float yield) {
Comment thread
granny marked this conversation as resolved.
+ super(what);
+ super(what, Collections.emptyList(), yield);
+ this.yield = yield;
+ this.cancelled = false;
+ }
Expand Down Expand Up @@ -63,29 +64,30 @@ index 0000000000000000000000000000000000000000..e4bfca1ca2f1cba73244819af6340951
+}
diff --git a/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java b/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..f4740487f80b53be80c4ef2f222616cc61e67c52
index 0000000000000000000000000000000000000000..2d4f68228861492baaea0bcc604dfef623b337ba
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java
@@ -0,0 +1,63 @@
@@ -0,0 +1,64 @@
+package org.purpurmc.purpur.event.entity;
+
+import org.bukkit.Location;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.bukkit.event.entity.EntityExplodeEvent;
+import org.jetbrains.annotations.NotNull;
+import java.util.Collections;
+
+/**
+ * Called before an entity's explosion is processed
+ */
+public class PreEntityExplodeEvent extends EntityEvent implements Cancellable {
+public class PreEntityExplodeEvent extends EntityExplodeEvent implements Cancellable {
+ private static final HandlerList handlers = new HandlerList();
+ private boolean cancelled;
+ private final float yield;
+ private final Location location;
+
+ public PreEntityExplodeEvent(@NotNull org.bukkit.entity.Entity what, @NotNull final Location location, final float yield) {
+ super(what);
+ super(what, location, Collections.emptyList(), yield);
+ this.cancelled = false;
+ this.yield = yield;
+ this.location = location;
Expand Down
14 changes: 3 additions & 11 deletions patches/server/0310-Add-PreExplodeEvents.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@ 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 51d8271cb8fe246f4c11db8fbc061ed63f416da0..3707347ec139b3ac0010fe0460314fd593f58fb6 100644
index 3c9e0cee78deeae6b47a186f1bfc47f3956ec9c7..cd63170e56b402fbf8bbd904270979fa51330e26 100644
--- a/src/main/java/net/minecraft/world/level/Explosion.java
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
@@ -45,6 +45,7 @@ import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.Location;
import org.bukkit.event.block.BlockExplodeEvent;
+import org.purpurmc.purpur.event.entity.PreEntityExplodeEvent;
// CraftBukkit end

public class Explosion {
@@ -141,6 +142,23 @@ public class Explosion {
@@ -141,6 +141,23 @@ 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 PreEntityExplodeEvent(this.source.getBukkitEntity(), location, this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F).callEvent()) {
+ 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;
+ }
Expand Down