Is there a Sponge method equal to ChatColor.translateAlternateColorCodes(char code, String text)
Bukkit method?
* @return The legacy formatting character */ char getLegacyChar(); /** * Return a representation that accepts and outputs legacy color codes, using the provided legacy character. * * @param legacyChar The legacy character to parse and output using * @return The appropriate legacy representation handler */ TextRepresentation legacy(char legacyChar); /** * Removes the legacy formatting character from a legacy string. * * @param text The legacy text as a String * @param code The color character to be replaced * @return The stripped text */ String stripLegacyCodes(String text, char code);
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)
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
This file has been truncated. show original
3 Likes