How to check if player has item with display name in inventory

Discussion in 'Plugin Development' started by Baklava, Aug 3, 2019.

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

    Baklava

    Hello! I am currently making a plugin that requires me to check if a player has an item with a specified display name in their inventory. I tried iterating through all the items in the player inventory like this
    Code:
    for (ItemStack i : p.getInventory()) {
                                 if (i.getItemMeta().getDisplayName().equals("blah blah blah")) {
                                     //do whatever
                                 }
                             }
    but without success. Does anybody know a way that works? thanks in advance!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Baklava Check if i is null, check if there is itemMeta, check if there is a displayName
     
  3. Offline

    CONTREKEE

Thread Status:
Not open for further replies.

Share This Page