From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 16 Jan 2021 14:30:12 -0500 Subject: [PATCH] Make ProjectileHitEvent Cancellable Allows cancelling things like detonating TNT from Fire Arrows diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java b/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java index 08b3499681eaf23a2f79f6dd9134ccfd86d888a4..7428de092006d5da3e8a543e46a11c6122eac323 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java +++ b/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java @@ -86,7 +86,7 @@ public abstract class EntityFireball extends IProjectile { // 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 } diff --git a/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java index 0e3c646dca1fa1fa895c3aece037367a9b2cf378..054785a3db3c787f5c1444613d3e8fe235e397f1 100644 --- a/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java +++ b/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java @@ -129,7 +129,7 @@ public abstract class IProjectile extends Entity { } 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 index 40c56301f497f66f8e8f6c737a5c5c8a26d372df..acb65ec8bd09b642c79bb8304bd82fb22a48608b 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -1298,9 +1298,9 @@ public class CraftEventFactory { 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; @@ -1317,7 +1317,7 @@ public class CraftEventFactory { } 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) {