PaperMC/Spigot-API-Patches/Make-ProjectileHitEvent-Cancellable.patch

50 lines
1.9 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
+++ b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ 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);