Entity Cancelled Event not workin

Discussion in 'Plugin Development' started by VictoryShot, Apr 24, 2014.

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

    VictoryShot

    So when I do this:
    Code:java
    1. @EventHandler
    2. public void onDamage(EntityDamageEvent e) {
    3. e.setCancelled(e.getEntity().getType() == EntityType.PIG);
    4. }
    5. @EventHandler
    6. public void onDamage2(EntityDamageEvent e) {
    7. e.setCancelled(e.getEntity().getType() == EntityType.SHEEP);
    8. }
    9. @EventHandler
    10. public void onDamage3(EntityDamageEvent e) {
    11. e.setCancelled(e.getEntity().getType() == EntityType.BLAZE);
    12. }


    It sets only 1 mob as cancelled. Help?
     
  2. Offline

    skyrimfan1

    Why don't you condense all of the events into one?
    Code:
    @EventHandler
    public void onDamage(EntityDamageEvent e) {
        EntityType type = e.getEntity().getType();
        e.setCancelled(type == EntityType.PIG || type == EntityType.SHEEP || type == EntityType.BLAZE);
    }
    Currently, it seems that one listening event is overriding the others (hence only one works).
     
  3. Offline

    BillyGalbreath

    Thats odd, because the three should work fine separated like that..

    Only thing I would have done different is used .equals() instead of ==, but I doubt thats the issue.
     
Thread Status:
Not open for further replies.

Share This Page