1.14.4 I need some help!

Discussion in 'Spigot Plugin Development' started by xMaikiYT, Mar 23, 2020.

  1. I want to check with a command, if a player have an item with a custom lore in his invenotry!
  2. Code? What have you tried so far?
  3. Nothing... Idk that!
  4. You may want to use a for loop to loop through the items in the players inventory then check if it contains an itemmeta then a lore.
  5. PseudoCode
    Something like this.
    Code (Java):
    for(Item item : player.getInventory().getContent()) {
    • Like Like x 1
  6. I do that but its not working...
    22 for(ItemStack item : player.getInventory().getContents())
    23 if(player.getInventory().getType().equals(Material.EMERALD)) {

    For line 22 says: upload_2020-3-23_15-44-10.png

    And for 23 says: upload_2020-3-23_15-44-37.png
  7. Inventory extends Iterable<ItemStack>, so it can simplified to for(ItemStack item : player.getInventory())
    edit: but according to javadocs, it's not recommended
    Check your item - not inventory.
    • Agree Agree x 1
    • Like Like x 1
  8. its correct? upload_2020-3-23_16-3-18.png
    upload_2020-3-23_16-3-32.png error!
  9. Take a look at the docs.
    #getMainHand() returns a "MainHand", not the item. Furthermore the warning appears because "MainHand" is either LEFT or RIGHT, nothing else, so that's something different than a Material. Also enums (which materials are) should be compared with ==
  10. If you want to check for a lore on any type of item use this:

    Code (Text):
    for (ItemStack item : p.getInventory().getContents()) {
                    if(item.getItemMeta().getLore() == otheritem.getItemMeta().getLore()) {
    //                    whatever you want it to do

  11. No, getLore returns a List, comparing lists like that will certainly return false. Not to talk about the fact that many NPEs could be thrown in this code.
  12. for specific strings:

    Code (Text):
    for (ItemStack item : p.getInventory().getContents()) {

                        String lorestring = "test";

                        if (item.getItemMeta().getLore().contains(lorestring)) {
    //                        whatever you want it to do