From 3940c828a6e1945054ab8eeb747dbfcb99f6ccfd Mon Sep 17 00:00:00 2001 From: Sage Date: Thu, 2 Mar 2023 02:07:06 +0100 Subject: [PATCH] Add PreExplodeEvents (#1234) --- patches/api/0053-Add-PreExplodeEvents.patch | 134 ++++++++++++++++++ .../server/0310-Add-PreExplodeEvents.patch | 34 +++++ ...1-Improve-output-of-plugins-command.patch} | 0 3 files changed, 168 insertions(+) create mode 100644 patches/api/0053-Add-PreExplodeEvents.patch create mode 100644 patches/server/0310-Add-PreExplodeEvents.patch rename patches/server/{0310-Improve-output-of-plugins-command.patch => 0311-Improve-output-of-plugins-command.patch} (100%) diff --git a/patches/api/0053-Add-PreExplodeEvents.patch b/patches/api/0053-Add-PreExplodeEvents.patch new file mode 100644 index 000000000..943406e24 --- /dev/null +++ b/patches/api/0053-Add-PreExplodeEvents.patch @@ -0,0 +1,134 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: SageSphinx63920 +Date: Mon, 26 Dec 2022 23:40:13 +0100 +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..b7db0db7f3afbccdb07390d1bcada109e9e6b30b +--- /dev/null ++++ b/src/main/java/org/purpurmc/purpur/event/PreBlockExplodeEvent.java +@@ -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.BlockExplodeEvent; ++import org.jetbrains.annotations.NotNull; ++import java.util.Collections; ++ ++/** ++ * Called before a block's explosion is processed ++ */ ++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) { ++ super(what, Collections.emptyList(), yield); ++ this.yield = yield; ++ this.cancelled = false; ++ } ++ ++ /** ++ * Returns the percentage of blocks to drop from this explosion ++ * ++ * @return The yield. ++ */ ++ public float getYield() { ++ return yield; ++ } ++ ++ @Override ++ public boolean isCancelled() { ++ return this.cancelled; ++ } ++ ++ @Override ++ public void setCancelled(boolean cancel) { ++ this.cancelled = cancel; ++ } ++ ++ @Override ++ public @NotNull HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ @NotNull ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} +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..2d4f68228861492baaea0bcc604dfef623b337ba +--- /dev/null ++++ b/src/main/java/org/purpurmc/purpur/event/entity/PreEntityExplodeEvent.java +@@ -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.EntityExplodeEvent; ++import org.jetbrains.annotations.NotNull; ++import java.util.Collections; ++ ++/** ++ * Called before an entity's explosion is processed ++ */ ++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, location, Collections.emptyList(), yield); ++ this.cancelled = false; ++ this.yield = yield; ++ this.location = location; ++ } ++ ++ /** ++ * Returns the percentage of blocks to drop from this explosion ++ * ++ * @return The yield. ++ */ ++ public float getYield() { ++ return yield; ++ } ++ ++ /** ++ * Returns the location where the explosion happened. ++ * ++ * @return The location of the explosion ++ */ ++ @NotNull ++ public Location getLocation() { ++ return location; ++ } ++ ++ @Override ++ public boolean isCancelled() { ++ return this.cancelled; ++ } ++ ++ @Override ++ public void setCancelled(boolean cancel) { ++ this.cancelled = cancel; ++ } ++ ++ @Override ++ public @NotNull HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ @NotNull ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} diff --git a/patches/server/0310-Add-PreExplodeEvents.patch b/patches/server/0310-Add-PreExplodeEvents.patch new file mode 100644 index 000000000..6915a8eb1 --- /dev/null +++ b/patches/server/0310-Add-PreExplodeEvents.patch @@ -0,0 +1,34 @@ +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 3c9e0cee78deeae6b47a186f1bfc47f3956ec9c7..cd63170e56b402fbf8bbd904270979fa51330e26 100644 +--- a/src/main/java/net/minecraft/world/level/Explosion.java ++++ b/src/main/java/net/minecraft/world/level/Explosion.java +@@ -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 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); ++ if(!new org.purpurmc.purpur.event.PreBlockExplodeEvent(location.getBlock(), this.blockInteraction == Explosion.BlockInteraction.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F).callEvent()) { ++ this.wasCanceled = true; ++ return; ++ } ++ } ++ //Purpur end ++ + this.level.gameEvent(this.source, GameEvent.EXPLODE, new Vec3(this.x, this.y, this.z)); + Set set = Sets.newHashSet(); + boolean flag = true; diff --git a/patches/server/0310-Improve-output-of-plugins-command.patch b/patches/server/0311-Improve-output-of-plugins-command.patch similarity index 100% rename from patches/server/0310-Improve-output-of-plugins-command.patch rename to patches/server/0311-Improve-output-of-plugins-command.patch