Checking for stuff in player inventory

Discussion in 'Plugin Development' started by jacklin213, Sep 16, 2012.

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

    jacklin213

    How do i check if 2 items(under "Item:" in the config.yml) are next to each other in a player inventory and do something if the stacks a both 1
     
  2. Offline

    kyle1320

    jacklin213
    This is probably the worst way to do it, but..:
    Code:
    PlayerInventory inv = player.getInventory();
    Material m1 = Material.getMaterial(plugin.config.getString("Item.One"));
    Material m2 = Material.getMaterial(plugin.config.getString("Item.Two"));
    HashMap<Material, Integer> found = new HashMap<Material, Integer>();
    for (int i = 0; i<inv.getSize(); i++) {
        if (inv.getItem(i) != null && inv.getItem(i).getType() == m1) {
            if (found.containsKey(m2)) {
                if (found.get(m2) + 1 == i || found.get(m2) + 9 == i) {
                    ItemStack i1 = inv.getItem(found.get(m2));
                    ItemStack i2 = inv.getItem(i);
                    //whatever you want to do
                    found.clear();
                    break;
     
                }
            }else {
                found.put(m1, i);
            }
        }else if (inv.getItem(i) != null && inv.getItem(i).getType() == m2) {
            if (found.containsKey(m1)) {
                if (found.get(m1) + 1 == i || found.get(m1) + 9 == i) {
                    ItemStack i1 = inv.getItem(found.get(m1));
                    ItemStack i2 = inv.getItem(i);
                    //whatever you want to do
                    found.clear();
                    break;
                }
            }else {
                found.put(m2, i);
            }
        }
    }
    And the config would look something like:
    Code:
    Item:
      One: DIRT
      Two: DIAMOND
     
  3. Offline

    jacklin213

    Ooh god I'm screwed XD
     
Thread Status:
Not open for further replies.

Share This Page