EntityDamageByEntityEvent not doing the damage it should do

Discussion in 'Plugin Development' started by Mahtaran, Mar 12, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Mahtaran

    Dear people of Bukkit,

    I've got a problem. I'm trying to manipulate the damage that an EntityDamageByEntityEvent does.

    Now, normally it works great. The new damage value is a double, usually around 57.0. I'm modifying the damage like this: (normally totalDamage is calculated with some maths, but by using debugging I found out that it most times lied around 57.0)
    Code:
    double totalDamage = 57.0D;
    e.setDamage(totalDamage);
    Now I've tested. If the event is called because an arrow hit a player, the damage is applied correctly. However, if it's called because of a player actually hit a player with a sword, the damage is divided by 28 or something like that. In place of 57 damage (28.5 hearts), it does 2 damage (1 heart).

    this is al the relevant code:
    Code:
    double damage = /*something*/ 57.0D;
    event.setDamage(damage);
    is there a limit I don't know about?

    Thanks, Mahtaran
     
    Last edited: Mar 12, 2017
  2. Offline

    MarkehMe

    Try:
    PHP:
    event.setDamage(DamageModifier.BASEdamage);
    If you can't find a solution, you could try cancelling the event and calling .damage() on the entity instead. This is not a good solution though.
     
  3. Offline

    Mahtaran

    Thanks! Will try it soon.
    Just a quick question; if I call
    Code:
    entity.damage(damage);
    I would have to inject some metadata into the entity and cancel the new event that is called, right?
     
  4. Offline

    ipodtouch0218

    If you use LivingEntity#damage(), then the entity would receive no knockback, which may not be what you want. Just modifying the EntityDamageEvent should work normally, are there any other plugins that could be factoring in damage events? What about armor?
     
  5. Offline

    Mahtaran

    Wait, I'm dumb... Please gods of Java and bukkit coding forgive me.

    I had 2 EntityDamageByEntityEvents registered: this one and one that resets the attack damage to 1.8. I had the 1.8 one set at priority HIGHEST, thinking it would be executed first. And this one, that should be called after, I had set to LOWEST, thinking it would be the last one to be executed. Dumb me. Let's see if it was the problem. Probably.

    :D:rolleyes::p
     
  6. Offline

    MarkehMe

    @Mahtaran oops, happy to hear you found the issue :)
     
Thread Status:
Not open for further replies.

Share This Page