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.BaseComponentapplyFormat(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.ComponentBuilderapplyFormat(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.ComponentBuilderapplyFormat(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 doubleGet the distance between two colorsstatic net.md_5.bungee.api.ChatColorgetClosestLegacy(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 MethodGet a method from a class if it exists.static 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 booleanCheck if a certain class exists.static booleanCheck if a class has a certain method.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.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 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.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:
trueif it's a format,falseif 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
-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.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:
trueif the class exists,falseif 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:
trueif the class has the method,falseif 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)