Class ChatComponent

java.lang.Object
com.saicone.rtag.util.ChatComponent

public class ChatComponent extends Object
Class to invoke CraftChatMessage methods across versions.
  • Field Details

    • NBT_PALETTE

      public static final String[] NBT_PALETTE
      Default color palette for pretty nbt.
    • NBT_PALETTE_HEX

      public static final String[] NBT_PALETTE_HEX
      Color palette with hex colors introduced on MC 1.16.
    • NBT_PALETTE_BUNGEE

      public static final String[] NBT_PALETTE_BUNGEE
      Color palette with hex colors introduced on MC 1.16 using Bungeecord chat format.
    • NBT_PALETTE_MINIMESSAGE

      public static final String[] NBT_PALETTE_MINIMESSAGE
      Color palette using Adventure MiniMessage format.
    • CODEC

      public static final Object CODEC
      Component codec.
  • Method Details

    • isChatComponent

      public static boolean isChatComponent(Object object)
      Check if the provided object is instance of chat component
      or is a String that follow the ChatComponent format.
      Parameters:
      object - the object to check.
      Returns:
      true if the object is ChatComponent.
    • fromJson

      public static Object fromJson(String json)
      Convert json component string to chat component.
      Supports any old representation of text component.
      Parameters:
      json - json to convert.
      Returns:
      a chat component instance.
    • fromString

      public static Object fromString(String string)
      Convert string to chat component.
      Parameters:
      string - Json to convert.
      Returns:
      A chat component instance.
    • fromTag

      public static Object fromTag(Object tag)
      Convert nbt to chat component.
      Supports newer representation of text component on older server versions.
      Parameters:
      tag - nbt to convert.
      Returns:
      a chat component instance.
    • toJson

      public static String toJson(Object component) throws IllegalArgumentException
      Convert String or chat component to json component.
      Parameters:
      component - String or chat component to convert.
      Returns:
      A json component.
      Throws:
      IllegalArgumentException - if component is not a valid ChatComponent.
    • toJsonOrNull

      public static String toJsonOrNull(Object component) throws IllegalArgumentException
      Convert String or chat component to json component.
      Parameters:
      component - String or chat component to convert.
      Returns:
      A json component or null.
      Throws:
      IllegalArgumentException - if component is not a valid ChatComponent.
    • toString

      public static String toString(Object component) throws IllegalArgumentException
      Convert json String or chat component to string.
      Parameters:
      component - Json String or chat component to convert.
      Returns:
      A string with old format.
      Throws:
      IllegalArgumentException - if component is not a valid ChatComponent.
    • toStringOrNull

      public static String toStringOrNull(Object component) throws IllegalArgumentException
      Convert json String or chat component to string.
      Parameters:
      component - Json String or chat component to convert.
      Returns:
      A string with old format or null.
      Throws:
      IllegalArgumentException - if component is not a valid ChatComponent.
    • toTag

      public static Object toTag(Object component)
      Convert chat component to nbt.
      Parameters:
      component - chat component to convert.
      Returns:
      a nbt object.
      Throws:
      IllegalArgumentException - if component is not a valid ChatComponent.
    • toTagOrNull

      public static Object toTagOrNull(Object component)
      Convert chat component to nbt.
      Parameters:
      component - chat component to convert.
      Returns:
      a nbt object or null.
      Throws:
      IllegalArgumentException - if component is not a valid ChatComponent.
    • toPrettyComponent

      public static Object toPrettyComponent(Object tag, String indent)
      Format the provided tag into pretty string as chat component.
      Parameters:
      tag - the tag to format.
      indent - the indent to use for multi-line formatting, use null or empty string for single-line format.
      Returns:
      a pretty formated nbt object as chat component.
    • toPrettyComponent

      public static Object toPrettyComponent(Object tag, String indent, String[] palette)
      Format the provided tag into pretty string as chat component.
      Parameters:
      tag - the tag to format.
      indent - the indent to use for multi-line formatting, use null or empty string for single-line format.
      palette - the color palette to use.
      Returns:
      a pretty formated nbt object as chat component.
    • toPrettyJson

      public static String toPrettyJson(Object tag, String indent)
      Format the provided tag into pretty string as json component.
      Parameters:
      tag - the tag to format.
      indent - the indent to use for multi-line formatting, use null or empty string for single-line format.
      Returns:
      a pretty formated nbt object as json.
    • toPrettyJson

      public static String toPrettyJson(Object tag, String indent, String[] palette)
      Format the provided tag into pretty string as json component.
      Parameters:
      tag - the tag to format.
      indent - the indent to use for multi-line formatting, use null or empty string for single-line format.
      palette - the color palette to use.
      Returns:
      a pretty formated nbt object as json.
    • toPrettyString

      public static String toPrettyString(Object tag, String indent)
      Format the provided tag into pretty string.
      Parameters:
      tag - the tag to format.
      indent - the indent to use for multi-line formatting, use null or empty string for single-line format.
      Returns:
      a pretty formated nbt object as string.
    • toPrettyString

      public static String toPrettyString(Object tag, String indent, String[] palette)
      Format the provided tag into pretty string.
      Parameters:
      tag - the tag to format.
      indent - the indent to use for multi-line formatting, use null or empty string for single-line format.
      palette - the color palette to use.
      Returns:
      a pretty formated nbt object as string.