Checking for item lore

Discussion in 'Plugin Development' started by justin_393, Mar 30, 2015.

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

    justin_393

    How can I check if a player has an item in their inventory and it has a certain lore/display name? I have my custom item created in a different class and now i'm trying to check if a player's inventory contains it in a different class. Here's my code.

    Creating the item
    Code:
    @Sub(permission = "minecraftplanetearth.admin", description = "Get Keep Inventory item", minArgs = 0, allowConsole = true)
        public void getKeepInv(CallInfo call) {
            Player p = call.getPlayer();
            String keepInv = "Keep Inventory";
    
            List<String> lores = new ArrayList<String>();
            lores.add("Keep this in your inventory");
            lores.add("To keep your items on death");
            lores.add("Will be removed on death");
    
            ItemStack kI = new ItemStack(Material.DIAMOND);
            ItemMeta im = kI.getItemMeta(); 
            im.setDisplayName(keepInv); 
            im.setLore(lores);
            kI.setItemMeta(im); 
            p.getInventory().addItem(kI);
        }
    Checking for item
    Code:
    @EventHandler
        public void onDeath(PlayerDeathEvent event) {
            Player p = event.getEntity();
            if (event.getKeepInventory() == false) {
                if (p.getInventory().contains(Material.DIAMOND)) {}
            }
          
          
        }
     
  2. Offline

    caseif

    Iterate over the current inventory items and check each one for its material (getType()), display name (getItemMeta().getDisplayName()), and lore (getItemMeta().getLore()).
     
Thread Status:
Not open for further replies.

Share This Page