Class MessageTranslator
java.lang.Object
org.geysermc.geyser.translator.text.MessageTranslator
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.kyori.adventure.text.ComponentcomponentFromNbtTag(Object nbtTag) static @Nullable StringconvertFromNullableNbtTag(GeyserSession session, @Nullable Object nbtTag) static StringconvertJsonMessage(String message, String locale) static StringconvertMessage(net.kyori.adventure.text.Component message) DO NOT USE THIS METHOD unless where you're calling from does not have a (reliable) way of getting the context's locale.static StringconvertMessage(net.kyori.adventure.text.Component message, String locale) Convert a Java message to the legacy format ready for bedrock.static StringconvertMessage(GeyserSession session, net.kyori.adventure.text.Component message) Convenience method for locale getting.static StringconvertMessageForTooltip(net.kyori.adventure.text.Component message, String locale) Convert a Java message to the legacy format ready for bedrock, for use in item tooltips (a gray color is applied).static StringconvertMessageLenient(String message) static StringconvertMessageLenient(String message, String locale) Verifies the message is valid JSON in case it's plaintext.static StringconvertMessageRaw(net.kyori.adventure.text.Component message, String locale) Convert a Java message to the legacy format ready for bedrock.static StringconvertToJavaMessage(String message) Convert a Bedrock message string back to a format Java can understandstatic StringconvertToPlainText(String message) Convert legacy format message to plain textstatic StringconvertToPlainText(net.kyori.adventure.text.Component message, String locale) Convert a Java message to plain textstatic StringconvertToPlainTextLenient(String message, String locale) Convert JSON and legacy format message to plain textstatic StringdeserializeDescription(GeyserSession session, org.cloudburstmc.nbt.NbtMap tag) Deserialize an NbtMap with a description text component (usually provided from a registry) into a Bedrock-formatted string.static StringdeserializeDescriptionForTooltip(GeyserSession session, org.cloudburstmc.nbt.NbtMap tag) Deserialize an NbtMap with a description text component (usually provided from a registry) into a Bedrock-formatted string.static net.kyori.adventure.text.format.StylegetStyleFromNbtMap(org.cloudburstmc.nbt.NbtMap map) static net.kyori.adventure.text.format.StylegetStyleFromNbtMap(org.cloudburstmc.nbt.NbtMap map, net.kyori.adventure.text.format.Style base) static voidhandleChatPacket(GeyserSession session, net.kyori.adventure.text.Component message, org.geysermc.mcprotocollib.protocol.data.game.Holder<org.geysermc.mcprotocollib.protocol.data.game.chat.ChatType> chatTypeHolder, net.kyori.adventure.text.Component targetName, net.kyori.adventure.text.Component sender, @Nullable UUID senderUuid) static voidinit()static booleanisTooLong(String message, GeyserSession session) Checks if the given message is over 256 characters (Java edition server chat limit) and sends a message to the user if it isstatic StringnormalizeSpace(String string) Normalizes whitespaces - a thing a vanilla client apparently does with commands and chat messages.signTextFromNbtTag(GeyserSession session, List<?> nbtTag)
-
Constructor Details
-
MessageTranslator
public MessageTranslator()
-
-
Method Details
-
convertMessage
Convert a Java message to the legacy format ready for bedrock. UnlikeconvertMessageRaw(Component, String)this adds a leading color reset. In Bedrock some places have build-in colors.- Parameters:
message- Java messagelocale- Locale to use for translation strings- Returns:
- Parsed and formatted message for bedrock
-
convertMessageForTooltip
public static String convertMessageForTooltip(net.kyori.adventure.text.Component message, String locale) Convert a Java message to the legacy format ready for bedrock, for use in item tooltips (a gray color is applied).- Parameters:
message- Java messagelocale- Locale to use for translation strings- Returns:
- Parsed and formatted message for bedrock, in gray color
-
convertMessageRaw
Convert a Java message to the legacy format ready for bedrock. UnlikeconvertMessage(Component, String)this version does not add a leading color reset. In Bedrock some places have build-in colors.- Parameters:
message- Java messagelocale- Locale to use for translation strings- Returns:
- Parsed and formatted message for bedrock
-
convertJsonMessage
-
convertMessage
public static String convertMessage(GeyserSession session, net.kyori.adventure.text.Component message) Convenience method for locale getting. -
convertMessage
DO NOT USE THIS METHOD unless where you're calling from does not have a (reliable) way of getting the context's locale. -
convertMessageLenient
Verifies the message is valid JSON in case it's plaintext. Works around GsonComponentSerializer not using lenient mode. See here for messages sent in lenient mode, and for a description on leniency.- Parameters:
message- Potentially lenient JSON messagelocale- Locale to use for translation strings- Returns:
- Bedrock formatted message
-
convertMessageLenient
-
convertToJavaMessage
Convert a Bedrock message string back to a format Java can understand- Parameters:
message- Message to convert- Returns:
- The formatted JSON string
-
convertToPlainText
Convert a Java message to plain text- Parameters:
message- Message to convertlocale- Locale to use for translation strings- Returns:
- The plain text of the message
-
convertToPlainText
Convert legacy format message to plain text- Parameters:
message- Message to convert- Returns:
- The plain text of the message
-
convertToPlainTextLenient
Convert JSON and legacy format message to plain text- Parameters:
message- Message to convertlocale- Locale to use for translation strings- Returns:
- The plain text of the message
-
handleChatPacket
public static void handleChatPacket(GeyserSession session, net.kyori.adventure.text.Component message, org.geysermc.mcprotocollib.protocol.data.game.Holder<org.geysermc.mcprotocollib.protocol.data.game.chat.ChatType> chatTypeHolder, net.kyori.adventure.text.Component targetName, net.kyori.adventure.text.Component sender, @Nullable UUID senderUuid) -
isTooLong
Checks if the given message is over 256 characters (Java edition server chat limit) and sends a message to the user if it is- Parameters:
message- Message to checksession-GeyserSessionfor the user- Returns:
- True if the message is too long, false if not
-
normalizeSpace
Normalizes whitespaces - a thing a vanilla client apparently does with commands and chat messages. -
deserializeDescription
Deserialize an NbtMap with a description text component (usually provided from a registry) into a Bedrock-formatted string. -
deserializeDescriptionForTooltip
public static String deserializeDescriptionForTooltip(GeyserSession session, org.cloudburstmc.nbt.NbtMap tag) Deserialize an NbtMap with a description text component (usually provided from a registry) into a Bedrock-formatted string. -
convertFromNullableNbtTag
public static @Nullable String convertFromNullableNbtTag(GeyserSession session, @Nullable Object nbtTag) -
componentFromNbtTag
-
signTextFromNbtTag
-
getStyleFromNbtMap
public static net.kyori.adventure.text.format.Style getStyleFromNbtMap(org.cloudburstmc.nbt.NbtMap map) -
getStyleFromNbtMap
public static net.kyori.adventure.text.format.Style getStyleFromNbtMap(org.cloudburstmc.nbt.NbtMap map, net.kyori.adventure.text.format.Style base) -
init
public static void init()
-