Player exp change event?

Hey all I’ve been messing around with the Sponge API and noticed that I can’t seem to find the event for when A players exp changes. Is this going to be implemented on the next release of the API or am I just missing it and is it already there?
EDIT: also is there a general place where I/We can find these sorts of things like bukkit had this? PS I know this isn’t bukkit ^^

Hmmm, not sure but I think you need this event:

Than you iterate over “getItems()” and check for instance of org.spongepowered.api.entity.ExperienceOrb.


import org.spongepowered.api.entity.ExperienceOrb;
import org.spongepowered.api.event.entity.EntityPickUpItemEvent;

public class Listener{

   public void onExperienceChange(EntityPickUpItemEvent event){
      int experience;
      for (Entity entity : event.getItems())
         if (entity instanceof ExperienceOrb)
            experience +=((ExperienceOrb)entity).getExperience();
      System.out.println("Got " + experience +" points!");

Ah that seems like it could work indeed :smiley: (this is one of those moments where I wished that there was an implementation so I could test this “cringes”).

I am not sure if this works. But if you build the current implementation you could test it ;).
If your to lazy to build it you can download it from my build server xD. But ya don’t expect it to work good … .

This already is PR’ed, specifically here.

(tagging @thomas15v and @thimovss)

Have messed around with that but can’t seem to get that to work, neither can i get yours to work xD

Awesome work man :smiley: keep it up

Is picking up the orb the only way xp changes? If not this may not be reliable.

EDIT: Also should point out that “change” could mean loss of Experience, like when an item is enchanted, death, or standing on an xp drain from Liquid XP or OpenBlocks.

1 Like

no there should be a function for the Player object

1 Like