Getting/Setting exp help!

Discussion in 'Spigot Plugin Development' started by JacksonHogan, May 29, 2016.

  1. I'm trying to check if the players exp is >= the exp set in config...
    This is what my code looks like...
    It says it takes 0 xp from the player. Like it doesnt even check if player has enough.

    Code (Java):
    if(player.getExp() >= CustomEnchant.config.getConfig().getInt("RandomBook.exp")){
                            RandomEnchant.giveRandomEnchant(player);
                         
                            player.setExp(player.getExp() - CustomEnchant.config.getConfig().getInt("RandomBook.exp"));
                            player.sendMessage(ChatColor.GREEN + "You successfully bought a random book for "
                                    + CustomEnchant.config.getConfig().getInt("RandomBook.exp") + " exp!");
                         
                        }else{
                            player.sendMessage(ChatColor.RED + "You don't have enough exp for this transaction!");
                        }
    Config...
    Code (YAML):
    RandomBook:
      exp
    : '1500'
     
     
    #1 JacksonHogan, May 29, 2016
    Last edited: May 29, 2016
  2. O sorry... I forgot to put why it wasn't working...
    It says it takes 0 xp from the player. Like it doesnt even check if player has enough.
     
  3. getInt() returns 0 by default in the event of improper formatting. Are you certain that the 1500 is an int, not a String?
     
  4. Pretty sure you don't put the int in a YAML file like exp: '1500'. If you still have the problem, try just putting exp: 1500
     
  5. Doesn't matter.