Check what item is in the first Inventory spot

Discussion in 'Plugin Development' started by Cr4zy[Box], Oct 8, 2013.

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

    Cr4zy[Box]

    Hey guys, hope i can get some help with this, so basically i want to manually check what item is in the frist spot of players inventory, or second etc, I want to know and have full controll.
    For example i want to see what item does a player contain in this particular spot:
    Untitled.png

    Sry my English hope i was clear enough
     
  2. Offline

    Garris0n

    You'll have to iterate through all the slots in the player's inventory and check what's in them.

    Code:java
    1. //This will iterate through their hotbar, look up the numbers for the rest of the inventory.
    2. for(int i = 0; i < 9; i++){
    3.  
    4. ItemStack item = player.getInventory().getItem(i);
    5. if(item.getType().equals(Material.IRON_INGOT) && item.getAmount() == 59)
    6. player.getInventory().setItem(i, new ItemStack(Material.DIRT, 59);
    7.  
    8. }
     
    Cr4zy[Box] likes this.
  3. Offline

    Cr4zy[Box]


    let me see if i get it, u looped throught the frist 9 slots and if in any of those there is 59 iton ingots it replaces them by dirt right?

    So if i do,
    ItemStack item = player.getInventory().getItem(0);
    IT should return Iron_Ingots .. ?
     
  4. Offline

    Garris0n

    Well you have to figure out which slot is which. Slot 0 is the far left slot on your hotbar, so that's not right. I believe slot 9 is the slot you want in this case, but I'm not positive, and you'll have to do some testing(maybe with the InventoryClickEvent) to find out.
     
    Cr4zy[Box] likes this.
  5. Offline

    Cr4zy[Box]

    Never mind i just figured it out :D thx alot mate

    Ow and if u are wondering i got it by checking this spot:
    player.getInventory().getItem(28);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. Offline

    Garris0n

    Use the edit button instead of double posting, but yeah, I wasn't sure which one it was :p
     
Thread Status:
Not open for further replies.

Share This Page