2019-10-08 20:37:02 +02:00
From 486d30c530a76c840f613c62d703fae42aa0ff95 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
2019-10-08 20:37:02 +02:00
index 2b829abac6..a9575d310b 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
2019-08-01 00:04:45 +02:00
@@ -184,6 +184,17 @@ public abstract class EntityArrow extends Entity implements 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
2019-10-08 20:37:02 +02:00
index 1a9fee8da1..14c4394933 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
2019-04-27 08:26:04 +02:00
@@ -67,7 +67,16 @@ public abstract class EntityFireball extends Entity {
++this.g;
MovingObjectPosition movingobjectposition = ProjectileHelper.a(this, true, this.g >= 25, this.shooter, RayTrace.BlockCollisionOption.COLLIDER);
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/EntityFishingHook.java b/src/main/java/net/minecraft/server/EntityFishingHook.java
2019-10-08 20:37:02 +02:00
index 390f1a24d0..758559d35d 100644
2016-12-17 05:13:45 +01:00
--- a/src/main/java/net/minecraft/server/EntityFishingHook.java
+++ b/src/main/java/net/minecraft/server/EntityFishingHook.java
2019-04-27 08:26:04 +02:00
@@ -217,7 +217,16 @@ public class EntityFishingHook extends Entity {
2019-06-03 05:26:25 +02:00
return !entity.isSpectator() && (entity.isInteractable() || entity instanceof EntityItem) && (entity != this.owner || this.g >= 5);
2019-04-27 08:26:04 +02:00
}, RayTrace.BlockCollisionOption.COLLIDER, true);
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 = org.bukkit.craftbukkit.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
org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition); // Craftbukkit - Call event
if (movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY) {
this.hooked = ((MovingObjectPositionEntity) movingobjectposition).getEntity();
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
2019-10-08 20:37:02 +02:00
index d1710259ce..5f0cb4c33d 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
2019-04-27 08:26:04 +02:00
@@ -102,7 +102,16 @@ public abstract class EntityProjectile extends Entity implements IProjectile {
this.as = null;
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 = org.bukkit.craftbukkit.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
if (movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK && this.world.getType(((MovingObjectPositionBlock) movingobjectposition).getBlockPosition()).getBlock() == Blocks.NETHER_PORTAL) {
this.c(((MovingObjectPositionBlock) movingobjectposition).getBlockPosition());
} else {
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
2019-10-08 20:37:02 +02:00
index 30492170b5..7f38d82a61 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
2019-10-08 20:37:02 +02:00
@@ -1144,6 +1144,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);
--
2019-08-26 16:25:58 +02:00
2.23.0
2016-12-17 05:13:45 +01:00