Hey, I am storing some colored names/lores in a config in my plugin. When regenerating the config the § character gets messed up (it gets replaced with some random letters) and the color code stops working. How do I avoid this? (I can manually replace the random letters back to §).
Is translating going to be simple? I am storing ItemStacks in the config which I generate when some event happens, how am I supposed to translate the color codes for the ItemStacks. Would I need to rename them to their respective translated name any time I load them?
This Code (Text): ChatColor.translateAlternateColorCodes('&', "&b&lCool Message here with fancy Colours");
Code (Text): ItemStack anItemStack = getConfig().getItemStack("path"); anItemStack.getItemMeta().setDisplayName(ChatColor.translateAlternateColorCodes('&', anItemStack.getItemMeta().getDisplayName())); That's the only way I see this working, disregarding the lore checking. Correct me if I am wrong.
That is basically how to use it, yea. It just takes any string you have and returns a new string that replaces the given char with section signs(§)
Just create a method like this: Code (Java): private String formatColors(String arg) { return ChatColor.translateAlternateColorCodes('&', arg); } private List<String> formatColors(List<String> arg) { ArrayList<String> preList = new ArrayList<>(); arg.stream().forEach(s -> preList.add(formatColors(s))); return preList; } P.S. Written without IDE, may have made a mistake in creating a stream. P.P.S. Use formatColors(Arrays.asList(.....)) for your lore.
Why do that when you could... Code (Java): private String formatColors(String arg) { return ChatColor.translateAlternateColorCodes('&', arg); } private List<String> formatColors(List<String> arg) { return arg.stream().map(string -> formatColors(string)).collect(Collectors.toList()); }
like I said look insto streams, its alot cleaner. can be shortened to Code (Java): arg.stream().map(this::formatColors).collect(Collectors.toList());
You only have to set encoding to UTF-8. Using ChatColor's method isn't a bad idea but you can avoid it and it's easier to just change the encoding.
no its not, using the § character is super bad practice, not to mention its harder on users since that character isnt even on the keyboard.