1.15.2 LivingEntity damage, Projectile and Damage Event

Discussion in 'Spigot Plugin Development' started by NightExpress, Jan 19, 2020.

  1. When using LivingEntity damage method:
    Code (Java):
    victim.damage(5D, damager);
    where damager is a Projectile entity, the EntityDamageByEntityEvent won't be called, but EntityDamageEvent, which says that damage is caused by PROJECTILE.

    Is this a bug or am I doing something wrong?
     
  2. Hi

    I tested it creating an arrow and damaging myself with that entity, and you are right, EntityDamageEvent is fired, not EntityDamageByEntityEvent
    Code (Text):

    Player player = (Player) sender;

    Projectile projectile = player.getWorld().spawnArrow(player.getLocation(), player.getVelocity(), 1f, 1f);
    player.damage(5D, projectile);
     
    Code (Text):

    @EventHandler(priority = EventPriority.LOWEST)
    public void onEntityDamage(EntityDamageEvent event) {
        System.out.println("Simple damage event");
    }

    @EventHandler(priority = EventPriority.LOWEST)
    public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
        System.out.println("Entity damage by entity");
    }
     
    Only the "simple" is fired.

    In craftbukkit this line should me called https://hub.spigotmc.org/stash/proj.../craftbukkit/event/CraftEventFactory.java#785
    But i think Arrow is not EntityDamageSourceIndirect,
    maybe is related with https://hub.spigotmc.org/stash/proj...craftbukkit/entity/CraftLivingEntity.java#250
    Only HumanEntity and the rest of LivingEntity gets it correct DamageSource, and the rest is Generic

    So, or I don't understant either when that EntityDamageByEntityEvent with Projectile is going to be fired, or it's a Spigot bug