Solved [1.9] Checking if a player has a XP level

Discussion in 'Spigot Plugin Development' started by tokyojack, May 24, 2016.

  1. Hello people!
    Im back with one of my "code thats really simple but I cant figure it out" questions!

    Im trying too see if a player has a level, and if so, remove a level, but if the player doesn't have a level,lets say half a bar, then just return and send that player a message. This is what I got atm:
    Code (Text):
    if (!(player.getExp() == 0) && player.getExpToLevel() < 0) {
    player.sendMessage("Removed 1 level!");

    return true;
    } else {
    player.sendMessage("You dont have a level!");

    return false;
    Additions and/or corrections are very much welcomed!

    Thanks in advance, Jack!
  2. so what you're doing is making sure their level is under 0, which is pretty impossible and I don't think you want that, I think you're looking for > 0 not < 0, because you're trying to take 1 away from less than 0 which just doesn't work with exp
  3. Yeah, thanks! Even after programming for a couple of years, I still can get those right! I have to use those alligator pictures, showing which ones what. :oops: I'll try now
  4. Nope, if the player is under 1, then it still continues, but if the XP is at a precise level, then it will return. Kinda funky.

    EDIT: Ignore that, it still works, but if its under the level one, it still continues.
  5. player.getExpToLevel() < 0
    You're checking if it's under 0
    player.getExpToLevel() >= 1
  6. Nope, still runs if the player has some xp. :confused:
  7. Debug the values in your console and check what they are when a player has no XP.
    Debug is the first step in solving your own problems.
  8. I already did that before posting this, non of them prevailed:(.
  9. Then at least tell us which values you got.
  10. Code (Text):
        public void a(Player b){
            if (b.getLevel() > 0){
                b.setLevel(b.getLevel() - 1);
            } else if (b.getExp() > 0){
                b.sendMessage("dank memes");
  11. Hey all, Im back!

    So, after alot of messing arond, I finally came out with this for anyone else running into this problem also:
    Code (Text):
    if (!(player.getExp() == 0) && player.getLevel() >= 1
    || player.getLevel() == 1)
    I know this seems like a bunch of overlapping bunch of code, but I tried compacting it, but it wouldn't work for some odd reason.

    I declare this post:

  12. Tux


    This is simpler (and might have the intended effect):

    Code (Java):
    player.getExp() > 0 || player.getLevel() > 0
    I didn't test it.