PlayerDeathEvent setNewExp() buggy?

Discussion in 'Plugin Development' started by AbdulAbdalla, Dec 13, 2011.

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

    AbdulAbdalla

    Hey,

    i tried to avoid exp loss on death, but the api seems to be buggy.

    Code:
    public void onEntityDeath(EntityDeathEvent event) {
            if (event.getEntity() instanceof Player) {
                Player pl = (Player)event.getEntity();
                PlayerDeathEvent death = (PlayerDeathEvent)event;            
                death.setNewExp(pl.getTotalExperience());
                event.setDroppedExp(0);      
            }
        }
    My exp level get increased everytime i gained some exp and died after that.

    Any ideas?

    Best regards
     
  2. Offline

    Chiller

    I dont think you set the exp for the death event try just doing pl.setExp(pl.getTotalExperience());
     
  3. Offline

    AbdulAbdalla

    That does not show any effects. After i die my exp got decreased.
     
  4. Offline

    user_43347

    Player death never drops the actual amount of EXP you have, it was changed (by Mojang) because it caused far to much lag. So for them to drop it all, would be a bad idea, but anyways, try something liks this:
    Code:
    event.setDroppedExp(player.getTotalExperience());
    The problem with yours is that your resetting your EXP to the level you had before, then on death, clearing it.
     
  5. Offline

    AbdulAbdalla

    Sure your code works so far, but i dont want to primary change the dropped exp. Im going to totaly avoid the loss of exp when you die. The documentation says setNewExp() is what i need, but i cant get it to work.

    Edit: Ahhw it was an bukkit issue. I updated to the latest development build and now all works fine :) Thank you all.
     
  6. Offline

    user_43347

    Well then don't put it under PlayerDeathEvent, because at that same event, the EXP is cleared. That's just bad practice.
     
  7. Offline

    ibhh

    There was an change:

    getTOTALExpirience()
    is now
    getTOTALExp()
    and
    at setTOTALExp() the same.
    If you use setExp() Bukkit only set the percent of the level wich is filled.
     
  8. Offline

    AbdulAbdalla

    setNewExp() in the entity death event works fine for me with the newest bukkit version :p
     
Thread Status:
Not open for further replies.

Share This Page