Solved Exp reset to login value when user repairs or enchants.

Discussion in 'Plugin Development' started by NewsByShawn, Feb 21, 2016.

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

    NewsByShawn

    I am currently removing exp from users for certain tasks via api. All is working well, the bar animates and counts down per exp, and level as expected.
    The issue comes after, when a user uses enchanting table or anvil. The exp will reset it self to the logged in value of the user after our loop is run.

    I am guessing that i am not saving the value, just animating the bar. My question is, how do i set the actual value to the api, if in-fact i am not doing so below?

    Code:
                    int pcurrent = p.getTotalExperience();
                    p.setTotalExperience(0);
                    p.setLevel(0);
                    p.setExp(0);
                    p.giveExp(pcurrent - 1);
    
     
    Last edited: Feb 21, 2016
  2. Offline

    Xerox262

    @NewsByShawn I don't understand what you mean, however I can tell you that setTotalExperience(); and getTotalExperience(); doesn't have anything to do with the actual exp bar.
     
  3. Offline

    NewsByShawn

    Thank you for the fast response. Also sorry for such a newb question. I kept digging in the java docs and did see
    setTotalExerience();

    I feel really silly now, but the below, i hope, should do the trick, and thank you again.
    1. int pcurrent = p.getTotalExperience();
      //p.setTotalExperience(0);
      p.setLevel(0);
      p.setExp(0);
      p.giveExp(pcurrent - 1);
      p.setTotalExperience(pcurrent -1);
    Thing is in my loops i was setting total exp to 0 but after user used the anvil or ench table the exp still reset to the value they logged in with.

    It seems as though i am not setting the value still.
     
    Last edited: Feb 21, 2016
  4. Offline

    elian1203

    I'm not exactly sure what you mean, but try saving it to a HashMap<UUID, Integer>?
     
  5. Offline

    NewsByShawn

    I am just trying to get the total exp a user has, then remove "1 exp" and then set total. What i am seeing is that setTotalExperience does not seem to be setting the experience, because after i remove some exp, and the user uses an anvil or ench table, their exp gets reset to value before i removed.
     
  6. Offline

    Xerox262

    @NewsByShawn So your problem is you want to store their exp when they log in, use the exp bar as a countdown but if a player uses an enchanting table reset their exp so they use their own?

    Since getTotalExperience() and setTotalExperience() are broken you have to store both the player's level and exp, using getLevel() and getExp().

    Check if a player uses an anvil or enchanting table, halt their countdown, reset their exp.
     
  7. Offline

    NewsByShawn

    You are a life saver, i have been banging my head at those for more than a week now, and i have not seen anywhere that they are broke lol. Thank, i will write a class to getLevel, getExp.

    This can be marked as solved.
     
  8. Offline

    Xerox262

    NewsByShawn likes this.
  9. Offline

    NewsByShawn

Thread Status:
Not open for further replies.

Share This Page