Package me.neznamy.tab.api.chat
Class TextColor
java.lang.Object
me.neznamy.tab.api.chat.TextColor
A class representing a component color, which can be either RGB or legacy code.
-
Constructor Summary
ConstructorsConstructorDescriptionTextColor(int red, int green, int blue) Constructs new instance with red, green and blue valuesConstructs new instance from provided 6-digit hex code stringTextColor(String hexCode, EnumChatFormat legacyColor) Constructs new instance from provided 6-digit hex code and forced legacy colorTextColor(EnumChatFormat legacyColor) Constructs new instance from provided legacy colorConstructs new instance as a clone of the provided color. -
Method Summary
Modifier and TypeMethodDescriptionstatic TextColorfromString(String string) Reads the string as it appears in chat component and turns it into the color object.intgetBlue()ReturnsbluevalueintgetGreen()ReturnsgreenvalueReturns the rgb combination as a 6-digit hex code stringReturns the closest legacy color of this color object.intgetRed()ReturnsredvaluebooleanReturns true if legacy color was forced with a constructor, false if nottoString()Converts the color into a valid color value used in color field in chat component.
-
Constructor Details
-
TextColor
Constructs new instance as a clone of the provided color.- Parameters:
color- color to create a clone of- Throws:
IllegalArgumentException- if color isnull
-
TextColor
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 isnull
-
TextColor
Constructs new instance from provided 6-digit hex code and forced legacy color- Parameters:
hexCode- 6-digit combination of hex numbers as a stringlegacyColor- color to use for legacy clients instead of using the closest legacy color- Throws:
IllegalArgumentException- ifhexCodeisnullorlegacyColorisnull
-
TextColor
Constructs new instance from provided legacy color- Parameters:
legacyColor- legacy color to construct the instance from- Throws:
IllegalArgumentException- iflegacyColorisnull
-
TextColor
public TextColor(int red, int green, int blue) Constructs new instance with red, green and blue values- Parameters:
red- red valuegreen- green valueblue- blue value- Throws:
IllegalArgumentException- ifred,greenorblueis out of range (0-255)
-
-
Method Details
-
getRed
public int getRed()Returnsredvalue- Returns:
- red value
-
getGreen
public int getGreen()Returnsgreenvalue- Returns:
- green value
-
getBlue
public int getBlue()Returnsbluevalue- Returns:
- blue value
-
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
Returns the rgb combination as a 6-digit hex code string- Returns:
- the rgb combination as a 6-digit hex code 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. -
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
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
-