From 58999b263e5040b78ca248114d0d1071bc5282e2 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 6 Jul 2024 17:19:42 +1000 Subject: [PATCH] SPIGOT-7799, #1039: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent By: antiPerson --- .../main/java/org/bukkit/ExplosionResult.java | 37 +++++++++++++++++++ .../bukkit/event/block/BlockExplodeEvent.java | 20 +++++++--- .../event/entity/EntityExplodeEvent.java | 15 +++++++- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/ExplosionResult.java diff --git a/paper-api/src/main/java/org/bukkit/ExplosionResult.java b/paper-api/src/main/java/org/bukkit/ExplosionResult.java new file mode 100644 index 0000000000..c875a10480 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/ExplosionResult.java @@ -0,0 +1,37 @@ +package org.bukkit; + +import org.jetbrains.annotations.ApiStatus; + +/** + * Represents the outcome of an explosion. + */ +@ApiStatus.Experimental +public enum ExplosionResult { + + /** + * Represents an explosion where no change took place. + * + * This is the case when {@link org.bukkit.GameRule#MOB_GRIEFING} is + * disabled. + */ + KEEP, + /** + * Represents an explosion where all destroyed blocks drop their items. + * + * This is the case when + * {@link org.bukkit.GameRule#TNT_EXPLOSION_DROP_DECAY} or + * {@link org.bukkit.GameRule#BLOCK_EXPLOSION_DROP_DECAY} is disabled. + */ + DESTROY, + /** + * Represents an explosion where explosions cause only some blocks to drop. + */ + DESTROY_WITH_DECAY, + /** + * Represents an explosion where a block change/update has happened. + * + * For example, when a wind charge is used it will cause nearby buttons, + * levers and bells to be activated. + */ + TRIGGER_BLOCK +} diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockExplodeEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockExplodeEvent.java index e534954457..1df172c0bb 100644 --- a/paper-api/src/main/java/org/bukkit/event/block/BlockExplodeEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockExplodeEvent.java @@ -1,6 +1,7 @@ package org.bukkit.event.block; import java.util.List; +import org.bukkit.ExplosionResult; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.event.Cancellable; @@ -20,18 +21,15 @@ public class BlockExplodeEvent extends BlockEvent implements Cancellable { private final BlockState blockState; private final List blocks; private float yield; + private final ExplosionResult result; - public BlockExplodeEvent(@NotNull final Block what, @NotNull final BlockState blockState, @NotNull final List blocks, final float yield) { + public BlockExplodeEvent(@NotNull final Block what, @NotNull final BlockState blockState, @NotNull final List blocks, final float yield, @NotNull final ExplosionResult result) { super(what); this.blockState = blockState; this.blocks = blocks; this.yield = yield; this.cancel = false; - } - - @Deprecated(forRemoval = true) - public BlockExplodeEvent(@NotNull final Block what, @NotNull final List blocks, final float yield) { - this(what, what.getState(), blocks, yield); + this.result = result; } @Override @@ -44,6 +42,16 @@ public class BlockExplodeEvent extends BlockEvent implements Cancellable { this.cancel = cancel; } + /** + * Returns the result of the explosion if it is not cancelled. + * + * @return the result of the explosion + */ + @NotNull + public ExplosionResult getExplosionResult() { + return result; + } + /** * Returns the captured BlockState of the block that exploded. * diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityExplodeEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityExplodeEvent.java index 10d0e18dfd..fc2158793a 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityExplodeEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/entity/EntityExplodeEvent.java @@ -1,6 +1,7 @@ package org.bukkit.event.entity; import java.util.List; +import org.bukkit.ExplosionResult; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -17,13 +18,15 @@ public class EntityExplodeEvent extends EntityEvent implements Cancellable { private final Location location; private final List blocks; private float yield; + private final ExplosionResult result; - public EntityExplodeEvent(@NotNull final Entity what, @NotNull final Location location, @NotNull final List blocks, final float yield) { + public EntityExplodeEvent(@NotNull final Entity what, @NotNull final Location location, @NotNull final List blocks, final float yield, @NotNull final ExplosionResult result) { super(what); this.location = location; this.blocks = blocks; this.yield = yield; this.cancel = false; + this.result = result; } @Override @@ -36,6 +39,16 @@ public class EntityExplodeEvent extends EntityEvent implements Cancellable { this.cancel = cancel; } + /** + * Returns the result of the explosion if it is not cancelled. + * + * @return the result of the explosion + */ + @NotNull + public ExplosionResult getExplosionResult() { + return result; + } + /** * Returns the list of blocks that would have been removed or were removed * from the explosion event.