Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 16:12:46 +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:
Ursprung
d0545c57c4
Commit
0178492b59
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren