[Urgent] Lore Issues!

Discussion in 'Plugin Development' started by Keubix, Aug 6, 2015.

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

    Keubix

    Hello, I am making a custom enchants plugin for my server, and I have run into an issue with checking the lore when you buy an enchant.
    Code:
    public void setLore(Player player, String enchant) {
    
            ItemStack item = player.getItemInHand();
    
            ItemMeta meta = item.getItemMeta();
    
            if (item.hasItemMeta()) {
    
                if (meta.hasLore()) {
    
                    List<String> getLore = meta.getLore();
    
                    ArrayList<String> lore = new ArrayList<String>();
    
                    if (getLore.contains(ChatColor.stripColor(enchant))) {
    
                        player.sendMessage(prefix+"Item already has enchant!");
    
                    }
    
                    else {
    
                        lore.addAll(getLore);
    
                        lore.add(ChatColor.GRAY + enchant);
    
                        meta.setLore(lore);
    
                        player.getItemInHand().setItemMeta(meta);
    
                        player.sendMessage(prefix+"Item has been enchanted!");
    
                    }
    
                }
    
            }
    
        }
    
    When the player clicks on an item in the GUI, it will add a lore to the item in the players hand. But I want to check whether or not the player already has that lore. If they do have it, then the purchase will be canceled, if they don't have it, then the lore will be added in with the other lore the item has (custom enchants are lore, so if they have other ones, I don't want them to be taken away, I want the one they are buying to get added to the list they already have.) Thanks for the help!
     
  2. Offline

    Shortninja66

    You need to be sure that you are checking for the correct text since it is case sensitive. You can do some debugging with sysout.
     
  3. Offline

    Keubix

    What is sysout?
    Nevermind, I just realized how stupid that question was xD
     
    Last edited: Aug 6, 2015
Thread Status:
Not open for further replies.

Share This Page