Package de.themoep.minedown
Class Util
java.lang.Object
de.themoep.minedown.Util
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.md_5.bungee.api.chat.BaseComponent
applyFormat
(net.md_5.bungee.api.chat.BaseComponent component, Collection<net.md_5.bungee.api.ChatColor> formats) Apply a collection of colors/formats to a componentstatic net.md_5.bungee.api.chat.ComponentBuilder
applyFormat
(net.md_5.bungee.api.chat.ComponentBuilder builder, Map<net.md_5.bungee.api.ChatColor, Boolean> formats) Apply a collection of colors/formats to a component builderstatic net.md_5.bungee.api.chat.ComponentBuilder
applyFormat
(net.md_5.bungee.api.chat.ComponentBuilder builder, Set<net.md_5.bungee.api.ChatColor> formats) Deprecated.static List<net.md_5.bungee.api.ChatColor>
createGradient
(int length, List<net.md_5.bungee.api.ChatColor> gradient, boolean rgb) Deprecated.static List<net.md_5.bungee.api.ChatColor>
createGradient
(long length, List<net.md_5.bungee.api.ChatColor> gradient, boolean rgb) Generate a gradient with certain colorsstatic List<net.md_5.bungee.api.ChatColor>
createRainbow
(int length, int phase, boolean rgb) Deprecated.static List<net.md_5.bungee.api.ChatColor>
createRainbow
(long length, int phase, boolean rgb) Generate a rainbow with a certain length and phasestatic double
Get the distance between two colorsstatic net.md_5.bungee.api.ChatColor
getClosestLegacy
(Color color) Get the legacy color closest to a certain RGB colorstatic Set<net.md_5.bungee.api.ChatColor>
getFormats
(net.md_5.bungee.api.chat.BaseComponent component, boolean ignoreParent) Get a set of ChatColor formats all formats that a component includesstatic Method
Get a method from a class if it exists.static int
getUnescapedEndIndex
(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 boolean
Check if a certain class exists.static boolean
Check if a class has a certain method.static int
indexOfNotEscaped
(String string, String chars) Get the index of the first occurrences of a not escaped characterstatic int
indexOfNotEscaped
(String string, String chars, int fromIndex) Get the index of the first occurrences of a not escaped characterstatic boolean
Check whether or not a character at a certain index of a string repeats itselfstatic boolean
Check if a character at a certain index is escapedstatic boolean
isFormat
(net.md_5.bungee.api.ChatColor format) Check whether a certain ChatColor is formatting or notstatic net.md_5.bungee.api.chat.BaseComponent[]
rgbColorsToLegacy
(net.md_5.bungee.api.chat.BaseComponent[] components) Utility method to remove RGB colors from components.static void
Utility method to throw an IllegalArgumentException if the value is falsestatic String
Wrap 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.md_5.bungee.api.chat.BaseComponent applyFormat(net.md_5.bungee.api.chat.BaseComponent component, Collection<net.md_5.bungee.api.ChatColor> formats) Apply a collection of colors/formats to a component- Parameters:
component
- The BaseComponentformats
- The collection of ChatColor formats to apply- Returns:
- The component that was modified
-
applyFormat
@Deprecated public static net.md_5.bungee.api.chat.ComponentBuilder applyFormat(net.md_5.bungee.api.chat.ComponentBuilder builder, Set<net.md_5.bungee.api.ChatColor> formats) Deprecated.Apply a collection of colors/formats to a component builder- Parameters:
builder
- The ComponentBuilderformats
- The collection of ChatColor formats to apply- Returns:
- The component builder that was modified
-
applyFormat
public static net.md_5.bungee.api.chat.ComponentBuilder applyFormat(net.md_5.bungee.api.chat.ComponentBuilder builder, Map<net.md_5.bungee.api.ChatColor, Boolean> formats) Apply a collection of colors/formats to a component builder- Parameters:
builder
- The ComponentBuilderformats
- The collection of ChatColor 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.md_5.bungee.api.ChatColor format) Check whether a certain ChatColor is formatting or not- Parameters:
format
- The ChatColor to check- Returns:
true
if it's a format,false
if it's a color
-
getFormats
public static Set<net.md_5.bungee.api.ChatColor> getFormats(net.md_5.bungee.api.chat.BaseComponent component, boolean ignoreParent) Get a set of ChatColor 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- Returns:
- A set of all the format ChatColors 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
-1
if 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 theindex
argument 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
-1
if 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.md_5.bungee.api.chat.BaseComponent[] rgbColorsToLegacy(net.md_5.bungee.api.chat.BaseComponent[] 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
Get the legacy color closest to a certain RGB color- Parameters:
color
- The color to get the closest legacy color for- Returns:
- The closest legacy color
-
distance
Get the distance between two colors- Parameters:
c1
- Color Ac2
- Color B- Returns:
- The distance or 0 if they are equal
-
createRainbow
@Deprecated public static List<net.md_5.bungee.api.ChatColor> createRainbow(int length, int phase, boolean rgb) Deprecated.Generate a rainbow with a certain length and phase- Parameters:
length
- The length of the rainbowphase
- The phase of the rainbow.rgb
- Whether or not to use RGB colors- Returns:
- the colors in the rainbow
-
createRainbow
public static List<net.md_5.bungee.api.ChatColor> createRainbow(long length, int phase, boolean rgb) Generate a rainbow with a certain length and phase- Parameters:
length
- The length of the rainbowphase
- The phase of the rainbow.rgb
- Whether or not to use RGB colors- Returns:
- the colors in the rainbow
-
createGradient
@Deprecated public static List<net.md_5.bungee.api.ChatColor> createGradient(int length, List<net.md_5.bungee.api.ChatColor> gradient, boolean rgb) Deprecated.Generate a gradient with certain colors- Parameters:
length
- The length of the gradientgradient
- The colors of the gradient.rgb
- Whether or not to use RGB colors- Returns:
- the colors in the gradient
-
createGradient
public static List<net.md_5.bungee.api.ChatColor> createGradient(long length, List<net.md_5.bungee.api.ChatColor> gradient, boolean rgb) Generate a gradient with certain colors- Parameters:
length
- The length of the gradientgradient
- The colors of the gradient.rgb
- Whether or not to use RGB colors- Returns:
- the colors in the gradient
-
hasClass
Check if a certain class exists. SeeClass.forName(String)
- Parameters:
className
- The class name to check- Returns:
true
if the class exists,false
if not
-
hasMethod
Check if a class has a certain method. SeeClass.getMethod(String, Class[])
- Parameters:
clazz
- The class to checkmethod
- The method to check forparameter
- Method parameter types- Returns:
true
if the class has the method,false
if not
-
getMethod
Get a method from a class if it exists. SeeClass.getMethod(String, Class[])
- Parameters:
clazz
- The classmethod
- The method name to getparameter
- Method parameter types- Returns:
- the method, null if it doesn't exist
-
applyFormat(BaseComponent, Collection)