Check if player does not contain an item?

Discussion in 'Plugin Development' started by youngbawss22, Nov 21, 2012.

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

    youngbawss22

    I have a quick question,

    how would i check the players inventory to see if he does NOT contain a specific item/itemstack? Thanks!
     
  2. Offline

    RealDope

    Code:JAVA
    1.  
    2. PlayerInventory inventory = player.getInventory();
    3. if(!inventory.contains(Material.SOME_ITEM) {
    4. // He doesn't have SOME_ITEM
    5. }
    6.  


    Or alternatively to the Material_SOME_ITEM you can use an ItemStack.
     
    Ne0nx3r0 likes this.
  3. Really, a not check (!) is one of the most basic programming basics... Go learn more before you code.
     
  4. Offline

    thefiscster510

    What if I want to check if they have a specific amount of a given item?..
     
  5. Offline

    fireblast709

    Code:java
    1. if(inventory.contains(Material.[thematerial], [minimumamount]))
    2. {
    3. // it contains at least [minimumamount] of [thematerial]
    4. }
     
    thefiscster510 likes this.
  6. Offline

    Gravity

    Answer the question, or don't reply at all please! Also, if you're asking for help it's advised you be gracious when people reply.
     
Thread Status:
Not open for further replies.

Share This Page