How to cancel lava damage event?

Discussion in 'Plugin Development' started by Sir Savary, Feb 7, 2012.

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

    Sir Savary

    Might sound a little newby, but I'm just tired. I set the event to cancelled, but it still damages the player.
  2. Offline


    Maybe there's another plugin which uncancels the event? Otherwise try setting the damage to 0, although the player may still burn afterwards. But simply setting the fire ticks to 0 would make lava a fire extinguiser.
  3. Can you post the code you used please?

  4. Offline


    At my server i needed to set it on false at 2 plugins... WorldGuard and Essentials. Just read the config data┬┤s and u will see who still is on true for some damage ;)
  5. Offline


    Did some work related to this in ChessCraft recently (boards can have lava walls which can be walked through without injuring players). I initially thought to cancel the EntityCombustEvent, but that didn't seem to do anything.

    Some more investigation revealed that it's the EntityDamageEvent that needs to be cancelled, and you'll also want to do event.setFireTicks(0) to stop any subsequent burning. You'll need to check for three possible causes (event.getCause()):
    • LAVA - applied when the player is actually in lava
    • FIRE - applied when a player catches fire
    • FIRE_TICK - applied while a player is on fire
    If you stand in lava, you'll continually receive damage events with all three above causes. If you stand right beside lava, you'll get a damage event of FIRE, and subsequent FIRE_TICK events until you're extinguished.
  6. Offline

    Sir Savary


    Thank you, this is what I needed to know. I was already cancelling Lava, and Fire Tick, but never thought to cancel fire. If anyone's wondering, this is for a races plugin, demons heal in lava (The healing works, but players still damage flinched).

    Nope, didn't work, cancelled all three events, code:

    2. if (e.getCause().equals(DamageCause.LAVA))
    3. {
    4. if (race == Race.DEMON)
    5. {
    6. sp.setHealth(sp.getHealth() + 1);
    7. e.setCancelled(true);
    8. }
    10. else if ((race == Race.FEYLING) || (race == Race.ARZOK))
    11. {
    12. e.setDamage((int) (e.getDamage() * 2));
    13. }
    15. }
    17. if (e.getCause().equals(DamageCause.FIRE_TICK))
    18. {
    19. if ((race == Race.DEMON) || (race == Race.DRAGONBORN))
    20. {
    21. e.setCancelled(true);
    22. }
    24. else if ((race == Race.FEYLING) || (race == Race.ARZOK))
    25. {
    26. e.setDamage((int) (e.getDamage() * 2));
    27. }
    28. }
    30. if (e.getCause().equals(DamageCause.FIRE))
    31. {
    32. if ((race == Race.DEMON) || (race == Race.DRAGONBORN))
    33. {
    34. e.setCancelled(true);
    35. }
    37. else if ((race == Race.FEYLING) || (race == Race.ARZOK))
    38. {
    39. e.setDamage((int) (e.getDamage() * 2));
    40. }
    41. }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 23, 2016
  7. Offline


    I don't see any check for DamageCause.FIRE there...

    Feel free to inspect my entity event handlers here: - all lava-related damage is cancelled (although the player appears to be on fire while standing in lava, it's cancelled when he leaves). The onEntityDamage() handler doesn't particularly distinguish between most damage types since all damage to players is cancelled while on a chess board. But maybe it's a place to start looking.

    BTW, it's preferable to use == when comparing enums (like comparing getCause() with DamageCause.LAVA etc.) - you get better compile-time type checking, and it's (marginally) faster.
  8. What code did you use to cancel the fire animation?

  9. Offline


    The code's all there in the source file I linked to. event.setFireTicks(0) in an EntityDamageEvent handler will extinguish the entity in question.
  10. Ah cheers mate, I knew it was in there, just want sure which bit of code it was.

  11. Offline

    Sir Savary


    It's right at the bottom, last damage cause that is cancelled.
Thread Status:
Not open for further replies.

Share This Page