From c17648952c16e137bf50b16f91ee6d9109e2832c Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Fri, 8 Jan 2021 13:34:04 -0800 Subject: [PATCH] shoot: projectiles should stop based on event --- .../denizen/scripts/commands/entity/ShootCommand.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/ShootCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/ShootCommand.java index 75d6ca139b..59d22bb806 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/ShootCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/ShootCommand.java @@ -27,6 +27,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; @@ -320,13 +321,16 @@ public void run() { } // Otherwise, if the entity is no longer traveling through // the air, stop the task - else if (lastLocation != null && lastVelocity != null) { + else if (lastLocation != null && lastVelocity != null && !(lastEntity.getBukkitEntity() instanceof Projectile)) { if (lastLocation.getWorld() != lastEntity.getBukkitEntity().getWorld() || (lastLocation.distanceSquared(lastEntity.getBukkitEntity().getLocation()) < 0.1 && lastVelocity.distanceSquared(lastEntity.getBukkitEntity().getVelocity()) < 0.1)) { flying = false; } } + if (!arrows.containsKey(lastEntity.getUUID()) || arrows.get(lastEntity.getUUID()) != null) { + flying = false; + } // Stop the task and run the script if conditions // are met if (!flying) { @@ -370,6 +374,11 @@ else if (lastLocation != null && lastVelocity != null) { } } + @EventHandler + public void projectileHit(ProjectileHitEvent event) { + arrows.remove(event.getEntity().getUniqueId()); + } + @EventHandler public void arrowDamage(EntityDamageByEntityEvent event) { // Get the damager