public class TextUtils
extends java.lang.Object
| Constructor and Description |
|---|
TextUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
iterateAll(TextComponent component,
java.util.function.Consumer<TextComponent> consumer)
Iterate over all siblings of the given component.
This includes all arguments of translation components. |
static TextComponent |
join(TextComponent separator,
TextComponent... components)
Join the given components with the given separator.
All components are copied before they are joined. If there are no components an empty StringComponent will be returned.If there is only one component it will be copied and returned. |
static TextComponent |
makeURLsClickable(TextComponent component)
Make URLs in the given text component clickable.
The lenient parser is used by default, be aware that this can cause exceptions if the URL is not a valid URI. |
static TextComponent |
makeURLsClickable(TextComponent component,
boolean lenient)
Make URLs in the given text component clickable.
|
static TextComponent |
replace(TextComponent component,
java.util.function.Function<TextComponent,TextComponent> replaceFunction)
Replace components in the given component and all siblings with the given function.
This includes all arguments of translation components. |
static TextComponent |
replace(TextComponent component,
java.lang.String searchRegex,
java.util.function.Function<TextComponent,TextComponent> replaceFunction)
Replace all matches of the given pattern in this component and all siblings.
This only works for StringComponent components. |
static TextComponent |
replaceRGBColors(TextComponent component)
Replace all rgb color codes with the nearest formatting color.
This can not perfectly convert the colors since there is only a limited amount of formatting colors. Minecraft 1.16 has added support for rgb colors which older versions can't display. |
static void |
setTranslator(TextComponent component,
Translator translator)
Recursively set the translator for all translation and keybind components in the given component.
This includes all arguments of translation components. |
static void |
setTranslator(TextComponent component,
Translator textTranslator,
Translator keyTranslator)
Recursively set the translators for all translation and keybind components in the given component.
This includes all arguments of translation components. |
static TextComponent[] |
split(TextComponent component,
java.lang.String split,
boolean resolveTranslations)
Split the given component by the given split string.
An array of components will be returned where each component is a part. This method behaves like string.split(split, -1) without regex.The original component will not be modified. |
public static TextComponent makeURLsClickable(TextComponent component)
makeURLsClickable(TextComponent, boolean) with lenient set to false to avoid potential exceptions.component - The component to make clickablepublic static TextComponent makeURLsClickable(TextComponent component, boolean lenient)
component - The component to make clickablelenient - If true, the URL will be used as is. Minecraft 1.21.5+ started parsing the URL as URI, the serializer can throw an exception if an invalid URI is entered.
If false, the URL will be parsed as a URI and ignored if it is invalid. This is the recommended option for Minecraft 1.21.5+.public static TextComponent replace(TextComponent component, java.util.function.Function<TextComponent,TextComponent> replaceFunction)
component - The component to replace inreplaceFunction - The function that will be called for every componentpublic static TextComponent replace(TextComponent component, java.lang.String searchRegex, java.util.function.Function<TextComponent,TextComponent> replaceFunction)
StringComponent components.component - The component to replace insearchRegex - The regex to search forreplaceFunction - The function that will be called for every matchpublic static TextComponent replaceRGBColors(TextComponent component)
component - The component to replace inpublic static TextComponent join(TextComponent separator, TextComponent... components)
StringComponent will be returned.separator - The separatorcomponents - The componentspublic static void iterateAll(TextComponent component, java.util.function.Consumer<TextComponent> consumer)
component - The component to iterate overconsumer - The consumer that will be called for every componentTextComponent.forEach(Consumer)public static void setTranslator(TextComponent component, @Nullable Translator translator)
component - The component to set the translator fortranslator - The translator functionpublic static void setTranslator(TextComponent component, @Nullable Translator textTranslator, @Nullable Translator keyTranslator)
component - The component to set the translators fortextTranslator - The translator function for text componentskeyTranslator - The translator function for keybind componentspublic static TextComponent[] split(TextComponent component, java.lang.String split, boolean resolveTranslations)
string.split(split, -1) without regex.component - The component to splitsplit - The split stringresolveTranslations - If translations should be resolved before splitting