How to find out the damage cause

Discussion in 'Plugin Development' started by kabbage, Feb 1, 2012.

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

    kabbage

    I'm trying to make it so something only happens if the damage cause was a certain type (such as lava damage). What I'm using right now is:
    Code:
    if (DamageCause.LAVA != null) {
    //do something
    }
    However, the "//do something" code is ran no matter what the damage type is. This is in an EntityDamageEvent Listener.
     
  2. Offline

    Kierrow

    Your general understanding of this kind of code is wrong.
    DamageCause is and enum, which means that DamageCause.LAVA can never be null.

    What you are probably looking for here is the following:
    Code:
    @EventHandler
    public void onEntityDamage(EntityDamageEvent event) {
        if (event.getCause() == DamageCause.LAVA) {
            //do something
        }
    }
    I hope this helps you. =D
     
    kabbage likes this.
  3. Offline

    kabbage

    Ah, perfect. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page