2020-05-06 11:48:49 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2016-12-17 05:13:45 +01:00
From: Techcable <Techcable@outlook.com>
Date: Fri, 16 Dec 2016 21:25:39 -0600
Subject: [PATCH] Add ProjectileCollideEvent
diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java
2020-08-25 04:22:08 +02:00
index 2fb014c2a20363c94045dd834f771cfd9baf37cd..a7c475454e627e54d6771c5023144d55ad389ae3 100644
2016-12-17 05:13:45 +01:00
--- a/src/main/java/net/minecraft/server/EntityArrow.java
+++ b/src/main/java/net/minecraft/server/EntityArrow.java
2020-06-25 14:04:34 +02:00
@@ -160,6 +160,17 @@ public abstract class EntityArrow extends IProjectile {
2019-04-27 08:26:04 +02:00
}
2016-12-17 05:13:45 +01:00
}
2019-04-27 08:26:04 +02:00
+ // Paper start - Call ProjectileCollideEvent
+ // TODO: flag - noclip - call cancelled?
+ if (object instanceof MovingObjectPositionEntity) {
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileCollideEvent(this, (MovingObjectPositionEntity)object);
+ if (event.isCancelled()) {
+ object = null;
2019-08-01 00:04:45 +02:00
+ movingobjectpositionentity = null;
2019-04-27 08:26:04 +02:00
+ }
2016-12-17 05:13:45 +01:00
+ }
2019-04-27 08:26:04 +02:00
+ // Paper end
2016-12-17 05:13:45 +01:00
+
2019-04-27 08:26:04 +02:00
if (object != null && !flag) {
this.a((MovingObjectPosition) object);
this.impulse = true;
2016-12-17 05:13:45 +01:00
diff --git a/src/main/java/net/minecraft/server/EntityFireball.java b/src/main/java/net/minecraft/server/EntityFireball.java
2020-08-25 04:22:08 +02:00
index d63b7b53da148ce404124115337e0dadf3357548..19aa9dab2509554417c2952eccd4ad5cb6008eda 100644
2016-12-17 05:13:45 +01:00
--- a/src/main/java/net/minecraft/server/EntityFireball.java
+++ b/src/main/java/net/minecraft/server/EntityFireball.java
2020-06-25 14:04:34 +02:00
@@ -57,7 +57,16 @@ public abstract class EntityFireball extends IProjectile {
2020-08-25 04:22:08 +02:00
MovingObjectPosition movingobjectposition = ProjectileHelper.a((Entity) this, this::a);
2016-12-17 05:13:45 +01:00
2019-04-27 08:26:04 +02:00
- if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) {
2016-12-17 05:13:45 +01:00
+ // Paper start - Call ProjectileCollideEvent
2019-04-27 08:26:04 +02:00
+ if (movingobjectposition instanceof MovingObjectPositionEntity) {
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = CraftEventFactory.callProjectileCollideEvent(this, (MovingObjectPositionEntity)movingobjectposition);
2016-12-17 05:13:45 +01:00
+ if (event.isCancelled()) {
+ movingobjectposition = null;
+ }
+ }
+ // Paper end
+
2019-04-27 08:26:04 +02:00
+ if (movingobjectposition != null && movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { // Paper - add null check in case cancelled
2016-12-17 05:13:45 +01:00
this.a(movingobjectposition);
2019-04-27 08:26:04 +02:00
// CraftBukkit start - Fire ProjectileHitEvent
2016-12-17 05:13:45 +01:00
diff --git a/src/main/java/net/minecraft/server/EntityProjectile.java b/src/main/java/net/minecraft/server/EntityProjectile.java
2020-08-25 04:22:08 +02:00
index 7391fd31148dbde60e34955841a296f454ac768e..53a8ea7d1eff84abe6c49464d556aa2788a6abcb 100644
2016-12-17 05:13:45 +01:00
--- a/src/main/java/net/minecraft/server/EntityProjectile.java
+++ b/src/main/java/net/minecraft/server/EntityProjectile.java
2020-06-26 03:58:00 +02:00
@@ -41,7 +41,17 @@ public abstract class EntityProjectile extends IProjectile {
2016-12-17 05:13:45 +01:00
}
2020-06-25 14:04:34 +02:00
if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS && !flag) {
+ // Paper start - Call ProjectileCollideEvent
+ if (movingobjectposition instanceof MovingObjectPositionEntity) {
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileCollideEvent(this, (MovingObjectPositionEntity)movingobjectposition);
+ if (event.isCancelled()) {
+ movingobjectposition = null;
+ }
2016-12-17 05:13:45 +01:00
+ }
2020-06-25 14:04:34 +02:00
+ if (movingobjectposition != null) {
+ // Paper end
this.a(movingobjectposition);
+ } // Paper
}
2020-08-25 04:22:08 +02:00
this.checkBlockCollisions();
2016-12-17 05:13:45 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2020-09-02 11:12:25 +02:00
index d423313fd949ff1adf3f6d9c5f339a465e0f0b9e..7239e9b9d072af9d1610fd2e06a123505e31a110 100644
2016-12-17 05:13:45 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2020-09-02 11:12:25 +02:00
@@ -1188,6 +1188,16 @@ public class CraftEventFactory {
2016-12-17 05:13:45 +01:00
return CraftItemStack.asNMSCopy(bitem);
}
+ // Paper start
2019-04-27 08:26:04 +02:00
+ public static com.destroystokyo.paper.event.entity.ProjectileCollideEvent callProjectileCollideEvent(Entity entity, MovingObjectPositionEntity position) {
2016-12-17 05:13:45 +01:00
+ Projectile projectile = (Projectile) entity.getBukkitEntity();
2019-04-27 08:26:04 +02:00
+ org.bukkit.entity.Entity collided = position.getEntity().getBukkitEntity();
2016-12-17 05:13:45 +01:00
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = new com.destroystokyo.paper.event.entity.ProjectileCollideEvent(projectile, collided);
+ Bukkit.getPluginManager().callEvent(event);
+ return event;
+ }
+ // Paper end
+
public static ProjectileLaunchEvent callProjectileLaunchEvent(Entity entity) {
Projectile bukkitEntity = (Projectile) entity.getBukkitEntity();
ProjectileLaunchEvent event = new ProjectileLaunchEvent(bukkitEntity);