player inventory contains problem

Discussion in 'Plugin Development' started by vYN, May 3, 2013.

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

    vYN

    Hi... I'm trying to check if a inventory contains an item.
    But it's not working for some reason...
    And i have made sure the chest contains the item... But it jumps straight for the else if... So pi.contains return false... But it should not...

    is = a diamond_block
    And the EnderChest has a diamond block in it...

    So here is the code i have:
    Code:
    static HashMap<ItemStack, Integer> itemReward = new HashMap<ItemStack, Integer>();
    static ArrayList<String> ItemStackList = new ArrayList<String>();
    Code:
    Inventory pi = player.getEnderChest();
     
                            for(String is : ItemStackList){
                                ItemStack sIS = new ItemStack(Material.getMaterial(is));
                                if(pi.contains(sIS)){
                                    if(!(pi.contains(sIS, 64))){
                                        int amount = itemReward.get(sIS);
                                        pi.addItem(new ItemStack(Material.getMaterial(is), amount));
     
                                        String query = "UPDATE users SET reward='1' WHERE `minecraft` = '" + pName + "';";
                                        player.sendMessage("pi.contains");
                                        try {
                                            statement.executeUpdate(query);
                                        } catch (SQLException ee) {
                                            // TODO Auto-generated catch block
                                            ee.printStackTrace();
                                        }
                                      }
     
                                    }else if(!(pi.firstEmpty() == -1)){
                                        int amount = itemReward.get(sIS);
                                        pi.addItem(new ItemStack(Material.getMaterial(is), amount));
     
                                        String query = "UPDATE users SET reward='1' WHERE `minecraft` = '" + pName + "';";
     
                                        player.sendMessage("pi.contains else pi.firstempty");
                                        try {
                                            statement.executeUpdate(query);
                                        } catch (SQLException ee) {
                                            // TODO Auto-generated catch block
                                            ee.printStackTrace();
                                        }
    }
     
  2. Do you mean something like this?
    Code:
     
     
    if(inventoryvariable.contains(DIAMOND_BLOCK)){
     
    inventoryvariable.addItem(IRON_BLOCK);
     
    p.updateInventory();
     
    
     
  3. Offline

    vYN

    facepalm
    I guess so yes... But for some reason... when i check for an item in the inventory. And i know the same item is in the inventory... It still returns false... And jumps to my else if...

    bump

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

Share This Page