Detect the lore of an item

Discussion in 'Plugin Development' started by MinecraftDorado, Jul 12, 2016.

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

    MinecraftDorado

    I need to know how to detect an item with a specific lore. The code I've done no work.
    Code:
            if(cmd.getName().equalsIgnoreCase("coconut")){
                player.sendMessage(ChatColor.AQUA + "Debug");
               
                ItemStack coconut = new ItemStack(Material.SKULL_ITEM, 1);
                ItemMeta meta = coconut.getItemMeta();
                List<String> lore = new ArrayList<String>();
                lore.add("Coconut");
                meta.setLore(lore);
                coconut.setItemMeta(meta);
               
                if(player.getPlayer().getInventory().contains(coconut) == true){
                    player.sendMessage(ChatColor.GREEN + "You have a coconut!");
                    return true;
                }
                player.sendMessage(ChatColor.RED + "You haven't a coconut!");
                return true;
            }
    Someone knows how to make it work?
     
  2. Offline

    Jakeeeee

    Loop through the lore using #getLore, and check if the string is equal to the 'specific lore string'. Don't forget one will have color and one will not if you even use ChatColor.
     
    ChipDev likes this.
  3. Offline

    MinecraftDorado

  4. What you need to do is define the lore, then see if the item lore = the defined lore
    Code:
    ItemStack i = new ItemStack(Material.POTATO_ITEM);
    ItemMeta im = i.getItemMeta();
    i.setItemMeta(im);
    List<String> ilore = new ArrayList<String>();
    ilore.add(ChatColor.GREEN + "stuff");
    if (im.getLore() == ilore) {
            // Events to play
    }
     
  5. Offline

    MinecraftDorado

    @Shadowdragon8969
    When active the command does not detect me.
    Code:
            if(cmd.getName().equalsIgnoreCase("coconut")){
                ItemStack i = new ItemStack(Material.STONE);
                ItemMeta im = i.getItemMeta();
              
                List<String> ilore = new ArrayList<String>();
                ilore.add(ChatColor.GREEN + "Coconut");
              
                if (im.getLore() == ilore) {
                    player.sendMessage(ChatColor.GREEN + "You have a coconut");
                }
                player.sendMessage(ChatColor.RED + "You haven't a coconut!");
                return true;
            }
     
  6. Does your item's lore match what you are checking for?
     
  7. Offline

    SeniorCluckers

    Make sure to add Array in front of your List<String>, and what are you trying to do here?
    Are you trying to Check the players inventory for a certain Material, that has a certain lore, and if the player does have the Material with the certain lore, then send them a messsge saying "You have a coconut." ?
     
Thread Status:
Not open for further replies.

Share This Page