From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 16 Jan 2021 14:00:16 -0500 Subject: [PATCH] Make ProjectileHitEvent Cancellable Allows cancelling things like detonating TNT from Fire Arrows diff --git a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java index 809c1098c16fe52eda47ae2335afab30e36746b2..000c9967e008d3340a08c4ee727a5d2de27dedcc 100644 --- a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java +++ b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java @@ -4,6 +4,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; import org.bukkit.entity.Projectile; +import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,11 +12,28 @@ import org.jetbrains.annotations.Nullable; /** * Called when a projectile hits an object */ -public class ProjectileHitEvent extends EntityEvent { +public class ProjectileHitEvent extends EntityEvent implements Cancellable { // Paper private static final HandlerList handlers = new HandlerList(); private final Entity hitEntity; private final Block hitBlock; private final BlockFace hitFace; + // Paper start - make cancellable + private boolean canceled; + /** + * @return If the arrow activating a block should be cancelled + */ + public boolean isCancelled() { + return canceled; + } + + /** + * Whether or not to cancel any behavior that would occur from the arrow hitting the block + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + canceled = cancel; + } + // Paper end public ProjectileHitEvent(@NotNull final Projectile projectile) { this(projectile, null, null);