"Inventory does not contain itemstack" (Even though it does!!)

Discussion in 'Plugin Development' started by joehot2000, Mar 16, 2013.

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

    joehot2000

    Ok, hi, this is my current code:


    Code:
     if (!player.getInventory().contains(new ItemStack(388, cost))){
    player.sendMessage(ChatColor.RED + "[EndcraftShop] You dont have enough emeralds!");
    return;
    }
    player.getInventory().addItem(new ItemStack(mat, amt));
    player.getInventory().remove(new ItemStack(388, cost));
    player.updateInventory();
    And it is always coming up with the "you dont have enough emeralds", even when i added the lines

    player.getInventory().addItem(new ItemStack(388, cost));
    player.updateInventory(); above it!

    What am i doing wrong?

    Thanks in advance.
     
  2. Offline

    chasechocolate

    Try using .containsAtLeast(<the ItemStack>).
     
  3. Offline

    joehot2000

    ContainsAtLeast has got to have an itemstack and an integer.

    What would i put in the integer?

    if (!player.getInventory().containsAtLeast(new ItemStack(388, 1) (itemstack) , cost (int) ))

    OK, NEVERMIND, I FIXED IT! THANKS FOR THE NICE CODE :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page