Class Text
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSeparation line for players (in-game chat).static final StringSeparation line for console.static final PatternPattern to match our HEX color format for MC 1.16+.static final PatternPattern to match our localized placeholders.static final net.kyori.adventure.text.minimessage.MiniMessage -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidBroadcasts the message after coloring and formatting it.static voidbroadcastRaw(@Nullable String permission, @Nullable String str) Broadcasts a colorized message without the prefix.static @NotNull StringcapitalizeFirst(@NotNull String str) Makes the first character uppercase and the rest lowercase.static voidclearTitle(@NotNull org.bukkit.entity.Player player) Clears the current title and subtitle of the player.static @NotNull StringConverts plain string with color codes into a colorized message.Colorizes a list of plain strings.static voidSends a formatted console message.static voidconsoleRaw(@Nullable String str) Sends a colorized console message without the prefix.static @NotNull StringAppends the prefix, a red chat color, and the message, and then colorizes.static @NotNull StringAppends the prefix, and then colorizes.static @NotNull LocalegetLocale(@Nullable org.bukkit.command.CommandSender sender) Gets the locale for the specified console or player.static @NotNull StringConvenience method to get the current prefix of the plugin.static @NotNull StringlegacyParseMini(@Nullable String str) Parses the string using the MiniMessage library, and then uses the legacy Bukkit Component Serializer to return a String rather than a Component.static @NotNull StringlegacySerialize(@NotNull net.kyori.adventure.text.Component component) Serializes an AdventureComponentusing the legacy Bukkit Component Serializer, which can be useful for displaying components in areas other than the chat (ex.static @NotNull Stringline(@NotNull org.bukkit.command.CommandSender sender) static @NotNull StringGets the localized string with the given key using the provided locale.static @NotNull Stringlocalized(@Nullable String key, @Nullable org.bukkit.command.CommandSender sender, @NotNull Object... args) Gets the localized string with the given key using the provided sender's locale.static @NotNull StringlocalizedDef(@Nullable String key, @NotNull Object... args) Gets the localized string with the given key using the default locale.static @NotNull StringlocalizedOrDefault(@Nullable org.bukkit.command.CommandSender sender, @Nullable String key, @NotNull String defaultMessage, @NotNull Object... args) Gets a localized error message with fallback to a default message.static @NotNull StringlocalizePlaceholders(@Nullable String str, @Nullable Locale locale, @NotNull Object... args) Localizes the placeholders in the string using the sender's locale.static @NotNull StringlocalizePlaceholders(@Nullable String str, @Nullable org.bukkit.command.CommandSender sender, @NotNull Object... args) static @NotNull StringlocalizePlaceholdersDef(@Nullable String str, @NotNull Object... args) Localizes the placeholders in the string using the default locale.static voidLogs a plain message into the console.static voidLogs a plain message into the console.static @NotNull net.kyori.adventure.text.ComponentParses the string using the MiniMessage library.static voidsendTitle(@NotNull org.bukkit.entity.Player player, @Nullable String title, @Nullable String subtitle) Sends the title to the player.static voidsendTitle(@NotNull org.bukkit.entity.Player player, @Nullable String title, @Nullable String subtitle, int fadeIn, int stay, int fadeOut) Sends the title to the player.splitLines(@Nullable String str) Creates a list of lines from a string line-broken with \n.static @NotNull StringFully strip all color from the string.Fully strip all color from strings.static voidSends a colored and prefixed message to the command sender.static voidtellCentered(@NotNull org.bukkit.entity.Player player, @Nullable String str) Sends a colored and centered message.static voidtellComponent(@NotNull org.bukkit.entity.Player player, @NotNull net.kyori.adventure.text.Component component) Sends theComponentto the player as a chat message.static voidtellLocalized(@NotNull org.bukkit.command.CommandSender sender, @Nullable String key, Object... args) Sends alocalized(String, CommandSender, Object...), colored, and prefixed message to the command sender.static voidtellLocalizedRaw(@NotNull org.bukkit.command.CommandSender sender, @Nullable String key, Object... args) Sends a localized, colorized message without the prefix.static voidSends a colorized message without the prefix.static @NotNull StringMakes a string Title Case.static @NotNull StringShorthand forlocalized(String, Locale, Object...).static @NotNull Stringtl(@Nullable String key, @Nullable org.bukkit.command.CommandSender sender, @NotNull Object... args) Shorthand forlocalized(String, CommandSender, Object...).
-
Field Details
-
HEX_PATTERN
Pattern to match our HEX color format for MC 1.16+. -
LOCALIZED_PLACEHOLDER_PATTERN
Pattern to match our localized placeholders. -
CHAT_LINE
Separation line for players (in-game chat).- See Also:
-
CONSOLE_LINE
Separation line for console.- See Also:
-
MINI_MESSAGE
public static final net.kyori.adventure.text.minimessage.MiniMessage MINI_MESSAGE
-
-
Constructor Details
-
Text
public Text()
-
-
Method Details
-
getLocale
@NotNull public static @NotNull Locale getLocale(@Nullable @Nullable org.bukkit.command.CommandSender sender) Gets the locale for the specified console or player. If the player's locale cannot be resolved, the sender is a console, or the sender is null, the default locale is returned.- Parameters:
sender- The sender to get the locale of- Returns:
- The sender's locale or the default locale if the sender's locale could not be resolved
-
localized
@NotNull public static @NotNull String localized(@Nullable @Nullable String key, @Nullable @Nullable org.bukkit.command.CommandSender sender, @NotNull @NotNull Object... args) Gets the localized string with the given key using the provided sender's locale. Uses the default locale if the localized string could not be resolved with the provided sender's locale.Uses
MessageFormatinternally for argument substitution. Single quotes in translation values must be doubled ('') to appear literally, and curly braces used as literal text (not placeholders) must be quoted:'{literal}'.- Parameters:
key- The key of the messagesender- The sender to get the locale ofargs- Arguments for positioned placeholders ({n})- Returns:
- The localized message, or key if unable to resolve
- See Also:
-
localized
@NotNull public static @NotNull String localized(@Nullable @Nullable String key, @Nullable @Nullable Locale locale, @NotNull @NotNull Object... args) Gets the localized string with the given key using the provided locale. Uses the default locale if the localized string could not be resolved with the provided locale.Uses
MessageFormatinternally for argument substitution. Single quotes in translation values must be doubled ('') to appear literally, and curly braces used as literal text (not placeholders) must be quoted:'{literal}'.- Parameters:
key- The key of the messagelocale- The localeargs- Arguments for positioned placeholders ({n})- Returns:
- The localized message, or key if unable to resolve
-
localizedDef
@NotNull public static @NotNull String localizedDef(@Nullable @Nullable String key, @NotNull @NotNull Object... args) Gets the localized string with the given key using the default locale.Uses
MessageFormatinternally for argument substitution. Single quotes in translation values must be doubled ('') to appear literally.- Parameters:
key- The key of the messageargs- Arguments for positioned placeholders ({n})- Returns:
- The localized message, or key if unable to resolve
-
localizedOrDefault
@NotNull public static @NotNull String localizedOrDefault(@Nullable @Nullable org.bukkit.command.CommandSender sender, @Nullable @Nullable String key, @NotNull @NotNull String defaultMessage, @NotNull @NotNull Object... args) Gets a localized error message with fallback to a default message. If the localization key cannot be resolved (returns the key itself), the default message is used instead.- Parameters:
sender- The command sender to get the locale ofkey- The localization keydefaultMessage- The default message if localization is not availableargs- Arguments for placeholders in the localized message- Returns:
- The localized or default message (not colorized)
-
tl
@NotNull public static @NotNull String tl(@Nullable @Nullable String key, @Nullable @Nullable org.bukkit.command.CommandSender sender, @NotNull @NotNull Object... args) Shorthand forlocalized(String, CommandSender, Object...). -
tl
@NotNull public static @NotNull String tl(@Nullable @Nullable String key, @Nullable @Nullable Locale locale, @NotNull @NotNull Object... args) Shorthand forlocalized(String, Locale, Object...).- See Also:
-
localizePlaceholders
@NotNull public static @NotNull String localizePlaceholders(@Nullable @Nullable String str, @Nullable @Nullable Locale locale, @NotNull @NotNull Object... args) Localizes the placeholders in the string using the sender's locale. Note that the same arguments are used for EVERY placeholder.Each resolved placeholder is processed through
MessageFormat. Single quotes in translation values must be doubled ('') to appear literally.- Parameters:
str- The string to localizelocale- The locale to useargs- The arguments to replace in the localized string- Returns:
- The localized string
-
localizePlaceholders
-
localizePlaceholdersDef
@NotNull public static @NotNull String localizePlaceholdersDef(@Nullable @Nullable String str, @NotNull @NotNull Object... args) Localizes the placeholders in the string using the default locale. Note that the same arguments are used for EVERY placeholder.- Parameters:
str- The string to localizeargs- The arguments to replace in the localized string- Returns:
- The localized string
-
getPrefix
Convenience method to get the current prefix of the plugin.- Returns:
- The prefix
-
line
@NotNull public static @NotNull String line(@NotNull @NotNull org.bukkit.command.CommandSender sender) - Parameters:
sender- The command sender- Returns:
- The separation line
-
colorize
Converts plain string with color codes into a colorized message. Supports HEX colors in the format of<#HEX>. 1.16+ HEX support requires the server software to be Spigot, or a fork of Spigot.- Parameters:
str- The plain string- Returns:
- Colorized string, or empty if the provided string is null
-
colorize
Colorizes a list of plain strings.- Parameters:
strList- The plain strings- Returns:
- Colorized strings, or an empty collection if the provided list is null
- See Also:
-
format
Appends the prefix, and then colorizes.- Parameters:
str- The plain, non-prefixed string- Returns:
- Formatted string, or empty if the provided string is null
-
error
Appends the prefix, a red chat color, and the message, and then colorizes.- Parameters:
str- The plain string- Returns:
- Formatted string with red message
-
parseMini
@NotNull public static @NotNull net.kyori.adventure.text.Component parseMini(@Nullable @Nullable String str) Parses the string using the MiniMessage library. Format: ...- Parameters:
str- The raw string- Returns:
- The result component for the string, or empty if the provided string is null
-
legacyParseMini
Parses the string using the MiniMessage library, and then uses the legacy Bukkit Component Serializer to return a String rather than a Component. Format: ...- Parameters:
str- The raw string(s)- Returns:
- The serialized component for the string, or empty if the provided string is null
-
legacySerialize
@NotNull public static @NotNull String legacySerialize(@NotNull @NotNull net.kyori.adventure.text.Component component) Serializes an AdventureComponentusing the legacy Bukkit Component Serializer, which can be useful for displaying components in areas other than the chat (ex. item names).- Parameters:
component- The component to serialize- Returns:
- The serialized component
- See Also:
-
strip
Fully strip all color from the string.- Parameters:
str- The string to strip- Returns:
- The stripped string, or an empty string if the provided one is null
-
strip
Fully strip all color from strings.- Parameters:
strList- The list of string to strip- Returns:
- The stripped string list, or an empty list if the provided one is null
- See Also:
-
capitalizeFirst
Makes the first character uppercase and the rest lowercase.- Parameters:
str- The string- Returns:
- The string with the first letter in upper case and the rest in lower case
-
titleCase
@NotNull public static @NotNull String titleCase(@NotNull @NotNull String str, @NotNull @NotNull String delimiter) Makes a string Title Case.- Parameters:
str- The stringdelimiter- The delimiter to use for splitting the string- Returns:
- The string in Title Case
-
splitLines
Creates a list of lines from a string line-broken with \n.- Parameters:
str- The string to split- Returns:
- The list of lines
-
console
Sends a formatted console message. Any message equaling null orIGNORE_MESSAGE_VALUE(ignore case) will be ignored.- Parameters:
str- The message to send
-
consoleRaw
Sends a colorized console message without the prefix. Any message equaling null orIGNORE_MESSAGE_VALUE(ignore case) will be ignored.- Parameters:
str- The message to send
-
log
Logs a plain message into the console.- Parameters:
str- The message to send
-
log
Logs a plain message into the console.- Parameters:
str- The message to sendlevel- The logging level
-
tell
public static void tell(@NotNull @NotNull org.bukkit.command.CommandSender sender, @Nullable @Nullable String str) Sends a colored and prefixed message to the command sender. Any message equaling null orIGNORE_MESSAGE_VALUE(ignore case) will be ignored.- Parameters:
sender- The command sender that will receive the messagestr- The message to send
-
tellLocalized
public static void tellLocalized(@NotNull @NotNull org.bukkit.command.CommandSender sender, @Nullable @Nullable String key, Object... args) Sends alocalized(String, CommandSender, Object...), colored, and prefixed message to the command sender. Any key equaling null or any message equaling toIGNORE_MESSAGE_VALUE(ignore case) will be ignored.Uses
MessageFormatinternally for argument substitution. Single quotes in translation values must be doubled ('') to appear literally.- Parameters:
sender- The command sender that will receive the messagekey- The key of the localized stringargs- Arguments to replace in the localized string- See Also:
-
tellRaw
public static void tellRaw(@NotNull @NotNull org.bukkit.command.CommandSender sender, @Nullable @Nullable String str) Sends a colorized message without the prefix. Any message equaling null orIGNORE_MESSAGE_VALUE(ignore case) will be ignored.- Parameters:
sender- The command sender that will receive the messagestr- The message to send- See Also:
-
tellLocalizedRaw
public static void tellLocalizedRaw(@NotNull @NotNull org.bukkit.command.CommandSender sender, @Nullable @Nullable String key, Object... args) Sends a localized, colorized message without the prefix. Any key equaling null or any message equaling toIGNORE_MESSAGE_VALUE(ignore case) will be ignored.Uses
MessageFormatinternally for argument substitution. Single quotes in translation values must be doubled ('') to appear literally.- Parameters:
sender- The command sender that will receive the messagekey- The key of the localized stringargs- Arguments to replace in the localized string- See Also:
-
tellComponent
public static void tellComponent(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @NotNull net.kyori.adventure.text.Component component) Sends theComponentto the player as a chat message.- Parameters:
player- The player who should receive the componentcomponent- The component to send- See Also:
-
tellCentered
public static void tellCentered(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable String str) Sends a colored and centered message. May not work if the player has changed their chat size, used a custom font (resource pack), or if the message contains HEX colors. Any message equaling null or IGNORE_MESSAGE_VALUE (ignore case) will be ignored.- Parameters:
player- The player that will receive the messagestr- The message to send
-
broadcast
Broadcasts the message after coloring and formatting it. Any message equaling null orIGNORE_MESSAGE_VALUE(ignore case) will be ignored.- Parameters:
permission- The permission players must have in order to see this broadcast, or null if the broadcast should be seen by everyonestr- The message to send
-
broadcastRaw
public static void broadcastRaw(@Nullable @Nullable String permission, @Nullable @Nullable String str) Broadcasts a colorized message without the prefix. Any message equaling null orIGNORE_MESSAGE_VALUE(ignore case) will be ignored.- Parameters:
permission- The permission players must have in order to see this broadcast, or null if the broadcast should be seen by everyonestr- The message to send- See Also:
-
sendTitle
public static void sendTitle(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable String title, @Nullable @Nullable String subtitle) Sends the title to the player.- Parameters:
player- The player who should receive the titletitle- The title to send, or null for nonesubtitle- The subtitle to send, or null for none
-
sendTitle
public static void sendTitle(@NotNull @NotNull org.bukkit.entity.Player player, @Nullable @Nullable String title, @Nullable @Nullable String subtitle, int fadeIn, int stay, int fadeOut) Sends the title to the player.- Parameters:
player- The player who should receive the titletitle- The title to send, or null for nonesubtitle- The subtitle to send, or null for nonefadeIn- The fade in duration, in ticksstay- The stay duration, in ticksfadeOut- The fade out duration, in ticks
-
clearTitle
public static void clearTitle(@NotNull @NotNull org.bukkit.entity.Player player) Clears the current title and subtitle of the player.- Parameters:
player- The player who should have their title and subtitle cleared
-