Solved Not removing my items from hand

Discussion in 'Plugin Development' started by Shzylo, Jul 30, 2013.

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

    Shzylo

    I have a config for how much of an item they need to use it, I tested it with the number 2 and when it is 1, it will tell me I need 2 of that item, but if I have 2 of that in my hand, it will be infinite. Here is the code:
    Code:
    if (p.getItemInHand().getAmount() >= miningAmount) {
        p.getItemInHand().setAmount(p.getItemInHand().getAmount() - miningAmount);
    } else {
        p.sendMessage(String message);
    }
    I even tried this, but it still doesn't work:
    Code:
    if (p.getItemInHand().getAmount() > miningAmount) {
        p.getItemInHand().setAmount(p.getItemInHand().getAmount() - miningAmount);
    } else if (p.getItemInHand().getAmount() == miningAmount) {
        p.getItemInHand().setType(Material.AIR);
    } else {
        p.sendMessage(String message);
    }
     
  2. Offline

    Tarestudio

    Shzylo
    Firtst of, I hope you checked if (p.getItemInHand() != null) before.
    So, if I got you right, with 1 item you get your message as you want. With the equal amount it happens nothing? Even no error? And what happens if you have 3 or more? Try your second code with p.setItemInHand(null)
     
    Shzylo likes this.
  3. Offline

    Shzylo

    If you have 3 or more, the items will be removed. I did not use getItemInHand() != null I checked if their hand had that material in it which works perfectly without bugs, and I used setting the item in hand to null which works, thank you! Haven't used bukkit API in a couple weeks :p
     
Thread Status:
Not open for further replies.

Share This Page