Paper/Spigot-Server-Patches/0126-Add-ProjectileCollideEvent.patch
Aikar 57dd397155
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
b999860d SPIGOT-2304: Add LootGenerateEvent

CraftBukkit Changes:
77fd87e4 SPIGOT-2304: Implement LootGenerateEvent
a1a705ee SPIGOT-5566: Doused campfires & fires should call EntityChangeBlockEvent
41712edd SPIGOT-5707: PersistentDataHolder not Persistent on API dropped Item
2020-05-01 18:03:57 -04:00

119 lines
7.1 KiB
Diff

From be379d4bd4b66d56bdb9b87a7ea37f62872c1cbc Mon Sep 17 00:00:00 2001
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
index 2b14b2c3fa..634e2bd304 100644
--- a/src/main/java/net/minecraft/server/EntityArrow.java
+++ b/src/main/java/net/minecraft/server/EntityArrow.java
@@ -187,6 +187,17 @@ public abstract class EntityArrow extends Entity implements IProjectile {
}
}
+ // 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;
+ movingobjectpositionentity = null;
+ }
+ }
+ // Paper end
+
if (object != null && !flag) {
this.a((MovingObjectPosition) object);
this.impulse = true;
diff --git a/src/main/java/net/minecraft/server/EntityFireball.java b/src/main/java/net/minecraft/server/EntityFireball.java
index 078cc25231..6756c79b31 100644
--- a/src/main/java/net/minecraft/server/EntityFireball.java
+++ b/src/main/java/net/minecraft/server/EntityFireball.java
@@ -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);
- if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) {
+ // Paper start - Call ProjectileCollideEvent
+ if (movingobjectposition instanceof MovingObjectPositionEntity) {
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = CraftEventFactory.callProjectileCollideEvent(this, (MovingObjectPositionEntity)movingobjectposition);
+ if (event.isCancelled()) {
+ movingobjectposition = null;
+ }
+ }
+ // Paper end
+
+ if (movingobjectposition != null && movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { // Paper - add null check in case cancelled
this.a(movingobjectposition);
// CraftBukkit start - Fire ProjectileHitEvent
diff --git a/src/main/java/net/minecraft/server/EntityFishingHook.java b/src/main/java/net/minecraft/server/EntityFishingHook.java
index 39e3bd3795..807ec3394d 100644
--- a/src/main/java/net/minecraft/server/EntityFishingHook.java
+++ b/src/main/java/net/minecraft/server/EntityFishingHook.java
@@ -214,7 +214,16 @@ public class EntityFishingHook extends Entity {
return !entity.isSpectator() && (entity.isInteractable() || entity instanceof EntityItem) && (entity != this.owner || this.g >= 5);
}, RayTrace.BlockCollisionOption.COLLIDER, true);
- if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) {
+ // 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;
+ }
+ }
+ // Paper end
+
+ 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();
diff --git a/src/main/java/net/minecraft/server/EntityProjectile.java b/src/main/java/net/minecraft/server/EntityProjectile.java
index 2e4c9d4267..724b78b5d2 100644
--- a/src/main/java/net/minecraft/server/EntityProjectile.java
+++ b/src/main/java/net/minecraft/server/EntityProjectile.java
@@ -99,7 +99,16 @@ public abstract class EntityProjectile extends Entity implements IProjectile {
this.ap = null;
}
- if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) {
+ // 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;
+ }
+ }
+ // Paper end
+
+ 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 {
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 0ed6611ac4..e6d4f7a06b 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1156,6 +1156,16 @@ public class CraftEventFactory {
return CraftItemStack.asNMSCopy(bitem);
}
+ // Paper start
+ public static com.destroystokyo.paper.event.entity.ProjectileCollideEvent callProjectileCollideEvent(Entity entity, MovingObjectPositionEntity position) {
+ Projectile projectile = (Projectile) entity.getBukkitEntity();
+ org.bukkit.entity.Entity collided = position.getEntity().getBukkitEntity();
+ 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);
--
2.26.2