From 96b534f1f1ecfbfb6c8958392a84a36f7e6c0d8f Mon Sep 17 00:00:00 2001 From: AlphaBlend Date: Wed, 5 Oct 2016 16:07:29 -0500 Subject: [PATCH] Add hit entity to ProjectileHitEvent --- ...Add-hit-entity-to-ProjectileHitEvent.patch | 64 +++++++++++++++ ...Add-hit-entity-to-ProjectileHitEvent.patch | 81 +++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 Spigot-API-Patches/0039-Add-hit-entity-to-ProjectileHitEvent.patch create mode 100644 Spigot-Server-Patches/0178-Add-hit-entity-to-ProjectileHitEvent.patch diff --git a/Spigot-API-Patches/0039-Add-hit-entity-to-ProjectileHitEvent.patch b/Spigot-API-Patches/0039-Add-hit-entity-to-ProjectileHitEvent.patch new file mode 100644 index 0000000000..7a8df45b8d --- /dev/null +++ b/Spigot-API-Patches/0039-Add-hit-entity-to-ProjectileHitEvent.patch @@ -0,0 +1,64 @@ +From 820409d462306180ec3d416d93a8dba43bb3874f Mon Sep 17 00:00:00 2001 +From: AlphaBlend +Date: Wed, 21 Sep 2016 20:40:21 -0700 +Subject: [PATCH] Add hit entity to ProjectileHitEvent + + +diff --git a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java +index 25ae832..250bddf 100644 +--- a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java ++++ b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java +@@ -1,23 +1,50 @@ + package org.bukkit.event.entity; + ++import org.bukkit.entity.Entity; // Paper + import org.bukkit.entity.Projectile; + import org.bukkit.event.HandlerList; + ++import javax.annotation.Nullable; ++ + /** + * Called when a projectile hits an object + */ + public class ProjectileHitEvent extends EntityEvent { + private static final HandlerList handlers = new HandlerList(); ++ // Paper start ++ @Nullable ++ private final Entity hitEntity; + + public ProjectileHitEvent(final Projectile projectile) { ++ this(projectile, null); ++ } ++ ++ public ProjectileHitEvent(final Projectile projectile, @Nullable final Entity hitEntity) { + super(projectile); ++ this.hitEntity = hitEntity; + } ++ // Paper end + + @Override + public Projectile getEntity() { + return (Projectile) entity; + } + ++ // Paper start ++ /** ++ * Gets the entity that was hit by the projectile. ++ * ++ * This may be null, depending on if the projectile ++ * actually hit an entity. ++ * ++ * @return The entity that was hit, or null otherwise ++ */ ++ @Nullable ++ public Entity getHitEntity() { ++ return hitEntity; ++ } ++ // Paper end ++ + @Override + public HandlerList getHandlers() { + return handlers; +-- +2.10.0 + diff --git a/Spigot-Server-Patches/0178-Add-hit-entity-to-ProjectileHitEvent.patch b/Spigot-Server-Patches/0178-Add-hit-entity-to-ProjectileHitEvent.patch new file mode 100644 index 0000000000..dd0135d9ad --- /dev/null +++ b/Spigot-Server-Patches/0178-Add-hit-entity-to-ProjectileHitEvent.patch @@ -0,0 +1,81 @@ +From 6e566525947b294d8825015c511d8dabd630af8e Mon Sep 17 00:00:00 2001 +From: AlphaBlend +Date: Wed, 21 Sep 2016 20:40:46 -0700 +Subject: [PATCH] Add hit entity to ProjectileHitEvent + + +diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java +index 37cb17c..9cdc58a 100644 +--- a/src/main/java/net/minecraft/server/EntityArrow.java ++++ b/src/main/java/net/minecraft/server/EntityArrow.java +@@ -263,7 +263,7 @@ public abstract class EntityArrow extends Entity implements IProjectile { + + protected void a(MovingObjectPosition movingobjectposition) { + Entity entity = movingobjectposition.entity; +- org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this); // CraftBukkit - Call event ++ org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, entity); // CraftBukkit - Call event // Paper - Include entity in movingobjectposition + if (entity != null) { + float f = MathHelper.sqrt(this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ); + int i = MathHelper.f((double) f * this.damage); +diff --git a/src/main/java/net/minecraft/server/EntityFireball.java b/src/main/java/net/minecraft/server/EntityFireball.java +index 393f26e..7cd3054 100644 +--- a/src/main/java/net/minecraft/server/EntityFireball.java ++++ b/src/main/java/net/minecraft/server/EntityFireball.java +@@ -99,7 +99,7 @@ public abstract class EntityFireball extends Entity { + + // CraftBukkit start - Fire ProjectileHitEvent + if (this.dead) { +- CraftEventFactory.callProjectileHitEvent(this); ++ CraftEventFactory.callProjectileHitEvent(this, movingobjectposition.entity); // Paper - include entity in movingobjectposition + } + // CraftBukkit end + } +diff --git a/src/main/java/net/minecraft/server/EntityFishingHook.java b/src/main/java/net/minecraft/server/EntityFishingHook.java +index 9b71cdd..08a2dc0 100644 +--- a/src/main/java/net/minecraft/server/EntityFishingHook.java ++++ b/src/main/java/net/minecraft/server/EntityFishingHook.java +@@ -207,7 +207,7 @@ public class EntityFishingHook extends Entity { + // Paper end + + if (movingobjectposition != null) { +- org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this); // Craftbukkit - Call event ++ org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition.entity); // Craftbukkit - Call event // Paper - Include entity in movingobjectposition + if (movingobjectposition.entity != null) { + this.hooked = movingobjectposition.entity; + this.getDataWatcher().set(EntityFishingHook.c, Integer.valueOf(this.hooked.getId() + 1)); +diff --git a/src/main/java/net/minecraft/server/EntityProjectile.java b/src/main/java/net/minecraft/server/EntityProjectile.java +index 770f130..e95cc24 100644 +--- a/src/main/java/net/minecraft/server/EntityProjectile.java ++++ b/src/main/java/net/minecraft/server/EntityProjectile.java +@@ -175,7 +175,7 @@ public abstract class EntityProjectile extends Entity implements IProjectile { + this.a(movingobjectposition); + // CraftBukkit start + if (this.dead) { +- org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition.entity); // Paper - include Entity in movingobjectposition + } + // CraftBukkit end + } +diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +index e39de2b..949db83 100644 +--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java ++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +@@ -782,6 +782,15 @@ public class CraftEventFactory { + return event; + } + ++ // Paper start ++ public static ProjectileHitEvent callProjectileHitEvent(Entity entity, Entity hitEntity) { ++ ProjectileHitEvent event = new ProjectileHitEvent((Projectile) entity.getBukkitEntity(), (hitEntity == null ? null : hitEntity.getBukkitEntity())); ++ ++ entity.world.getServer().getPluginManager().callEvent(event); ++ return event; ++ } ++ // Paper end ++ + public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) { + ThrownExpBottle bottle = (ThrownExpBottle) entity.getBukkitEntity(); + ExpBottleEvent event = new ExpBottleEvent(bottle, exp); +-- +2.10.0 +