I've created a for loop for List lores. That people can create new lores in the config. That works if you don't add color support. And i need color support, anyone do understand this and can help me? Spoiler: CODE Code (Text): public void setupItem3(){ item3 = new ItemStack(Material.valueOf(fm.getConfig("Inventories.yml").get("Inventories.Test.Items.3.Material"))); ItemMeta meta = item3.getItemMeta(); meta.setDisplayName(ChatUtil.format(fm.getConfig("Inventories.yml").get("Inventories.Test.Items.3.Name"))); int lines = fm.getConfig("Inventories.yml").getInt("Inventories.Test.Items.3.Lore.Lines-Total"); for (int i = 0; i < lines; i++) { List<String> lore = new ArrayList<>(); lore.add(ChatUtil.format(fm.getConfig("Inventories.yml").get("Inventories.Test.Items.3.Lore.lore-" + (i + 1)).replace("%arrow%", "»").replace("&", "§"))); meta.setLore(lore); item3.setItemMeta(meta); } }
You can add color support by using ChatColor.translateAlternateColorCodes('&',string); Replace the string with the input from the yml and this will make a string with all color codes.
Get the string list, use Code (Text): .stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList());
Put that method after your string list, this method returns a string list. For example Code (Text): List<String> memes = new ArrayList<>(); memes.add("&6DOGE"); memes = memes.stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList()); Bukkit.broadcastMessage(memes.get(0)); This returns DOGE
Spoiler: Code that i've tried.java Code (Text): public void setupItem3(){ item3 = new ItemStack(Material.valueOf(fm.getConfig("Test.yml").get("Inventories.Compass.Items.3.Material"))); ItemMeta meta = item3.getItemMeta(); meta.setDisplayName(ChatUtil.format(fm.getConfig(" public void setupItem3(){ item3 = new ItemStack(Material.valueOf(fm.getConfig("Inventories.yml").get("Inventories.Compass.Items.3.Material"))); ItemMeta meta = item3.getItemMeta(); meta.setDisplayName(ChatUtil.format(fm.getConfig("Inventories.yml").get("Inventories.Compass.Items.3.Name"))); int lines = fm.getConfig("Inventories.yml").getInt("Inventories.Compass.Items.3.Lore.Lines-Total"); for (int i = 0; i < lines; i++) { List<String> lore = new ArrayList<>(); lore.add(ChatUtil.format(fm.getConfig("Inventories.yml").get("Inventories.Compass.Items.3.Lore.lore-" + (i + 1)).replace("%arrow%", "»").replace("&", "§"))); lore.add("&6DOGE"); lore = lore.stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList()); Bukkit.broadcastMessage(lore.get(0)); meta.setLore(lore); item3.setItemMeta(meta); } } .yml").get("Inventories.Compass.Items.3.Name"))); int lines = fm.getConfig("Inventories.yml").getInt("Inventories.Compass.Items.3.Lore.Lines-Total"); for (int i = 0; i < lines; i++) { List<String> lore = new ArrayList<>(); lore.add(ChatUtil.format(fm.getConfig("Inventories.yml").get("Inventories.Compass.Items.3.Lore.lore-" + (i + 1)).replace("%arrow%", "»").replace("&", "§"))); lore.add("&6DOGE"); lore = lore.stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList()); Bukkit.broadcastMessage(lore.get(0)); meta.setLore(lore); item3.setItemMeta(meta); } }
Does Collectors.toList() need the list type? Like Collectors.<String>toList()? My guess would be it doesn't, but I admit I have no idea.