setLore for my ItemStack does not work.

Discussion in 'Plugin Development' started by stvnzii, Sep 11, 2021.

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

    stvnzii

    I've been trying to create a plugin that allows you to customize the lore of different items, and I have made a method that changes the lore of items when you open a chest, but it does not seem to work.

    Code:
    ItemMeta meta = item.getItemMeta();
    if (meta == null) {
           System.out.println("EMPTY META CREATING NEW META");
           item.setItemMeta(Bukkit.getItemFactory().getItemMeta(item.getType()));
           meta = item.getItemMeta();
    }
    lore.add("\n" + customItem.getRarity().getColor() + customItem.getRarity().toString());
    System.out.println(lore);
    meta.setLore(lore);
    System.out.println(meta.getLore());
    item.setItemMeta(meta);
    The System.out.println prints an empty list, although the printing of the lore itself has stuff inside it. I've tried this inside another method and it worked, so I don't know why this isn't working. (This is also inside a loop of the inventory's contents, so the variable item is the loop variable).
     
  2. Offline

    Kars

    Show the whole code. It is impossible to tell where the error is just from that snippet as parts are missing.
     
  3. Offline

    man_in_matrix

    try using setlore instead of add lore
    meta.setLore(Arrays.asList(
    ChatColor.RED + "lore line 1",
    ChatColor.GREEN + "lore line 2"));
     
Thread Status:
Not open for further replies.

Share This Page