Lava is a bitch...

Discussion in 'Plugin Development' started by stelar7, Jun 15, 2012.

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

    stelar7

    This code:
    Code:
    public void death(EntityDamageEvent e) {
        if (!(e.getEntity() instanceof Player)) return;
        Player p = (Player)e.getEntity();
        if (p.getHealth() - e.getDamage() > 0) return; 
        if (p.getHealth() <= 0) return;
        System.out.print(e.getCause().name());
    
    for some reason prints out LAVA more than 1 time if you die in lava, and afaik it should not do that...
    any idea why?
     
  2. Maybe more players are damaged at the time?
    greetz blackwolf12333
     
  3. Offline

    stelar7

    I am the only player on the server and it fires so fast that ca. 10 players would have to die from lava at the same time...
     
  4. Hmm ok, how did you register the event?
    I made a mistake once too with that:p it resulted in a lot of spam of the same things.
     
  5. Offline

    stelar7

    the source is here, if that interests you...
    The code in question starts at line 80
     
  6. Offline

    Njol

    Try to add another check:
    Code:
    if (p.getNoDamageTicks() > 0) return;
     
  7. Offline

    stelar7

    Njol with that it does not even show once...
     
  8. Offline

    BH72

    Line 90 calls a new playerkillthread for every entity damage event whether they have been killed or not?

    Just out of curiosity why did you not use the onPlayerDeath event and then just get the cause. I guess maybe fire and lava return the cause of death as fire but you could always check the combuster to determine what caused the fire.
     
  9. Offline

    stelar7

    Line 90 calls a new playerkillthread for every player that dies because of non-entity attacks. (lava, falling, osv..)
    I dont use the PlayerDeathEvent because I need the thing that kills the player, not the cause.
    The issue here is that the event gets called ca. 10 times if you die from lava, but only once if you die from say a spider.
     
  10. player.getLastDamageCause(), you can acall that from the PlayerDeathEvent
     
  11. Offline

    stelar7

    Like I said, I need the damager not the cause
     
  12. Offline

    MrMag518

    But I thought the cause IS the damager?

    For an example; If I die from Lava, the cause for my death is Lava.
    Or, If I get damaged by Lava, the cause is Lava.

    EDIT: Or do you mean you need the one who placed the Lava?
     
  13. Offline

    stelar7

    Kinda, but if it is a zombie or a spider its ENTITY_ATTACK. A skeleton would be PROJECTILE... So that wont work
     
  14. Offline

    MrMag518

    Ah I see. It may be a bug in bukkit.


    Can't you disable the check you've done with Lava and check all the other entities, then do a stand-alone check for the Lava damage cause? (Something like that)
     
  15. I don't see the problem there. Making an if statement which separates them, because ENTITY_ATTACK you can get the direct entity, and if it's a projectile you can get the shooter which will give you the skeleton.
     
    MrMag518 likes this.
  16. Offline

    stelar7

    ye, I have that, but dying in lava keeps spamming ca. 10 events. that has been the problem since the start of this thread.

    Looking at the stuff that just came up from dying in lava: LAVA x6, FIRE x1, FIRE_TICK x1
    How is it possible to die 7 times while beeing dead?
     
  17. But since the start of the thread you use EntityDamageEvent, and not the suggested PlayerDeathEvent or EntityDeathEvent. Try that.
     
  18. Offline

    stelar7

    Another question, how do I get the killing entity from either of those events?
     
  19. getEntity().getLastDamageCause().getEntity()
     
  20. Offline

    stelar7

    When jumping into lava:
    Code:
    Entity killer = e.getEntity().getLastDamageCause().getEntity();
    Player killed = (Player)e.getEntity();
    System.out.print(killer + "    " + killed);
    this code ends up as
    Code:
    CraftPlayer{name=stelar7}      CraftPlayer{name=stelar7}
    so I think you are mistaken somewhere...
     
  21. Offline

    ThatBox

    stelar7 killed.getName(); and for killer try to use
    Code:java
    1. if(e.getEntity() instanceof HumanEntity) {
    2. HumanEntity kiler = (HumanEntity) e.getEntity().getLastDamageCause().getEntity();
    3. }

    Then use killer.getName().

    And you should check if the entity who died is a player or else you might get ClassCastExceptions.
     
  22. Offline

    stelar7

    I R CONFUS, how can a human entity be a mob? let alone lava!?
     
  23. Offline

    ThatBox

    Oh I thought a player was killing you sorry.
     
  24. Lava isn't an entity.

    Code:
    EntityDamageEvent lastDamage = e.getEntity().getLastDamageCause();
    if(lastDamage.getCause() == DamageCause.LAVA)
        System.out.println("it's freakin' lava!");
    else if(lastDamage.getCause() == DamageCause.ENTITY_ATTACK)
        System.out.println("Oh hey entity + " lastDamage.getEntity());
    else if(lastDamage.getCause() == DamageCause.PROJECTILE)
    {
        Projectile p = (Projectile)lastDamage.getEntity();
        System.out.println("Someone shot you! it's " + p.getShooter());
    }
    Something along those lines.
     
    ThatBox likes this.
  25. Offline

    ThatBox

    Basically what hes doing is looking up the damage cause and the entity who got damaged, in this case himself.
     
  26. Offline

    stelar7

    seems to be fixed now thx
     
Thread Status:
Not open for further replies.

Share This Page