3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/Spigot-Server-Patches/0122-Add-ProjectileCollideEvent.patch

94 Zeilen
5.3 KiB
Diff

From 0000000000000000000000000000000000000000 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 2a86d4b8af5e436e82e003f50c1929702af700c4..93084633d487684fb598038d148670fe6a00b3ed 100644
--- 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
}
}
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;
+ movingobjectpositionentity = null;
2019-04-27 08:26:04 +02:00
+ }
+ }
2019-04-27 08:26:04 +02:00
+ // Paper end
+
2019-04-27 08:26:04 +02:00
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 1ee09cb383d762219bda89463f4b6af807799385..74ca38f8e4e1addc243c3f3b57021d26f0ce3c97 100644
--- 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 {
MovingObjectPosition movingobjectposition = ProjectileHelper.a((Entity) this, this::a);
2019-04-27 08:26:04 +02:00
- if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) {
+ // 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);
+ 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
this.a(movingobjectposition);
2019-04-27 08:26:04 +02:00
// CraftBukkit start - Fire ProjectileHitEvent
diff --git a/src/main/java/net/minecraft/server/EntityProjectile.java b/src/main/java/net/minecraft/server/EntityProjectile.java
index 7391fd31148dbde60e34955841a296f454ac768e..53a8ea7d1eff84abe6c49464d556aa2788a6abcb 100644
--- a/src/main/java/net/minecraft/server/EntityProjectile.java
+++ b/src/main/java/net/minecraft/server/EntityProjectile.java
@@ -41,7 +41,17 @@ public abstract class EntityProjectile extends IProjectile {
}
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;
+ }
+ }
2020-06-25 14:04:34 +02:00
+ if (movingobjectposition != null) {
+ // Paper end
this.a(movingobjectposition);
+ } // Paper
}
this.checkBlockCollisions();
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index be74f172383f270e3f1ec194044f024e7b040694..8fbaaa7d287ecd13203ae7362b552c5f11858066 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1186,6 +1186,16 @@ public class CraftEventFactory {
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) {
+ Projectile projectile = (Projectile) entity.getBukkitEntity();
2019-04-27 08:26:04 +02:00
+ 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);