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
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityArrow.java b/src/main/java/net/minecraft/world/entity/projectile/EntityArrow.java
index 9bd4a283a99f86c9a26f73e0bad0c3414d66ad55..5ecbe9135a71dd84e0722fa9c039c272a11d206f 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/EntityArrow.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/EntityArrow.java
@@ -198,6 +198,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;
2021-03-16 08:19:45 +01: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-03-16 16:50:45 +01:00
index ed76aec99f46a7923d139e347779c24f512ac131..ede7b4dbf2dce7bac83c5e17eecfdaf0e8a84fe7 100644
2021-03-16 08:19:45 +01: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 16:50:45 +01:00
@@ -13,6 +13,7 @@ import net.minecraft.world.entity.EntityLiving;
import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.level.World;
import net.minecraft.world.phys.MovingObjectPosition;
+import net.minecraft.world.phys.MovingObjectPositionEntity;
import net.minecraft.world.phys.Vec3D;
import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
@@ -72,7 +73,16 @@ public abstract class EntityFireball extends IProjectile {
2020-06-25 14:04:34 +02:00
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
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/EntityProjectile.java
2021-03-16 16:50:45 +01:00
index 829b4f28896bcb0eb6e48242bd00585eeaae62c2..3b379e83b79bd9b46dbdd4a48ac3842abc4dfbb8 100644
2021-03-16 08:19:45 +01:00
--- a/src/main/java/net/minecraft/world/entity/projectile/EntityProjectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/EntityProjectile.java
2021-03-16 16:50:45 +01:00
@@ -14,6 +14,7 @@ import net.minecraft.world.level.block.entity.TileEntityEndGateway;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.phys.MovingObjectPosition;
import net.minecraft.world.phys.MovingObjectPositionBlock;
+import net.minecraft.world.phys.MovingObjectPositionEntity;
import net.minecraft.world.phys.Vec3D;
public abstract class EntityProjectile extends IProjectile {
@@ -57,7 +58,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
2021-04-25 00:47:20 +02:00
index a7c371694a7c6be117501b1dd816acbd304290f5..54d4d2363cb343c059c5676d2b351b8ad8bbe529 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
2021-04-25 00:47:20 +02:00
@@ -1195,6 +1195,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);