Class TextColor

java.lang.Object
me.neznamy.tab.api.chat.TextColor

public class TextColor extends Object
A class representing a component color, which can be either RGB or legacy code.
  • Constructor Details

    • TextColor

      public TextColor(TextColor color)
      Constructs new instance as a clone of the provided color.
      Parameters:
      color - color to create a clone of
      Throws:
      IllegalArgumentException - if color is null
    • TextColor

      public TextColor(String hexCode)
      Constructs new instance from provided 6-digit hex code string
      Parameters:
      hexCode - a 6-digit combination of hex numbers as a string
      Throws:
      IllegalArgumentException - if hexCode is null
    • TextColor

      public TextColor(String hexCode, EnumChatFormat legacyColor)
      Constructs new instance from provided 6-digit hex code and forced legacy color
      Parameters:
      hexCode - 6-digit combination of hex numbers as a string
      legacyColor - color to use for legacy clients instead of using the closest legacy color
      Throws:
      IllegalArgumentException - if hexCode is null or legacyColor is null
    • TextColor

      public TextColor(EnumChatFormat legacyColor)
      Constructs new instance from provided legacy color
      Parameters:
      legacyColor - legacy color to construct the instance from
      Throws:
      IllegalArgumentException - if legacyColor is null
    • TextColor

      public TextColor(int red, int green, int blue)
      Constructs new instance with red, green and blue values
      Parameters:
      red - red value
      green - green value
      blue - blue value
      Throws:
      IllegalArgumentException - if red, green or blue is out of range (0-255)
  • Method Details

    • getRed

      public int getRed()
      Returns red value
      Returns:
      red value
    • getGreen

      public int getGreen()
      Returns green value
      Returns:
      green value
    • getBlue

      public int getBlue()
      Returns blue value
      Returns:
      blue value
    • getLegacyColor

      public EnumChatFormat getLegacyColor()
      Returns the closest legacy color of this color object. If the color was defined in constructor, it's returned. Otherwise, the closest color is calculated the then returned.
      Returns:
      closest legacy color
    • getHexCode

      public String getHexCode()
      Returns the rgb combination as a 6-digit hex code string
      Returns:
      the rgb combination as a 6-digit hex code string
    • toString

      public String toString()
      Converts the color into a valid color value used in color field in chat component. That is either 6-digit hex code prefixed with '#', or lowercase legacy color.
      Overrides:
      toString in class Object
      Returns:
      the color serialized for use in chat component
    • isLegacyColorForced

      public boolean isLegacyColorForced()
      Returns true if legacy color was forced with a constructor, false if not
      Returns:
      true if forced, false if not
    • fromString

      public static TextColor fromString(String string)
      Reads the string as it appears in chat component and turns it into the color object. If the entered string is null, returns null. If it's prefixed with '#', it's considered as a hex code. Otherwise, it is considered being a lowercase legacy color.
      Parameters:
      string - string from color field in chat component
      Returns:
      An instance from specified string or null if string is null