Using formatting codes (§) is OUTDATED, but if you want to use it in plugins, use Texts.legacy().from("§aHello §eWorld!"), or if you have a custom formatting character (like &), use Texts.legacy('&').from("§aHello §eWorld!"). Your IDE or compiler will give you a warning that the method is deprecated; this is expected, as you should not be doing this.
You can use XML-based formatting by using Texts.xml().from("<color name=green>Hello</color> <color name=yellow>World!</color>"). This is the recommended way to do formatting with new plugins. This does not work with formatting codes.
org.spongepowered.api.util.TextMessageException: Error parsing TextXML message '<span><color name=yellow>test</color></span>'
...
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 19; Open quote is expected for attribute "name" associated with an element type "color".
I wasn’t sure whether the quotes were needed. Try Texts.xml().from("<color name=\"green\">Hello</color> <color name=\"yellow\">World!</color>"). If you’re reading the string from somewhere other than Java source, remove the backslashes (\ , NOT /).
@FerusGrim
Just weighing my options. I know it’ll be quite a while before the standard color codes are fazed out, but want to be prepared when they do.
Well isn’t that why Texts.legacy() is deprecated because mojang is getting rid of the standard formatting system? From what I can tell, this method will no longer function after that, in which case we’ll need something to identify color in config’s and chat. Maybe I’m misunderstanding the situation.
I’m unfamiliar with XML so does anyone know how to use the onClick, onHover attributes in this:
The file you linked is a XML Schema that describes the elements that may be used in a valid XML file.
Based in the schema I generated a demonstration file filled with blank data using Intellij Idea. It should give you an idea on how to correctly use XMLs as the properties are named rather clearly.
Sorry, I did not recognize that those are not covered by the schema.
As of writing there does not appear to be any documentation available. However a corresponding docs issue links to this Bukkit issue witch explains how onHover etc. work (on Bukkit this change was never implemented but it was picked up by Sponge developers).