Class ComponentUtils

java.lang.Object
com.thewinterframework.component.ComponentUtils

public final class ComponentUtils extends Object
Utility class for working with Adventure components.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addComponentModifier(@NotNull UnaryOperator<net.kyori.adventure.text.Component> modifier)
    Adds a component modifier.
    static <T> void
    addComponentResolver(@NotNull Class<T> clazz, @NotNull ComponentResolver<T> resolver)
    Adds a component resolver.
    static void
    addGlobalTagResolver(@NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver tagResolver)
    Adds a global tag resolver.
    static net.kyori.adventure.text.Component
    legacyAmpersand(@NotNull String message)
    Serializes a string into a legacy ampersand string.
    static net.kyori.adventure.text.Component
    legacyAmpersand(@NotNull String message, boolean applyModifiers)
    Serializes a string into a legacy ampersand string.
    static List<net.kyori.adventure.text.Component>
    legacyAmpersand(@NotNull Collection<String> messages)
    Serializes multiple strings into legacy ampersand components.
    static List<net.kyori.adventure.text.Component>
    legacyAmpersand(@NotNull Collection<String> messages, boolean applyModifiers)
    Serializes multiple strings into legacy ampersand components.
    static String
    legacyAmpersand(@NotNull net.kyori.adventure.text.Component component)
    Serializes a component into a legacy ampersand string.
    static net.kyori.adventure.text.Component
    legacySection(@NotNull String message)
    Serializes a string into a legacy section string.
    static net.kyori.adventure.text.Component
    legacySection(@NotNull String message, boolean applyModifiers)
    Serializes a string into a legacy section string.
    static List<net.kyori.adventure.text.Component>
    legacySection(@NotNull Collection<String> messages)
    Serializes multiple strings into legacy section components.
    static List<net.kyori.adventure.text.Component>
    legacySection(@NotNull Collection<String> messages, boolean applyModifiers)
    Serializes multiple strings into legacy section components.
    static String
    legacySection(@NotNull net.kyori.adventure.text.Component component)
    Serializes a component into a legacy section string.
    static net.kyori.adventure.text.Component
    miniMessage(@NotNull String message, boolean applyModifiers, @NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... tagResolvers)
    Parses a MiniMessage string into a component.
    static net.kyori.adventure.text.Component
    miniMessage(@NotNull String message, @NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... tagResolvers)
    Parses a MiniMessage string into a component.
    static List<net.kyori.adventure.text.Component>
    miniMessage(@NotNull Collection<String> messages, boolean applyModifiers, @NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... tagResolvers)
    Parses multiple MiniMessage strings into components.
    static List<net.kyori.adventure.text.Component>
    miniMessage(@NotNull Collection<String> messages, @NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... tagResolvers)
    Parses multiple MiniMessage strings into components.
    static List<String>
    miniMessage(@NotNull Collection<net.kyori.adventure.text.Component> components)
    Serializes multiple components into MiniMessage strings.
    static String
    miniMessage(@NotNull net.kyori.adventure.text.Component component)
    Serializes a component into a MiniMessage string.
    static net.kyori.adventure.text.Component
    plainText(@NotNull String message)
    Serializes a string into a plain text component.
    static net.kyori.adventure.text.Component
    plainText(@NotNull String message, boolean applyModifiers)
    Serializes a string into a plain text component.
    static List<String>
    plainText(@NotNull Collection<net.kyori.adventure.text.Component> components)
    Serializes multiple components into plain text strings.
    static String
    plainText(@NotNull net.kyori.adventure.text.Component component)
    Serializes a component into a plain text string.
    static @NotNull net.kyori.adventure.text.Component
    resolve(@NotNull Object object)
    Resolves an object into a component.
    static @NotNull net.kyori.adventure.text.Component[]
    resolveMany(@NotNull Object... objects)
    Resolves multiple objects into components.

    Methods inherited from class java.lang.Object

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

    • addGlobalTagResolver

      public static void addGlobalTagResolver(@NotNull @NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver tagResolver)
      Adds a global tag resolver.
      Parameters:
      tagResolver - The tag resolver to add.
    • addComponentResolver

      public static <T> void addComponentResolver(@NotNull @NotNull Class<T> clazz, @NotNull @NotNull ComponentResolver<T> resolver)
      Adds a component resolver.
      Type Parameters:
      T - The type of the class to resolve.
      Parameters:
      clazz - The class to resolve.
      resolver - The resolver to add.
    • addComponentModifier

      public static void addComponentModifier(@NotNull @NotNull UnaryOperator<net.kyori.adventure.text.Component> modifier)
      Adds a component modifier.
      Parameters:
      modifier - The modifier to add.
    • miniMessage

      public static String miniMessage(@NotNull @NotNull net.kyori.adventure.text.Component component)
      Serializes a component into a MiniMessage string.
      Parameters:
      component - The component to serialize.
      Returns:
      The serialized MiniMessage string.
    • miniMessage

      public static List<String> miniMessage(@NotNull @NotNull Collection<net.kyori.adventure.text.Component> components)
      Serializes multiple components into MiniMessage strings.
      Parameters:
      components - The components to serialize.
      Returns:
      The serialized MiniMessage strings.
    • miniMessage

      public static net.kyori.adventure.text.Component miniMessage(@NotNull @NotNull String message, boolean applyModifiers, @NotNull @NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... tagResolvers)
      Parses a MiniMessage string into a component.
      Parameters:
      message - The message to parse.
      applyModifiers - Whether to apply component modifiers.
      tagResolvers - The tag resolvers to use.
      Returns:
      The parsed component.
    • miniMessage

      public static net.kyori.adventure.text.Component miniMessage(@NotNull @NotNull String message, @NotNull @NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... tagResolvers)
      Parses a MiniMessage string into a component.
      Parameters:
      message - The message to parse.
      tagResolvers - The tag resolvers to use.
      Returns:
      The parsed component.
    • miniMessage

      public static List<net.kyori.adventure.text.Component> miniMessage(@NotNull @NotNull Collection<String> messages, boolean applyModifiers, @NotNull @NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... tagResolvers)
      Parses multiple MiniMessage strings into components.
      Parameters:
      messages - The messages to parse.
      applyModifiers - Whether to applycomponent modifiers.
      tagResolvers - The tag resolvers to use.
      Returns:
      The parsed components.
    • miniMessage

      public static List<net.kyori.adventure.text.Component> miniMessage(@NotNull @NotNull Collection<String> messages, @NotNull @NotNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... tagResolvers)
      Parses multiple MiniMessage strings into components.
      Parameters:
      messages - The messages to parse.
      tagResolvers - The tag resolvers to use.
      Returns:
      The parsed components.
    • legacySection

      public static net.kyori.adventure.text.Component legacySection(@NotNull @NotNull String message, boolean applyModifiers)
      Serializes a string into a legacy section string. This is a string where color codes are prefixed with §. For example, §cHello §fworld.
      Parameters:
      message - The message to serialize.
      Returns:
      The serialized legacy section component.
    • legacySection

      public static net.kyori.adventure.text.Component legacySection(@NotNull @NotNull String message)
      Serializes a string into a legacy section string. This is a string where color codes are prefixed with §. For example, §cHello §fworld.
      Parameters:
      message - The message to serialize.
      Returns:
      The serialized legacy section component.
    • legacySection

      public static List<net.kyori.adventure.text.Component> legacySection(@NotNull @NotNull Collection<String> messages, boolean applyModifiers)
      Serializes multiple strings into legacy section components.
      Parameters:
      messages - The messages to serialize.
      applyModifiers - Whether to apply component modifiers.
      Returns:
      The serialized legacy section components.
    • legacySection

      public static List<net.kyori.adventure.text.Component> legacySection(@NotNull @NotNull Collection<String> messages)
      Serializes multiple strings into legacy section components.
      Parameters:
      messages - The messages to serialize.
      Returns:
      The serialized legacy section components.
    • legacySection

      public static String legacySection(@NotNull @NotNull net.kyori.adventure.text.Component component)
      Serializes a component into a legacy section string. This is a string where color codes are prefixed with §. For example, §cHello §fworld.
      Parameters:
      component - The component to serialize.
      Returns:
      The serialized legacy section component.
    • legacyAmpersand

      public static net.kyori.adventure.text.Component legacyAmpersand(@NotNull @NotNull String message, boolean applyModifiers)
      Serializes a string into a legacy ampersand string. This is a string where color codes are prefixed with ampersand.
      Parameters:
      message - The message to serialize.
      applyModifiers - Whether to apply component modifiers.
      Returns:
      The serialized legacy ampersand component.
    • legacyAmpersand

      public static net.kyori.adventure.text.Component legacyAmpersand(@NotNull @NotNull String message)
      Serializes a string into a legacy ampersand string. This is a string where color codes are prefixed with ampersand.
      Parameters:
      message - The message to serialize.
      Returns:
      The serialized legacy ampersand component.
    • legacyAmpersand

      public static List<net.kyori.adventure.text.Component> legacyAmpersand(@NotNull @NotNull Collection<String> messages, boolean applyModifiers)
      Serializes multiple strings into legacy ampersand components.
      Parameters:
      messages - The messages to serialize.
      applyModifiers - Whether to applycomponent modifiers.
      Returns:
      The serialized legacy ampersand components.
    • legacyAmpersand

      public static List<net.kyori.adventure.text.Component> legacyAmpersand(@NotNull @NotNull Collection<String> messages)
      Serializes multiple strings into legacy ampersand components.
      Parameters:
      messages - The messages to serialize.
      Returns:
      The serialized legacy ampersand components.
    • legacyAmpersand

      public static String legacyAmpersand(@NotNull @NotNull net.kyori.adventure.text.Component component)
      Serializes a component into a legacy ampersand string. This is a string where color codes are prefixed with ampersand.
      Parameters:
      component - The component to serialize.
      Returns:
      The serialized legacy ampersand component.
    • plainText

      public static String plainText(@NotNull @NotNull net.kyori.adventure.text.Component component)
      Serializes a component into a plain text string. This is a string where all formatting is removed.
      Parameters:
      component - The component to serialize.
      Returns:
      The serialized plain text component.
    • plainText

      public static List<String> plainText(@NotNull @NotNull Collection<net.kyori.adventure.text.Component> components)
      Serializes multiple components into plain text strings.
      Parameters:
      components - The components to serialize.
      Returns:
      The serialized plain text components.
    • plainText

      public static net.kyori.adventure.text.Component plainText(@NotNull @NotNull String message, boolean applyModifiers)
      Serializes a string into a plain text component. This is a component where all formatting is removed.
      Parameters:
      message - The message to serialize.
      Returns:
      The serialized plain text component.
    • plainText

      public static net.kyori.adventure.text.Component plainText(@NotNull @NotNull String message)
      Serializes a string into a plain text component. This is a component where all formatting is removed.
      Parameters:
      message - The message to serialize.
      Returns:
      The serialized plain text component.
    • resolve

      @NotNull public static @NotNull net.kyori.adventure.text.Component resolve(@NotNull @NotNull Object object)
      Resolves an object into a component.
      Parameters:
      object - The object to resolve.
      Returns:
      The resolved component.
    • resolveMany

      @NotNull public static @NotNull net.kyori.adventure.text.Component[] resolveMany(@NotNull @NotNull Object... objects)
      Resolves multiple objects into components.
      Parameters:
      objects - The objects to resolve.
      Returns:
      The resolved components.