Class IChatBaseComponent

java.lang.Object
me.neznamy.tab.api.chat.IChatBaseComponent
Direct Known Subclasses:
ChatComponentEntity, DeserializedChatComponent, WrappedChatComponent

public class IChatBaseComponent extends Object
A class representing the n.m.s.IChatBaseComponent class to make work with it much easier
  • Constructor Details

    • IChatBaseComponent

      public IChatBaseComponent()
      Constructs a new empty component
    • IChatBaseComponent

      public IChatBaseComponent(IChatBaseComponent component)
      Constructs a new component which is a clone of provided component
      Parameters:
      component - component to clone
    • IChatBaseComponent

      public IChatBaseComponent(String text)
      Constructs new instance with given text
      Parameters:
      text - text to display
  • Method Details

    • getExtra

      public List<IChatBaseComponent> getExtra()
      Returns list of extra components. If no extra components are defined, returns empty list.
      Returns:
      list of extra components
    • setExtra

      public IChatBaseComponent setExtra(List<IChatBaseComponent> components)
      Sets full list of extra components to given list. Does not allow empty list.
      Parameters:
      components - components to use as extra
      Returns:
      self
      Throws:
      IllegalArgumentException - if components is an empty list
    • addExtra

      public void addExtra(IChatBaseComponent child)
      Appends provided component as extra component
      Parameters:
      child - component to append
    • getText

      public String getText()
      Returns text of this component
      Returns:
      text of this component
    • getModifier

      public ChatModifier getModifier()
      Returns chat modifier of this component
      Returns:
      chat modifier of this component
    • setModifier

      public void setModifier(ChatModifier modifier)
      Sets modifier to provided value
      Parameters:
      modifier - modifier to set value to
      Throws:
      IllegalArgumentException - if modifier is null
    • setText

      public void setText(String text)
      Changes text of this component
      Parameters:
      text - text to show
    • deserialize

      public static IChatBaseComponent deserialize(String json)
      Deserializes string and returns created component. If provided string is null, returns null.
      Parameters:
      json - serialized string
      Returns:
      Deserialized component or null if input is null
    • toString

      public String toString()
      Converts the component to a string representing the serialized component. This method is only used internally by json library since it's missing protocol version field used by the method.
      Overrides:
      toString in class Object
      Returns:
      serialized component in string form
      See Also:
    • toString

      public String toString(ProtocolVersion clientVersion)
      Serializes this component with colors based on client version. If client version is <1.16, HEX colors will be converted to legacy colors.
      Parameters:
      clientVersion - client version to adapt component for
      Returns:
      serialized string
    • toString

      public String toString(ProtocolVersion clientVersion, boolean sendTranslatableIfEmpty)
      Serializes this component with colors based on client version. If client version is <1.16, HEX colors will be converted to legacy colors.
      Parameters:
      clientVersion - client version to adapt component for
      sendTranslatableIfEmpty - whether empty translatable should be sent if text is empty or not
      Returns:
      serialized string
    • fromColoredText

      public static IChatBaseComponent fromColoredText(String originalText)
      Returns organized component from colored text
      Parameters:
      originalText - text to convert
      Returns:
      organized component from colored text
    • toLegacyText

      public String toLegacyText()
      Converts this component into a simple text with legacy colors (the closest match if color is set to RGB)
      Returns:
      The simple text format
    • toRawText

      public String toRawText()
      Returns raw text without colors, only works correctly when component is organized
      Returns:
      raw text in this component and all child components
    • toFlatText

      public String toFlatText()
      Converts the component into flat text with used colors (including rgb) and magic codes
      Returns:
      converted text
    • optimizedComponent

      public static IChatBaseComponent optimizedComponent(String text)
      Returns the most optimized component based on text. Returns null if text is null, organized component if RGB colors are used or simple component with only text field containing the whole text when no RGB colors are used
      Parameters:
      text - text to create component from
      Returns:
      The most performance-optimized component based on text