Hey I try to update lores in my Inventory but it dont work here my code: Config replacer: Code (Text): public void variable(List<String> lore, Player p){ for(int i = 0; i < lore.size(); i++){ String name = p.getName(); lore.set(i, ChatColor.translateAlternateColorCodes('&', lore.get(i).replaceAll("%name", name))); } } StringList: Code (Text): public List<String> infolore = getConfig().getStringList("Profile.Inventory.Info.Lore"); InventoryUpdater: Code (Text): lores = new BukkitRunnable() { [USER=32110]@Override[/USER] public void run() { String invinfodisname = plugin.getConfig().getString("Profile.Inventory.Info.ItemName"); invinfodisname = color(invinfodisname); (color(name) is only ChatColor.translate....) ItemStack info = new ItemStack(Material.getMaterial(plugin.getConfig().getString("Profile.Inventory.Info.ItemID"))); ItemMeta infometa = info.getItemMeta(); infometa.setDisplayName(invinfodisname); variable(plugin.infolore, p); infometa.setLore(plugin.infolore); info.setItemMeta(infometa); inv.clear(); p.updateInventory(); inv.setItem(11, info); p.updateInventory(); } }.runTaskTimer(plugin, 20, 5); p.openInventory(inv); } Lores from the Stringlist on items will work but I cant update the lores... Can anyone help me ? MfG nflug
So there is %name in every item lore? Try "replace()" instead of "replaceAll()": Code (Text): public void variable(List<String> lore, Player p){ for(int i = 0; i < lore.size(); i++){ String name = p.getName(); lore.set(i, ChatColor.translateAlternateColorCodes('&', lore.get(i).replace("%name", name))); } }
When you modified your lore containing %name once it contains for example "Friwi" instead. Then you got the problem that it wont update ever again. You should create a copy of plugin.infolore before processing it through variable() and then use the copy as a lore. Hope this helps
Code (Text): public static List<String> copyList(List<String> list) { List<String> clone = new ArrayList<String>(list.size()); for(String item: list) clone.add(item+""); return clone; }
Code (Text): ... ItemMeta infometa = info.getItemMeta(); infometa.setDisplayName(invinfodisname); List<String> l = copyList(plugin.infolore); variable(l, p); infometa.setLore(l); info.setItemMeta(infometa); ...