Skip to content

Commit

Permalink
shoot: projectiles should stop based on event
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 8, 2021
1 parent c51bdbd commit c176489
Showing 1 changed file with 10 additions and 1 deletion.
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c176489

Please sign in to comment.