Class Util

java.lang.Object
de.themoep.minedown.Util

public class Util extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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
    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
    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)
    static List<net.md_5.bungee.api.ChatColor>
    createGradient​(int length, List<net.md_5.bungee.api.ChatColor> gradient, boolean rgb)
    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
    static List<net.md_5.bungee.api.ChatColor>
    createRainbow​(int length, int phase, boolean rgb)
    static List<net.md_5.bungee.api.ChatColor>
    createRainbow​(long length, int phase, boolean rgb)
    Generate a rainbow with a certain length and phase
    static double
    distance​(Color c1, Color c2)
    Get the distance between two colors
    static net.md_5.bungee.api.ChatColor
    Get the legacy color closest to a certain RGB color
    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
    static Method
    getMethod​(Class<?> clazz, String method, Class<?>... parameter)
    Get a method from a class if it exists.
    static boolean
    hasClass​(String className)
    Check if a certain class exists.
    static boolean
    hasMethod​(Class<?> clazz, String method, Class<?>... parameter)
    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 character
    static int
    indexOfNotEscaped​(String string, String chars, int fromIndex)
    Get the index of the first occurrences of a not escaped character
    static boolean
    isDouble​(String string, int index)
    Check whether or not a character at a certain index of a string repeats itself
    static boolean
    isEscaped​(String string, int index)
    Check if a character at a certain index is escaped
    static boolean
    isFormat​(net.md_5.bungee.api.ChatColor format)
    Check whether a certain ChatColor is formatting or not
    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.
    static void
    validate​(boolean value, String message)
    Utility method to throw an IllegalArgumentException if the value is false
    static String
    wrap​(String string, int lineLength)
    Wrap a string if it is longer than the line length and contains no new line.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • validate

      public static void validate(boolean value, String message) throws IllegalArgumentException
      Utility method to throw an IllegalArgumentException if the value is false
      Parameters:
      value - The value to validate
      message - 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 BaseComponent
      formats - 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)
      Apply a collection of colors/formats to a component builder
      Parameters:
      builder - The ComponentBuilder
      formats - 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 ComponentBuilder
      formats - The collection of ChatColor formats to apply
      Returns:
      The component builder that was modified
    • isDouble

      public static boolean isDouble(String string, int index)
      Check whether or not a character at a certain index of a string repeats itself
      Parameters:
      string - The string to check
      index - 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 from
      ignoreParent - Whether or not to include the parent's format
      Returns:
      A set of all the format ChatColors that the component includes
    • indexOfNotEscaped

      public static int indexOfNotEscaped(String string, String chars)
      Get the index of the first occurrences of a not escaped character
      Parameters:
      string - The string to search
      chars - The characters to search for
      Returns:
      The first unescaped index or -1 if not found
    • indexOfNotEscaped

      public static int indexOfNotEscaped(String string, String chars, int fromIndex)
      Get the index of the first occurrences of a not escaped character
      Parameters:
      string - The string to search
      chars - The characters to search for
      fromIndex - Start searching from that index
      Returns:
      The first unescaped index or -1 if not found
    • isEscaped

      public static boolean isEscaped(String string, int index)
      Check if a character at a certain index is escaped
      Parameters:
      string - The string to check
      index - 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 the index argument is not less than the length of this string.
    • wrap

      public static String wrap(String string, int lineLength)
      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 wrap
      lineLength - 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

      public static net.md_5.bungee.api.ChatColor getClosestLegacy(Color color)
      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

      public static double distance(Color c1, Color c2)
      Get the distance between two colors
      Parameters:
      c1 - Color A
      c2 - 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)
      Generate a rainbow with a certain length and phase
      Parameters:
      length - The length of the rainbow
      phase - 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 rainbow
      phase - 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)
      Generate a gradient with certain colors
      Parameters:
      length - The length of the gradient
      gradient - 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 gradient
      gradient - The colors of the gradient.
      rgb - Whether or not to use RGB colors
      Returns:
      the colors in the gradient
    • hasClass

      public static boolean hasClass(String className)
      Check if a certain class exists. See Class.forName(String)
      Parameters:
      className - The class name to check
      Returns:
      true if the class exists, false if not
    • hasMethod

      public static boolean hasMethod(Class<?> clazz, String method, Class<?>... parameter)
      Check if a class has a certain method. See Class.getMethod(String, Class[])
      Parameters:
      clazz - The class to check
      method - The method to check for
      parameter - Method parameter types
      Returns:
      true if the class has the method, false if not
    • getMethod

      public static Method getMethod(Class<?> clazz, String method, Class<?>... parameter)
      Get a method from a class if it exists. See Class.getMethod(String, Class[])
      Parameters:
      clazz - The class
      method - The method name to get
      parameter - Method parameter types
      Returns:
      the method, null if it doesn't exist