I'm trying to add a new lore line to an existing item in a player's inventory. This is my code so far, but gives me errors. I can't think of a way to get List<String> to somehow work in setLore(). Code (Text): List<String> loreCurrent = event.getCurrentItem().getItemMeta().getLore(); String[] loreCurrent1 = loreCurrent.toArray(new String[0]); String enchantName = event.getCursor().getItemMeta().getDisplayName(); event.getCurrentItem().getItemMeta().setLore(loreCurrent1, enchantName); Thanks, Max.
get the itemmeta and save it. get the lore and save it change the lore set the lore for the meta set the meta for the item
I've got this so far, but I'm not sure how I would go about adding a String to a List<String>. Code (Text): ItemStack currentItem = event.getCurrentItem(); ItemMeta currentItemItemMeta = currentItem.getItemMeta(); String name = currentItemItemMeta.getDisplayName(); List<String> currentItemLore = currentItemItemMeta.getLore(); List<String> currentItemLore1 = currentItemLore, name; currentItemItemMeta.setLore(currentItemLore1); currentItem.setItemMeta(currentItemItemMeta);
First of all check if it really has Lore. I will give you an example how to add a line to lore. Code (Java): ItemStack stack = ..... // Your itemstack ItemMeta meta = stack.getItemMeta(); // ItemMeta of the itemstack. if (meta.hasLore()) { // Checking if it already has lore. List<String> lore = meta.getLore(); lore.add("This is a line"); // Adding a line. meta.setLore(lore); // Setting lore. stack.setItemMeta(meta); // Setting ItemMeta. }
I've tried this out, but it doesn't give it a lore, it just creates a new empty line in the lore. Here is my code: Code (Text): ItemStack currentItem = event.getCurrentItem(); ItemMeta currentItemItemMeta = currentItem.getItemMeta(); String name = currentItemItemMeta.getDisplayName(); String name1 = ChatColor.stripColor(name); if (currentItemItemMeta.hasLore()) { List<String> lore11 = currentItemItemMeta.getLore(); lore11.add(name1); currentItemItemMeta.setLore(lore11); currentItem.setItemMeta(currentItemItemMeta); } else { currentItemItemMeta.setLore(Arrays.asList(name1)); currentItem.setItemMeta(currentItemItemMeta); }
Another dumb mistake I've made xD. I was checking for the wrong displayer name. Its all working now, thanks for the help!