How to check for items?

Discussion in 'Plugin Development' started by MidnightTNT, Mar 12, 2014.

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

    MidnightTNT

    Here's my problem:
    I want to check the player's inventory for (x) amount of a certain item, and store it in a variable.
    How would I do this?
     
  2. Offline

    Minesuchtiiii

    public void getItemAmount(Player p.ItemStack istack, int count) {
    if(p.getInventory().contains(istack) {
    return istack.getAmount();
    }
    }

    something like that
     
  3. Offline

    Amgis

    MidnightTNT
    Code:java
    1. public int getAmount(Player player, ItemStack item) {
    2.  
    3. int quantity = 0;
    4.  
    5. if(item != null) {
    6.  
    7. for(ItemStack itemStack:player.getInventory().getContents()) {
    8.  
    9. if(itemStack != null && itemStack.isSimilar(item)) {
    10.  
    11. quantity += itemStack.getAmount();
    12. }
    13. }
    14. }
    15.  
    16. return quantity;
    17. }
     
    Mathias Eklund likes this.
  4. Offline

    MidnightTNT

    Thank You!
     
Thread Status:
Not open for further replies.

Share This Page