Class MessageTranslator

java.lang.Object
org.geysermc.geyser.translator.text.MessageTranslator

public class MessageTranslator extends Object
  • Constructor Details

    • MessageTranslator

      public MessageTranslator()
  • Method Details

    • convertMessage

      public static String convertMessage(net.kyori.adventure.text.Component message, String locale)
      Convert a Java message to the legacy format ready for bedrock
      Parameters:
      message - Java message
      locale - Locale to use for translation strings
      Returns:
      Parsed and formatted message for bedrock
    • convertJsonMessage

      public static String convertJsonMessage(GeyserSession session, String message)
      Convenience method for locale getting.
    • convertJsonMessage

      public static String convertJsonMessage(String message, String locale)
    • convertMessage

      public static String convertMessage(GeyserSession session, net.kyori.adventure.text.Component message)
      Convenience method for locale getting.
    • convertMessage

      public static String convertMessage(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.
    • convertMessageLenient

      public static String convertMessageLenient(String message, String locale)
      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 message
      locale - Locale to use for translation strings
      Returns:
      Bedrock formatted message
    • convertMessageLenient

      public static String convertMessageLenient(String message)
    • convertToJavaMessage

      public static String convertToJavaMessage(String message)
      Convert a Bedrock message string back to a format Java can understand
      Parameters:
      message - Message to convert
      Returns:
      The formatted JSON string
    • convertToPlainText

      public static String convertToPlainText(net.kyori.adventure.text.Component message, String locale)
      Convert a Java message to plain text
      Parameters:
      message - Message to convert
      locale - Locale to use for translation strings
      Returns:
      The plain text of the message
    • convertToPlainText

      public static String convertToPlainText(String message)
      Convert legacy format message to plain text
      Parameters:
      message - Message to convert
      Returns:
      The plain text of the message
    • convertToPlainTextLenient

      public static String convertToPlainTextLenient(String message, String locale)
      Convert JSON and legacy format message to plain text
      Parameters:
      message - Message to convert
      locale - 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)
    • toChatColor

      public static String toChatColor(org.geysermc.mcprotocollib.protocol.data.game.scoreboard.TeamColor teamColor)
      Convert a team color to a chat color
      Parameters:
      teamColor - Color or format to convert
      Returns:
      The chat color character
    • isTooLong

      public static boolean isTooLong(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 is
      Parameters:
      message - Message to check
      session - GeyserSession for the user
      Returns:
      True if the message is too long, false if not
    • normalizeSpace

      public static String normalizeSpace(String string)
      Normalizes whitespaces - a thing a vanilla client apparently does with commands and chat messages.
    • deserializeDescription

      public static String deserializeDescription(org.cloudburstmc.nbt.NbtMap tag)
      Deserialize an NbtMap provided from a registry into a string.
    • init

      public static void init()