FirstEmpty

Discussion in 'Plugin Development' started by Pwninz, Oct 24, 2013.

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

    Pwninz

    I have been trying to make my plugin put the items it gives you into an empty slot but it just is not working.

    Code:
    ItemStack StoneSword = new ItemStack(Material.STONE_SWORD, 1);
                    PlayerInventory pi = player.getInventory();
                    pi.firstEmpty(StoneSword);
                }
    It keeps giving me an error after I put the Itemstack StoneSword in the parentheses. I just want it so it will put the items in an empty slot. Any help please?
     
  2. Offline

    KipperOrigin

    Try changing it to:
    Code:java
    1. ItemStack StoneSword = new ItemStack(Material.STONE_SWORD, 1);
    2. PlayerInventory pi = player.getInventory();
    3. int slot = pi.firstEmpty();
    4. pi.setItem(slot, StoneSword);

    Atleast that's how I do it.
     
    Pwninz likes this.
  3. Offline

    Pwninz

    Okay, it works when I have one item but when I have multiple items with one command it only give me the leather boots... Heres the new code:
    Code:java
    1. ItemStack StoneSword = new ItemStack(Material.STONE_SWORD, 1);
    2. ItemStack LeatherHelmet = new ItemStack(Material.LEATHER_HELMET, 1);
    3. ItemStack LeatherChestplate = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    4. ItemStack LeatherLeggings = new ItemStack(Material.LEATHER_LEGGINGS, 1);
    5. ItemStack LeatherBoots = new ItemStack(Material.LEATHER_BOOTS, 1);
    6. PlayerInventory pi = player.getInventory();
    7. int slot = pi.firstEmpty();
    8. pi.setItem(slot, StoneSword);
    9. pi.setItem(slot, LeatherHelmet);
    10. pi.setItem(slot, LeatherChestplate);
    11. pi.setItem(slot, LeatherLeggings);
    12. pi.setItem(slot, LeatherBoots);
     
  4. Offline

    NathanWolf

    Just use pi.addItem versus setItem- the inventory will automatically put the items in the next available slots.

    What you are doing there is getting the first available slot once, then putting 5 different items in it, each one replacing the last.
     
    Pwninz likes this.
  5. Offline

    Pwninz

    Oh, Thanks! Alright it makes sense now :)
     
    NathanWolf likes this.
Thread Status:
Not open for further replies.

Share This Page