3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-04 23:30:17 +01:00

Fix some book translation failures (#661)

Book pages can be sent as plain text rather than JSON. The text library doesn't use lenient parsing, so this fails, and the book isn't visible in the inventory.

This will convert the text into JSON if it's not already, before feeding it to the text library.
Dieser Commit ist enthalten in:
Arktisfox 2020-05-25 21:19:37 -04:00 committet von GitHub
Ursprung d0545c57c4
Commit 0178492b59
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 18 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -55,7 +55,7 @@ public class BookPagesTranslator extends NbtItemStackTranslator {
CompoundTag pageTag = new CompoundTag("");
pageTag.put(new StringTag("photoname", ""));
pageTag.put(new StringTag("text", MessageUtils.getBedrockMessage(textTag.getValue())));
pageTag.put(new StringTag("text", MessageUtils.getBedrockMessageLenient(textTag.getValue())));
pages.add(pageTag);
}

Datei anzeigen

@ -137,6 +137,23 @@ public class MessageUtils {
}
}
/**
* Verifies the message is valid JSON in case it's plaintext. Works around GsonComponentSeraializer not using lenient mode.
* See https://wiki.vg/Chat for messages sent in lenient mode, and for a description on leniency.
*
* @param message Potentially lenient JSON message
* @return Bedrock formatted message
*/
public static String getBedrockMessageLenient(String message) {
if (isMessage(message)) {
return getBedrockMessage(message);
} else {
final JsonObject obj = new JsonObject();
obj.addProperty("text", message);
return getBedrockMessage(obj.toString());
}
}
public static String getBedrockMessage(String message) {
Component component = phraseJavaMessage(message);
return LegacyComponentSerializer.legacy().serialize(component);