Package de.themoep.minedown.adventure
Class Util
java.lang.Object
de.themoep.minedown.adventure.Util
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.kyori.adventure.text.ComponentBuilderapplyFormat(net.kyori.adventure.text.ComponentBuilder builder, Collection<net.kyori.adventure.text.format.TextDecoration> formats) Deprecated.static net.kyori.adventure.text.ComponentBuilderapplyFormat(net.kyori.adventure.text.ComponentBuilder builder, Map<net.kyori.adventure.text.format.TextDecoration, Boolean> formats) Apply a collection of colors/formats to a component builderstatic net.kyori.adventure.text.ComponentapplyFormat(net.kyori.adventure.text.Component component, Collection<net.kyori.adventure.text.format.TextDecoration> formats) Apply a collection of colors/formats to a componentstatic List<net.kyori.adventure.text.format.TextColor> createGradient(int length, List<net.kyori.adventure.text.format.TextColor> gradient) Deprecated.static List<net.kyori.adventure.text.format.TextColor> createGradient(long length, List<net.kyori.adventure.text.format.TextColor> gradient) Generate a gradient with certain colorsstatic List<net.kyori.adventure.text.format.TextColor> createRainbow(int length, int phase) Deprecated.static List<net.kyori.adventure.text.format.TextColor> createRainbow(long length, int phase) Generate a rainbow with a certain length and phasestatic doubleDeprecated.Doesn't use perceived brightness (HSV) but simply takes the distance between RGB.static net.kyori.adventure.text.format.NamedTextColorgetClosestLegacy(net.kyori.adventure.text.format.TextColor textColor) Deprecated.UseNamedTextColor.nearestTo(TextColor)static net.kyori.adventure.text.format.TextFormatgetFormatFromLegacy(char code) Get a TextFormat from its legacy color code as kyori-text-api does not support thatstatic net.kyori.adventure.text.format.TextFormatgetFormatFromString(String formatString) Get the text format from a string, either its name or hex codestatic Set<net.kyori.adventure.text.format.TextDecoration> getFormats(net.kyori.adventure.text.Component component, boolean ignoreParent) Get a set of TextColor formats all formats that a component includesstatic chargetLegacyFormatChar(net.kyori.adventure.text.format.TextFormat format) Get the legacy color code from its format as kyori-text-api does not support thatstatic intgetUnescapedEndIndex(String string, char startChar, char endChar, int fromIndex) Gets the proper end index of a certain definition on the same depth while ignoring escaped chars.static intindexOfNotEscaped(String string, String chars) Get the index of the first occurrences of a not escaped characterstatic intindexOfNotEscaped(String string, String chars, int fromIndex) Get the index of the first occurrences of a not escaped characterstatic booleanCheck whether or not a character at a certain index of a string repeats itselfstatic booleanCheck if a character at a certain index is escapedstatic booleanisFormat(net.kyori.adventure.text.format.TextColor format) Check whether a certain TextColor is formatting or notstatic net.kyori.adventure.text.ComponentrgbColorsToLegacy(net.kyori.adventure.text.Component components) Utility method to remove RGB colors from components.static voidUtility method to throw an IllegalArgumentException if the value is falsestatic StringWrap a string if it is longer than the line length and contains no new line.
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
validate
Utility method to throw an IllegalArgumentException if the value is false- Parameters:
value- The value to validatemessage- The message for the exception- Throws:
IllegalArgumentException- Thrown if the value is false
-
applyFormat
public static net.kyori.adventure.text.Component applyFormat(net.kyori.adventure.text.Component component, Collection<net.kyori.adventure.text.format.TextDecoration> formats) Apply a collection of colors/formats to a component- Parameters:
component- The BaseComponentformats- The collection of TextColor formats to apply- Returns:
- The component that was modified
-
applyFormat
@Deprecated public static net.kyori.adventure.text.ComponentBuilder applyFormat(net.kyori.adventure.text.ComponentBuilder builder, Collection<net.kyori.adventure.text.format.TextDecoration> formats) Deprecated.Apply a collection of colors/formats to a component builder- Parameters:
builder- The ComponentBuilderformats- The collection of TextColor formats to apply- Returns:
- The component builder that was modified
-
applyFormat
public static net.kyori.adventure.text.ComponentBuilder applyFormat(net.kyori.adventure.text.ComponentBuilder builder, Map<net.kyori.adventure.text.format.TextDecoration, Boolean> formats) Apply a collection of colors/formats to a component builder- Parameters:
builder- The ComponentBuilderformats- The collection of TextColor formats to apply- Returns:
- The component builder that was modified
-
isDouble
Check whether or not a character at a certain index of a string repeats itself- Parameters:
string- The string to checkindex- The index at which to check the character- Returns:
- Whether or not the character at that index repeated itself
-
isFormat
public static boolean isFormat(net.kyori.adventure.text.format.TextColor format) Check whether a certain TextColor is formatting or not- Parameters:
format- The TextColor to check- Returns:
trueif it's a format,falseif it's a color
-
getFormats
public static Set<net.kyori.adventure.text.format.TextDecoration> getFormats(net.kyori.adventure.text.Component component, boolean ignoreParent) Get a set of TextColor formats all formats that a component includes- Parameters:
component- The component to get the formats fromignoreParent- Whether or not to include the parent's format (TODO: Does kyori-text not handle this?)- Returns:
- A set of all the format TextColors that the component includes
-
indexOfNotEscaped
Get the index of the first occurrences of a not escaped character- Parameters:
string- The string to searchchars- The characters to search for- Returns:
- The first unescaped index or -1 if not found
-
indexOfNotEscaped
Get the index of the first occurrences of a not escaped character- Parameters:
string- The string to searchchars- The characters to search forfromIndex- Start searching from that index- Returns:
- The first unescaped index or
-1if not found
-
isEscaped
Check if a character at a certain index is escaped- Parameters:
string- The string to checkindex- The index of the character in the string to check- Returns:
- Whether or not the character is escaped (uneven number of backslashes in front of char mains it is escaped)
- Throws:
IndexOutOfBoundsException- if theindexargument is not less than the length of this string.
-
getUnescapedEndIndex
Gets the proper end index of a certain definition on the same depth while ignoring escaped chars.- Parameters:
string- The string to searchstartChar- The start cahracter of the definitionendChar- The end character of the definitionfromIndex- The index to start searching from (should be at the start char)- Returns:
- The first end index of that group or
-1if not found
-
wrap
Wrap a string if it is longer than the line length and contains no new line. Will try to wrap at spaces between words.- Parameters:
string- The string to wraplineLength- The max length of a line- Returns:
- The wrapped string
-
rgbColorsToLegacy
public static net.kyori.adventure.text.Component rgbColorsToLegacy(net.kyori.adventure.text.Component components) Utility method to remove RGB colors from components. This modifies the input array!- Parameters:
components- The components to remove the rgb colors from- Returns:
- The modified components (same as input).
-
getClosestLegacy
@Deprecated public static net.kyori.adventure.text.format.NamedTextColor getClosestLegacy(net.kyori.adventure.text.format.TextColor textColor) Deprecated.UseNamedTextColor.nearestTo(TextColor)Get the legacy color closest to a certain RGB color- Parameters:
textColor- The color to get the closest legacy color for- Returns:
- The closest legacy color
-
distance
Deprecated.Doesn't use perceived brightness (HSV) but simply takes the distance between RGB. Do not rely on this, I twill look ugly!Get the distance between two colors- Parameters:
c1- Color Ac2- Color B- Returns:
- The distance or 0 if they are equal
-
getFormatFromString
public static net.kyori.adventure.text.format.TextFormat getFormatFromString(String formatString) throws IllegalArgumentException Get the text format from a string, either its name or hex code- Parameters:
formatString- The string to get the format from- Returns:
- The TextFormat
- Throws:
IllegalArgumentException- if the format could not be found from the string
-
getFormatFromLegacy
public static net.kyori.adventure.text.format.TextFormat getFormatFromLegacy(char code) Get a TextFormat from its legacy color code as kyori-text-api does not support that- Parameters:
code- The legacy char- Returns:
- The TextFormat or null if none found with that char
-
getLegacyFormatChar
public static char getLegacyFormatChar(net.kyori.adventure.text.format.TextFormat format) Get the legacy color code from its format as kyori-text-api does not support that- Parameters:
format- The format- Returns:
- The legacy color code or null if none found with that char
-
createRainbow
@Deprecated public static List<net.kyori.adventure.text.format.TextColor> createRainbow(int length, int phase) Deprecated.Generate a rainbow with a certain length and phase- Parameters:
length- The length of the rainbowphase- The phase of the rainbow.- Returns:
- the colors in the rainbow
-
createRainbow
Generate a rainbow with a certain length and phase- Parameters:
length- The length of the rainbowphase- The phase of the rainbow.- Returns:
- the colors in the rainbow
-
createGradient
@Deprecated public static List<net.kyori.adventure.text.format.TextColor> createGradient(int length, List<net.kyori.adventure.text.format.TextColor> gradient) Deprecated.Generate a gradient with certain colors- Parameters:
length- The length of the gradientgradient- The colors of the gradient.- Returns:
- the colors in the gradient
-
createGradient
public static List<net.kyori.adventure.text.format.TextColor> createGradient(long length, List<net.kyori.adventure.text.format.TextColor> gradient) Generate a gradient with certain colors- Parameters:
length- The length of the gradientgradient- The colors of the gradient.- Returns:
- the colors in the gradient
-
applyFormat(ComponentBuilder, Map)