Question

I have a piece of code that outputs the player's total experience.

The issue is that the XP value it outputs doesn't change if the actual XP does. For example, at level 50,000 the XP was 2,147,483,647. When level dropped to 4, the XP value stayed the same.

if (cmd.getName().equalsIgnoreCase("checkxp")) {
    // If person is null, it's not a player!
    if (person == null) {
        sender.sendMessage("This command can only be used by a player, sorry!");
        return false;
    } else {
        int curxp;
        Player player = (Player) sender;
        curxp = player.getTotalExperience();
        sender.sendMessage("You currently have: " + curxp + " XP!");
        return true;
    }
}

How do I get this value to reset after it was ran so it re-checks the XP and updates the variable with the new amount?

Was it helpful?

Solution

Looking at ExpSkills, it seems that playing with experience instead of levels is the way to go.

So use setTotalExperience() and getTotalExperience() for now.

Once you get everything working, then try and add support for levels. Maybe there's a converter somewhere to convert levels to experience and experience to levels? If not, here are the conversion charts.

OTHER TIPS

If you don't update your Player object which looks like it's coming from sender it will hold the old values, so I check that sender is coming in with new data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top