Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not parsing json messages in XML #955

Merged
merged 1 commit into from
Jan 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions util/src/main/java/tc/oc/pgm/util/text/TextParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ public static Component parseComponent(String text) throws TextException {
*
* <p>Accepts legacy formatting with "§" as the color character.
*
* <p>Accepts full qualified json strings as components.
*
* <p>This method is mainly for backwards compatability for {@link
* XMLUtils#parseFormattedText(Node, Component)}. Previously using {@link #parseComponent(String)}
* with the result from {@code parseFormattedText} would bug out when sent to older clients, since
Expand All @@ -442,10 +444,19 @@ public static Component parseComponent(String text) throws TextException {
*
* @param text The text.
* @return a Component.
* @throws TextException If there is json present and it is invalid.
*/
public static Component parseComponentSection(String text) {
checkNotNull(text, "cannot parse component from null");

if (text.startsWith("{\"") && text.endsWith("\"}")) {
try {
return GsonComponentSerializer.gson().deserialize(text);
} catch (JsonSyntaxException e) {
throw invalidFormat(text, Component.class, e);
}
}

return LegacyComponentSerializer.legacySection().deserialize(text);
}

Expand Down