Solved Setting XP

Discussion in 'Plugin Development' started by flash1110, Dec 24, 2014.

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

    flash1110

    My issue is that I'm trying to set xp, after someone buys an item. I'll post my code down below.

    Code:
    if (cmd.getName().equalsIgnoreCase("tool")) {
                if (args.length == 0) {
                    p.sendMessage(prefix + ChatColor.AQUA + "/tool repair");
                    return true;
                }
                if (p.hasPermission("pickaxe.repair")) {
                    if (args[0].equalsIgnoreCase("repair")) {
                       
                        int xp = (int) p.getLevel();
                        int newXP = (int) p.getLevel() - 75;
                       
                         if (xp >= 75) {
                         p.getItemInHand().setDurability((short) 0);
                         p.sendMessage(prefix + ChatColor.GREEN + "Repaired " + p.getItemInHand().getType() + " for 75 levels");
                         p.setExp((float) newXP);
                         }
                         else {
                             p.sendMessage(prefix + ChatColor.AQUA + "Insufficient exp");
                             return true;
                         }
                    }
                }
            }
     
  2. Offline

    mine-care

  3. Offline

    flash1110

    Ah, sorry, I omitted that part. The xp doesn't get removed, which means that the set command line isn't working, but I can't figure out why.
     
  4. Offline

    Unica

    @flash1110

    Try
    Code:
    int newXP = (int) p.getExp() - 75;
    
    Get their exp rather than their level.
    You're now getting their level and deducting 75 out of it.
    Hence, if the person is, for example level 2, he will get 2-75 xp = -73 xp. ?

    EDIT: Sorry, was solved. my mistake.
     
Thread Status:
Not open for further replies.

Share This Page