Skip to content

Commit 3940c82

Browse files
Add PreExplodeEvents (#1234)
1 parent c5f1057 commit 3940c82

3 files changed

Lines changed: 168 additions & 0 deletions

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: SageSphinx63920 <sage@sagesphinx63920.dev>
3+
Date: Mon, 26 Dec 2022 23:40:13 +0100
4+
Subject: [PATCH] Add PreExplodeEvents
5+
6+
7+
diff --git a/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java b/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java
8+
new file mode 100644
9+
index 0000000000000000000000000000000000000000..b7db0db7f3afbccdb07390d1bcada109e9e6b30b
10+
--- /dev/null
11+
+++ b/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java
12+
@@ -0,0 +1,52 @@
13+
+package org.purpurmc.purpur.event;
14+
+
15+
+import org.bukkit.block.Block;
16+
+import org.bukkit.event.Cancellable;
17+
+import org.bukkit.event.HandlerList;
18+
+import org.bukkit.event.block.BlockExplodeEvent;
19+
+import org.jetbrains.annotations.NotNull;
20+
+import java.util.Collections;
21+
+
22+
+/**
23+
+ * Called before a block's explosion is processed
24+
+ */
25+
+public class PreBlockExplodeEvent extends BlockExplodeEvent implements Cancellable {
26+
+ private static final HandlerList handlers = new HandlerList();
27+
+ private boolean cancelled;
28+
+ private final float yield;
29+
+
30+
+ public PreBlockExplodeEvent(@NotNull final Block what, final float yield) {
31+
+ super(what, Collections.emptyList(), yield);
32+
+ this.yield = yield;
33+
+ this.cancelled = false;
34+
+ }
35+
+
36+
+ /**
37+
+ * Returns the percentage of blocks to drop from this explosion
38+
+ *
39+
+ * @return The yield.
40+
+ */
41+
+ public float getYield() {
42+
+ return yield;
43+
+ }
44+
+
45+
+ @Override
46+
+ public boolean isCancelled() {
47+
+ return this.cancelled;
48+
+ }
49+
+
50+
+ @Override
51+
+ public void setCancelled(boolean cancel) {
52+
+ this.cancelled = cancel;
53+
+ }
54+
+
55+
+ @Override
56+
+ public @NotNull HandlerList getHandlers() {
57+
+ return handlers;
58+
+ }
59+
+
60+
+ @NotNull
61+
+ public static HandlerList getHandlerList() {
62+
+ return handlers;
63+
+ }
64+
+}
65+
diff --git a/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java b/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java
66+
new file mode 100644
67+
index 0000000000000000000000000000000000000000..2d4f68228861492baaea0bcc604dfef623b337ba
68+
--- /dev/null
69+
+++ b/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java
70+
@@ -0,0 +1,64 @@
71+
+package org.purpurmc.purpur.event.entity;
72+
+
73+
+import org.bukkit.Location;
74+
+import org.bukkit.event.Cancellable;
75+
+import org.bukkit.event.HandlerList;
76+
+import org.bukkit.event.entity.EntityExplodeEvent;
77+
+import org.jetbrains.annotations.NotNull;
78+
+import java.util.Collections;
79+
+
80+
+/**
81+
+ * Called before an entity's explosion is processed
82+
+ */
83+
+public class PreEntityExplodeEvent extends EntityExplodeEvent implements Cancellable {
84+
+ private static final HandlerList handlers = new HandlerList();
85+
+ private boolean cancelled;
86+
+ private final float yield;
87+
+ private final Location location;
88+
+
89+
+ public PreEntityExplodeEvent(@NotNull org.bukkit.entity.Entity what, @NotNull final Location location, final float yield) {
90+
+ super(what, location, Collections.emptyList(), yield);
91+
+ this.cancelled = false;
92+
+ this.yield = yield;
93+
+ this.location = location;
94+
+ }
95+
+
96+
+ /**
97+
+ * Returns the percentage of blocks to drop from this explosion
98+
+ *
99+
+ * @return The yield.
100+
+ */
101+
+ public float getYield() {
102+
+ return yield;
103+
+ }
104+
+
105+
+ /**
106+
+ * Returns the location where the explosion happened.
107+
+ *
108+
+ * @return The location of the explosion
109+
+ */
110+
+ @NotNull
111+
+ public Location getLocation() {
112+
+ return location;
113+
+ }
114+
+
115+
+ @Override
116+
+ public boolean isCancelled() {
117+
+ return this.cancelled;
118+
+ }
119+
+
120+
+ @Override
121+
+ public void setCancelled(boolean cancel) {
122+
+ this.cancelled = cancel;
123+
+ }
124+
+
125+
+ @Override
126+
+ public @NotNull HandlerList getHandlers() {
127+
+ return handlers;
128+
+ }
129+
+
130+
+ @NotNull
131+
+ public static HandlerList getHandlerList() {
132+
+ return handlers;
133+
+ }
134+
+}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: SageSphinx63920 <sage@sagesphinx63920.dev>
3+
Date: Mon, 26 Dec 2022 23:42:37 +0100
4+
Subject: [PATCH] Add PreExplodeEvents
5+
6+
7+
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
8+
index 3c9e0cee78deeae6b47a186f1bfc47f3956ec9c7..cd63170e56b402fbf8bbd904270979fa51330e26 100644
9+
--- a/src/main/java/net/minecraft/world/level/Explosion.java
10+
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
11+
@@ -141,6 +141,23 @@ public class Explosion {
12+
return;
13+
}
14+
// CraftBukkit end
15+
+
16+
+ // Purpur start - add PreExplodeEvents
17+
+ if(this.source != null){
18+
+ Location location = new Location(this.level.getWorld(), this.x, this.y, this.z);
19+
+ 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()) {
20+
+ this.wasCanceled = true;
21+
+ return;
22+
+ }
23+
+ }else {
24+
+ Location location = new Location(this.level.getWorld(), this.x, this.y, this.z);
25+
+ if(!new org.purpurmc.purpur.event.PreBlockExplodeEvent(location.getBlock(), this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F).callEvent()) {
26+
+ this.wasCanceled = true;
27+
+ return;
28+
+ }
29+
+ }
30+
+ //Purpur end
31+
+
32+
this.level.gameEvent(this.source, GameEvent.EXPLODE, new Vec3(this.x, this.y, this.z));
33+
Set<BlockPos> set = Sets.newHashSet();
34+
boolean flag = true;

patches/server/0310-Improve-output-of-plugins-command.patch renamed to patches/server/0311-Improve-output-of-plugins-command.patch

File renamed without changes.

0 commit comments

Comments
 (0)