PSA: Read if you modify EntityDamageEvent.setDamage

Discussion in 'Plugin Development' started by Aikar, Jul 8, 2014.

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

    Aikar

    after much research last night, I found a pretty nasty bug in the new Damage API.

    If you are using setDamage to lower the amount of damage done to an entity, then any one using the newer CraftBukkit builds with the new Damage API will potentially receive major behavior changes, including GIVING non human living entities absorption!

    Before (1.7.9 Beta 2):

    You hit entity for 8 damage, plugin reduces damage to 2
    The method that checks armor/magic/absorption receives a value of 2 to process.
    Armor takes damage based on a value of 2


    Now (1.7.9 Beta 3-snapshots):

    You hit the entity for 8 damage, and lets say 6 of that damage was resisted by armor.
    getFinalDamage() now returns 2.

    However, you have the same code as "Before" above, and you reduce the damage to 2. But this only changes the Base modifier.

    Now, getFinalDamage returns 2 - 6 = -4!

    Before this API change, armor damage scaled to the POST event call damage value. Now it does not.

    But heres the worse part: For non human entities, absorption will then be GIVEN 4 points. So in this scenario, every hit on the monster gives it an additional 4 absorption points.... Making it invincible and further building up resistance for when the bug is finally fixed.

    So, if your lowering damage - you really should warn your users to NOT upgrade to this newer CraftBukkit until Bukkit can figure out a way to fix this major bug.

    To fix this yourself, you will need to automatically scale the armor, hardhat, blocking and magic modifiers by the same scale you modify the base damage.

    That will restore it back to pre new api behavior.
    Bug report is here: https://bukkit.atlassian.net/browse/BUKKIT-5678

    But as described above, its worse than just the absorption issue - armor damage is also affected here.
     
  2. Aikar When is this "before" and "after"?
     
  3. Offline

    Aikar

  4. Aikar Ah yes, I see the commit now. Will probably look at it more later. :)
     
  5. Offline

    Aikar

    Well Bukkit has closed the bug as wont-fix... so I guess just gotta try to spread the word about this bug more to get that changed.

    Well, Bukkit is working on a solution still.... Just the typical "close a valid bug just because we aren't happy with the full details on the report even though we know the bug exists" scenario.
     
Thread Status:
Not open for further replies.

Share This Page