Skip to content

Commit

Permalink
shoot: fix up hit_entities
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 10, 2021
1 parent 641fd0d commit ab23a96
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,26 @@ else if (lastLocation != null && lastVelocity != null && !(lastEntity.getBukkitE

@EventHandler
public void projectileHit(ProjectileHitEvent event) {
arrows.remove(event.getEntity().getUniqueId());
if (!arrows.containsKey(event.getEntity().getUniqueId())) {
return;
}
if (event.getHitEntity() != null) {
arrows.put(event.getEntity().getUniqueId(), new EntityTag(event.getHitEntity()));
}
else {
arrows.remove(event.getEntity().getUniqueId());
}
}

@EventHandler
public void arrowDamage(EntityDamageByEntityEvent event) {
// Get the damager
Entity arrow = event.getDamager();
// First, quickly confirm it's a projectile (relevant at all)
if (!(arrow instanceof Projectile)) {
return;
}
// Second, more slowly check if we shot it
if (!arrows.containsKey(arrow.getUniqueId())) {
return;
}
// Replace its entry with the hit entity.
arrows.remove(arrow.getUniqueId());
arrows.put(arrow.getUniqueId(), new EntityTag(event.getEntity()));
}
}

0 comments on commit ab23a96

Please sign in to comment.