Class MessageTranslator
java.lang.Object
org.geysermc.geyser.translator.text.MessageTranslator
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
convertMessage(String message)
static String
convertMessage(String message, String locale)
static String
convertMessage(net.kyori.adventure.text.Component message)
static String
convertMessage(net.kyori.adventure.text.Component message, String locale)
Convert a Java message to the legacy format ready for bedrockstatic String
convertMessageLenient(String message)
static String
convertMessageLenient(String message, String locale)
Verifies the message is valid JSON in case it's plaintext.static String
convertToJavaMessage(String message)
Convert a Bedrock message string back to a format Java can understandstatic String
convertToPlainText(String message, String locale)
Convert JSON and legacy format message to plain textstatic void
init()
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 isstatic String
toChatColor(com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor teamColor)
Convert a team color to a chat color
-
Constructor Details
-
MessageTranslator
public MessageTranslator()
-
-
Method Details
-
convertMessage
Convert a Java message to the legacy format ready for bedrock- Parameters:
message
- Java messagelocale
- Locale to use for translation strings- Returns:
- Parsed and formatted message for bedrock
-
convertMessage
-
convertMessage
-
convertMessage
-
convertMessageLenient
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.- 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 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
-
toChatColor
public static String toChatColor(com.github.steveice10.mc.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
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
-GeyserSession
for the user- Returns:
- True if the message is too long, false if not
-
init
public static void init()
-