Translating alternate color codes

Is there a Sponge method equal to ChatColor.translateAlternateColorCodes(char code, String text) Bukkit method?

I think you can get a TextRepresentation from the Texts.legacy(char theChar) then pass it the string?

I’ve seen an easier way to do it, but I can’t see it right now…

The docs say there is a method called parseLegacyMessage(String text, char code) which well parses a messages from the legacy format using the specified character to the new color.
But inside the TextFactor.java file on GitHub there is only replaceLegacyCodes(String name, char from, char to) which replaces the current strings color formatting character to the new specified one. I would recommend trying to figure out how to use replaceLegacyCodes() to fit your needs. and read this.

Those github pages javadocs are out of date, as are the current docs. If you are able to read the API straight from the repository it’s the best way to be sure that you are using the up to date code.

Thats why i included replaceLegacyCodes()

Replace legacy codes only swaps between one legacy character code to another.

replaceLegacyCodes("%4This is a test message", ‘%’, ‘&’) would result in “&4This is a test message”

Bumping an old post, because people are finding it when searching.

On API 7

TextSerializers.FORMATTING_CODE.deserialize(string)
3 Likes