mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-09 04:09:54 +01:00
a207d14a0e
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
110 lines
6.3 KiB
Diff
110 lines
6.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/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
|
|
index 0dc5792d542658107c9c22c1f920986decd13920..3ce431c1fdf1f5bd62b49f26cca188e939e98efa 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
|
|
@@ -196,6 +196,17 @@ public abstract class AbstractArrow extends Projectile {
|
|
}
|
|
}
|
|
|
|
+ // Paper start - Call ProjectileCollideEvent
|
|
+ // TODO: flag - noclip - call cancelled?
|
|
+ if (object instanceof EntityHitResult) {
|
|
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileCollideEvent(this, (EntityHitResult)object);
|
|
+ if (event.isCancelled()) {
|
|
+ object = null;
|
|
+ movingobjectpositionentity = null;
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
if (object != null && !flag) {
|
|
this.preOnHit((HitResult) object); // CraftBukkit - projectile hit event
|
|
this.hasImpulse = true;
|
|
diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java
|
|
index bdff1c57f64d1bf29f2050f06c8b585d395b2c5c..872ff430547276e2a41a48aa07ae63b87ab39e5d 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java
|
|
@@ -12,6 +12,7 @@ import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.level.Level;
|
|
+import net.minecraft.world.phys.EntityHitResult;
|
|
import net.minecraft.world.phys.HitResult;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
|
|
@@ -71,7 +72,16 @@ public abstract class AbstractHurtingProjectile extends Projectile {
|
|
|
|
HitResult movingobjectposition = ProjectileUtil.getHitResult((Entity) this, this::canHitEntity);
|
|
|
|
- if (movingobjectposition.getType() != HitResult.Type.MISS) {
|
|
+ // Paper start - Call ProjectileCollideEvent
|
|
+ if (movingobjectposition instanceof EntityHitResult) {
|
|
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = CraftEventFactory.callProjectileCollideEvent(this, (EntityHitResult)movingobjectposition);
|
|
+ if (event.isCancelled()) {
|
|
+ movingobjectposition = null;
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
+ if (movingobjectposition != null && movingobjectposition.getType() != HitResult.Type.MISS) { // Paper - add null check in case cancelled
|
|
this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
|
|
|
|
// CraftBukkit start - Fire ProjectileHitEvent
|
|
diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrowableProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/ThrowableProjectile.java
|
|
index 23f255bfa63cd16e2930fc932a2f4df8e522f2dc..becb07cda7388bcf2e987f06557894ae50d70dbf 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrowableProjectile.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrowableProjectile.java
|
|
@@ -13,6 +13,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
+import net.minecraft.world.phys.EntityHitResult;
|
|
import net.minecraft.world.phys.HitResult;
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
@@ -57,7 +58,17 @@ public abstract class ThrowableProjectile extends Projectile {
|
|
}
|
|
|
|
if (movingobjectposition.getType() != HitResult.Type.MISS && !flag) {
|
|
+ // Paper start - Call ProjectileCollideEvent
|
|
+ if (movingobjectposition instanceof EntityHitResult) {
|
|
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileCollideEvent(this, (EntityHitResult)movingobjectposition);
|
|
+ if (event.isCancelled()) {
|
|
+ movingobjectposition = null;
|
|
+ }
|
|
+ }
|
|
+ if (movingobjectposition != null) {
|
|
+ // Paper end
|
|
this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
|
|
+ } // Paper
|
|
}
|
|
|
|
this.checkInsideBlocks();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index c85fcad33e17c8ae2e4ee5cb873dbd4166fcc7f5..3f082b7fd50752728917a7da28cba4cb396a9fdf 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1190,6 +1190,16 @@ public class CraftEventFactory {
|
|
return CraftItemStack.asNMSCopy(bitem);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public static com.destroystokyo.paper.event.entity.ProjectileCollideEvent callProjectileCollideEvent(Entity entity, EntityHitResult 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);
|