Getting item in inventory

Discussion in 'Plugin Development' started by inventorman101, Jun 5, 2013.

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

    inventorman101

    How do you check to see if a player has a specific item with a specific display name in their inventory. Also the item slot #

    bump

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

    kreashenz

    Please don't bump till after 12 hours.
    You can
    Code:
    //pseudo code
    check if item is in their inv
    check if it hasItemMeta
    item.getSlot();
     
  3. Offline

    inventorman101

    What is the code for that to check for both of those kreashenz
     
  4. Offline

    kreashenz

  5. Offline

    inventorman101

    kreashenz I have the check if the item is in their inv but I am not sure how to check if it has the right item meta.
     
  6. Offline

    kreashenz

    inventorman101
    Code:java
    1. for(ItemStack i : player.getContents())
    2. if(i.hasItemMeta().getDisplayName().equalsIgnoreCase("string!"))

    I think that'd work.
     
  7. Offline

    inventorman101

    Thanks so does this loop until it finds an item with the right meta data

    I debugged some of your code but the second line in the if statement doesn't work kreashenz

    Code:
    for(ItemStack i : p.getInventory().getContents())
                        {
                     
                            if(i.hasItemMeta().getDisplayName().equalsIgnoreCase("string!"));
                        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  8. Offline

    kreashenz

  9. Offline

    inventorman101

    It doesn't work it says "cannot invoke getDisplayName on primitive type boolean" kreashenz
     
  10. Offline

    kreashenz

  11. Offline

    inventorman101

    kreashenz That doesn't work. I don't think that is the right code for this.
     
  12. Offline

    kreashenz

    inventorman101 Maybe you should try mess around with that, it's a very simple thing to do.. You're not doing something right..
     
  13. Offline

    inventorman101

    Can anyone else help me?
     
  14. Offline

    Kuuk

    Maybe this could help you out. This is a piece of a plugin of mine. Here it check's if the player has an item in his/her inventory with a metadata displayname which contains "helm".
    Code:java
    1. ItemStack[] invcheck = player.getInventory().getContents();
    2. if(CheckHelm == true){
    3. sender.sendMessage(ChatColor.BLUE + "[Carmor debug] Helm being checked.");
    4. for(ItemStack item:invcheck){
    5. if(item != null){
    6. if(item.hasItemMeta()){
    7. if(item.getItemMeta().getDisplayName().contains("helm")){
    8. inv.remove(item);
    9. inv.addItem(helmet);
    10. sender.sendMessage(ChatColor.BLUE + "[Carmor debug] Helm found and replaced! (" + item + ")");
    11. }
    12. }
    13. }
    14. }
    15. }
     
Thread Status:
Not open for further replies.

Share This Page