Class Util

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

public class Util
extends java.lang.Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  Util.TextControl  
  • Constructor Summary

    Constructors
    Constructor Description
    Util()  
  • Method Summary

    Modifier and Type Method Description
    static net.kyori.adventure.text.ComponentBuilder applyFormat​(net.kyori.adventure.text.ComponentBuilder builder, java.util.Collection<net.kyori.adventure.text.format.TextDecoration> formats)
    Apply a collection of colors/formats to a component builder
    static net.kyori.adventure.text.Component applyFormat​(net.kyori.adventure.text.Component component, java.util.Collection<net.kyori.adventure.text.format.TextDecoration> formats)
    Apply a collection of colors/formats to a component
    static double distance​(java.awt.Color c1, java.awt.Color c2)
    Get the distance between two colors
    static net.kyori.adventure.text.format.NamedTextColor getClosestLegacy​(java.awt.Color color)
    Get the legacy color closest to a certain RGB color
    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
    static java.util.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
    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
    static int indexOfNotEscaped​(java.lang.String string, java.lang.String chars)
    Get the index of the first occurrences of a not escaped character
    static int indexOfNotEscaped​(java.lang.String string, java.lang.String chars, int fromIndex)
    Get the index of the first occurrences of a not escaped character
    static boolean isDouble​(java.lang.String string, int index)
    Check whether or not a character at a certain index of a string repeats itself
    static boolean isEscaped​(java.lang.String string, int index)
    Check if a character at a certain index is escaped
    static boolean isFormat​(net.kyori.adventure.text.format.TextColor format)
    Check whether a certain TextColor is formatting or not
    static net.kyori.adventure.text.Component rgbColorsToLegacy​(net.kyori.adventure.text.Component components)
    Utility method to remove RGB colors from components.
    static void validate​(boolean value, java.lang.String message)
    Utility method to throw an IllegalArgumentException if the value is false
    static java.lang.String wrap​(java.lang.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, java.lang.String message) throws java.lang.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:
      java.lang.IllegalArgumentException - Thrown if the value is false
    • applyFormat

      public static net.kyori.adventure.text.Component applyFormat​(net.kyori.adventure.text.Component component, java.util.Collection<net.kyori.adventure.text.format.TextDecoration> formats)
      Apply a collection of colors/formats to a component
      Parameters:
      component - The BaseComponent
      formats - The collection of TextColor formats to apply
      Returns:
      The component that was modified
    • applyFormat

      public static net.kyori.adventure.text.ComponentBuilder applyFormat​(net.kyori.adventure.text.ComponentBuilder builder, java.util.Collection<net.kyori.adventure.text.format.TextDecoration> formats)
      Apply a collection of colors/formats to a component builder
      Parameters:
      builder - The ComponentBuilder
      formats - The collection of TextColor formats to apply
      Returns:
      The component builder that was modified
    • isDouble

      public static boolean isDouble​(java.lang.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.kyori.adventure.text.format.TextColor format)
      Check whether a certain TextColor is formatting or not
      Parameters:
      format - The TextColor to check
      Returns:
      true if it's a format, false if it's a color
    • getFormats

      public static java.util.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 from
      ignoreParent - 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

      public static int indexOfNotEscaped​(java.lang.String string, java.lang.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​(java.lang.String string, java.lang.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​(java.lang.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:
      java.lang.IndexOutOfBoundsException - if the index argument is not less than the length of this string.
    • wrap

      public static java.lang.String wrap​(java.lang.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.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

      public static net.kyori.adventure.text.format.NamedTextColor getClosestLegacy​(java.awt.Color color)
      Get the legacy color closest to a certain RGB color
      Parameters:
      color - The color to get teh closest legacy color for
      Returns:
      The closest legacy color
    • distance

      public static double distance​(java.awt.Color c1, java.awt.Color c2)
      Get the distance between two colors
      Parameters:
      c1 - Color A
      c2 - Color B
      Returns:
      The distance or 0 if they are equal
    • 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