Solved NullPointerException @ enum DamageCause

Discussion in 'Plugin Development' started by Shzylo, Oct 13, 2013.

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

    Shzylo

    I want to cancel the fall damage all entities take, and my code keeps throwing an NPE at DamageCause.FALL in the following code:

    Code:
    @EventHandler
    public void onEntityDamage(EntityDamageEvent e) {
        Entity ent = e.getEntity();
     
        if (ent.getLastDamageCause().equals(DamageCause.FALL)) e.setCancelled(true);
    }
    What silly mistake have I committed?
     
  2. Offline

    RealDope

    Print the value of all variables on that line to console.
    Print:
    • ent
    • ent.getLastDamageCause()
     
  3. Offline

    Rocoty

    First of all, just to make sure you avoid lots of frustration getLastDamageCause does not return a DamageCause, but an EntityDamageEvent.

    If you had read the docs you would have known this, as well as the method can return null if there was no previous cause of damage at that point.
     
  4. Offline

    Shzylo

    I found out my problem seconds after I posted this, but I could not fix my post considering that the database was giving me errors when I tried to get back on to the site, so I could not do anything.

    I just needed to change ent.getLastDamageCause() to e.getCause() I confused myself.
     
Thread Status:
Not open for further replies.

Share This Page