Class TextUtil

java.lang.Object
com.github.darksoulq.abyssallib.common.util.TextUtil

public class TextUtil extends Object
Utility methods for text handling, including:
  • JSON serialization/deserialization with Gson
  • MiniMessage parsing with MiniMessage
  • String/array conversions
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static com.google.gson.Gson
    The shared Gson instance configured with registered type adapters.
    static final net.kyori.adventure.text.minimessage.MiniMessage
    The shared MiniMessage instance used for parsing MiniMessage text.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Builds the global Gson instance using all registered type adapters.
    static String[]
    Converts a List of strings into a String[] array.
    static List<String>
    Converts a String[] into a List.
    static net.kyori.adventure.text.Component
    parse(String mmText)
    Parses a MiniMessage string into a Component.
    static net.kyori.adventure.text.Component
    parse(String mmText, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... resolvers)
    Parses a MiniMessage string with custom TagResolvers into a Component.
    static <T> void
    registerTypeAdapter(Class<T> clazz, Object adapter)
    Registers a type adapter for a specific class and rebuilds the global Gson instance.
    static <T> void
    Registers a type adapter for a class hierarchy and rebuilds the global Gson instance.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • GSON

      public static com.google.gson.Gson GSON
      The shared Gson instance configured with registered type adapters.

      Rebuilt whenever new type adapters are registered.

    • MM

      public static final net.kyori.adventure.text.minimessage.MiniMessage MM
      The shared MiniMessage instance used for parsing MiniMessage text.
  • Constructor Details

    • TextUtil

      public TextUtil()
  • Method Details

    • buildGson

      public static void buildGson()
      Builds the global Gson instance using all registered type adapters.

      This method is automatically called when registering new adapters.

    • registerTypeAdapter

      public static <T> void registerTypeAdapter(Class<T> clazz, Object adapter)
      Registers a type adapter for a specific class and rebuilds the global Gson instance.
      Type Parameters:
      T - the class type
      Parameters:
      clazz - the class to register the adapter for
      adapter - the type adapter instance
    • registerTypeHierarchyAdapter

      public static <T> void registerTypeHierarchyAdapter(Class<T> clazz, Object adapter)
      Registers a type adapter for a class hierarchy and rebuilds the global Gson instance.
      Type Parameters:
      T - the base class type
      Parameters:
      clazz - the base class of the hierarchy
      adapter - the type adapter instance
    • convertToList

      public static List<String> convertToList(String[] arr)
      Converts a String[] into a List.
      Parameters:
      arr - the string array
      Returns:
      a list backed by the array
    • convertToArray

      public static String[] convertToArray(List<String> list)
      Converts a List of strings into a String[] array.
      Parameters:
      list - the list of strings
      Returns:
      a new array containing the elements of the list
    • parse

      public static net.kyori.adventure.text.Component parse(String mmText)
      Parses a MiniMessage string into a Component.
      Parameters:
      mmText - the MiniMessage string
      Returns:
      the parsed Component
    • parse

      public static net.kyori.adventure.text.Component parse(String mmText, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... resolvers)
      Parses a MiniMessage string with custom TagResolvers into a Component.
      Parameters:
      mmText - the MiniMessage string
      resolvers - the tag resolvers to apply
      Returns:
      the parsed Component