2021-01-16 19:31:14 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 16 Jan 2021 14:30:12 -0500
Subject: [PATCH] Make ProjectileHitEvent Cancellable
Allows cancelling things like detonating TNT from Fire Arrows
2021-03-16 07:19:45 +00:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java b/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
2021-05-02 19:37:24 +00:00
index 09e547a299286c47750325fe3c44ee9cd45748a0..c4248531d4a6a11259d9d78ce1d7683a86840d40 100644
2021-03-16 07:19:45 +00:00
--- a/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
2021-03-16 15:50:45 +00:00
@@ -87,7 +87,7 @@ public abstract class EntityFireball extends IProjectile {
2021-01-16 19:31:14 +00:00
// CraftBukkit start - Fire ProjectileHitEvent
if (this.dead) {
- CraftEventFactory.callProjectileHitEvent(this, movingobjectposition);
+ if (!CraftEventFactory.callProjectileHitEvent(this, movingobjectposition)) return; // Paper - this is an undesired duplicate event, but make cancellable
}
// CraftBukkit end
}
2021-03-16 07:19:45 +00:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java
2021-03-16 15:50:45 +00:00
index 37b1febb45b900dfe4b225152e66bc4be83df220..9f2e7d345d98f50e6d47cbf4bb35714852fa42da 100644
2021-03-16 07:19:45 +00:00
--- a/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java
2021-03-16 15:50:45 +00:00
@@ -130,7 +130,7 @@ public abstract class IProjectile extends Entity {
2021-01-16 19:31:14 +00:00
}
protected void a(MovingObjectPosition movingobjectposition) {
- org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition); // CraftBukkit - Call event
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition)) return; // CraftBukkit - Call event // Paper - make cancellable
MovingObjectPosition.EnumMovingObjectType movingobjectposition_enummovingobjecttype = movingobjectposition.getType();
if (movingobjectposition_enummovingobjecttype == MovingObjectPosition.EnumMovingObjectType.ENTITY) {
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2021-04-24 22:47:20 +00:00
index 08b3adcd1ab8c8872a40b2faecc95471c3236292..5f40bc588971bae14e500755697db3290aa4af3b 100644
2021-01-16 19:31:14 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2021-04-24 22:47:20 +00:00
@@ -1312,9 +1312,9 @@ public class CraftEventFactory {
2021-01-16 19:31:14 +00:00
return event;
}
- public static void callProjectileHitEvent(Entity entity, MovingObjectPosition position) {
+ public static boolean callProjectileHitEvent(Entity entity, MovingObjectPosition position) { // Paper - make cancellable
if (position.getType() == MovingObjectPosition.EnumMovingObjectType.MISS) {
- return;
+ return false; // Paper - make cancellable
}
Block hitBlock = null;
2021-04-24 22:47:20 +00:00
@@ -1331,7 +1331,7 @@ public class CraftEventFactory {
2021-01-16 19:31:14 +00:00
}
ProjectileHitEvent event = new ProjectileHitEvent((Projectile) entity.getBukkitEntity(), hitEntity, hitBlock, hitFace);
- entity.world.getServer().getPluginManager().callEvent(event);
+ return event.callEvent(); // Paper
}
public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) {