Class ChatColor
This class is a pseudo-Enum
. It contains the following methods:
name()
, ordinal()
, valueOf(String)
and values()
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ChatColor
Aqua.static final ChatColor
Black.static final ChatColor
Blue.static final ChatColor
Bold.static final String
String containing all default color and format codes.static final String
String containing all default color codes.static final ChatColor
Dark aqua.static final ChatColor
Dark blue.static final ChatColor
Dark gray.static final ChatColor
Dark green.static final ChatColor
Dark purple.static final ChatColor
Dark red.static final String
String containing all default format codes.static final ChatColor
Gold.static final ChatColor
Gray.static final ChatColor
Green.static final Pattern[]
Patterns used to identify hex colors.static final ChatColor
Italic.static final ChatColor
Light purple.static final ChatColor
Obfuscated/magic.static final ChatColor
Red.static final ChatColor
Reset.static final ChatColor
Strikethrough.static final Pattern
Pattern used to strip color from a string.static final ChatColor
Underline.static final ChatColor
White.static final ChatColor
Yellow. -
Method Summary
Modifier and TypeMethodDescriptionorg.bukkit.ChatColor
Gets the chat color adapted for Bukkit environments.net.md_5.bungee.api.ChatColor
Gets the chat color adapted for BungeeCord environments.boolean
Checks if another object is an instance ofChatColor
and if this color'stoString()
value is equal to the other object's one.static ChatColor
getByChar
(char code) Gets a default chat color by its code.Gets the default color closest to this color.getCode()
Gets this color's code.getColor()
Gets this color'sColor
value.static String
getLastColors
(String string) Gets the last colors contained in a string.static ChatColor
Gets a random color, format codes not included.int
hashCode()
Gets this color's hash code.static boolean
isColorCode
(char character) Checks if the specified character is a valid color code.static boolean
isColorString
(String string) Checks if the specified string contains color codes.boolean
Checks if this is a default color.boolean
Checks if this is a format code.static boolean
isFormatCode
(char character) Checks if the specified character is a valid format code.name()
Equivalent ofEnum.name()
.static ChatColor
Gets a chat color from givenColor
.static ChatColor
Gets a chat color from given hex color code.int
ordinal()
Equivalent ofEnum.ordinal()
.org.spongepowered.api.text.TextElement
Gets the chat color adapted for Sponge environments.static String
stripColor
(String string) Strips a string from any color and/or formatting codes.toString()
Gets the string representation of this color.static String
Callstranslate(String, boolean)
, specifyingtrue
as the second argument.static String
Translates given string applying default ("&x") and hex ("&#rrggbb", "#rrggbb") color codes.Translates given string list.Translates given string list.static ChatColor
Equivalent ofEnum#valueOf(String)
, with the only difference that instead of throwingIllegalArgumentException
null
is returned if the constant's name is invalid.static ChatColor[]
values()
Equivalent ofEnum#values()
.net.kyori.adventure.text.format.TextFormat
Gets the chat color adapted for Velocity environments.
-
Field Details
-
BLACK
Black.Code: 0
Type: color
Hex: #000000 -
DARK_BLUE
Dark blue.Code: 1
Type: color
Hex: #0000AA -
DARK_GREEN
Dark green.Code: 2
Type: color
Hex: #00AA00 -
DARK_AQUA
Dark aqua.Code: 3
Type: color
Hex: #00AAAA -
DARK_RED
Dark red.Code: 4
Type: color
Hex: #AA0000 -
DARK_PURPLE
Dark purple.Code: 5
Type: color
Hex: #AA00AA -
GOLD
Gold.Code: 6
Type: color
Hex: #FFAA00 -
GRAY
Gray.Code: 7
Type: color
Hex: #AAAAAA -
DARK_GRAY
Dark gray.Code: 8
Type: color
Hex: #555555 -
BLUE
Blue.Code: 9
Type: color
Hex: #5555FF -
GREEN
Green.Code: a/A
Type: color
Hex: #55FF55 -
AQUA
Aqua.Code: b/B
Type: color
Hex: #55FFFF -
RED
Red.Code: c/C
Type: color
Hex: #FF5555 -
LIGHT_PURPLE
Light purple.Code: d/D
Type: color
Hex: #FF55FF -
YELLOW
Yellow.Code: e/E
Type: color
Hex: #FFFF55 -
WHITE
White.Code: f/F
Type: color
Hex: #FFFFFF -
OBFUSCATED
Obfuscated/magic.Code: k/K
Type: format -
BOLD
Bold.Code: l/L
Type: format -
STRIKETHROUGH
Strikethrough.Code: m/M
Type: format -
UNDERLINE
Underline.Code: n/N
Type: format -
ITALIC
Italic.Code: o/O
Type: format -
RESET
Reset.Code: r/R
Type: color -
COLOR_CODES
String containing all default color codes.Content: "0123456789AaBbCcDdEeFfRr"
- See Also:
-
FORMAT_CODES
String containing all default format codes.Content: "KkLlMmNnOo"
- See Also:
-
CODES
String containing all default color and format codes.Content: "0123456789AaBbCcDdEeFfRrKkLlMmNnOo"
- See Also:
-
STRIP_COLOR
Pattern used to strip color from a string.Regex: "(?i)§[0-9A-FK-ORX]"
-
HEX_COLORS
Patterns used to identify hex colors.Contents: ["&#([A-Fa-f0-9]){6}", "#([A-Fa-f0-9]){6}"]
-
-
Method Details
-
toString
Gets the string representation of this color.Will return
'§' +
getCode()
ifisDefaultColor()
and a hex string (example: "§x§f§f§5§5§f§f" - translated) otherwise. -
equals
Checks if another object is an instance ofChatColor
and if this color'stoString()
value is equal to the other object's one. -
hashCode
public int hashCode()Gets this color's hash code.Will return
toString()
's hash code. -
bukkitValue
public org.bukkit.ChatColor bukkitValue()Gets the chat color adapted for Bukkit environments.Will return
ChatColor.RESET
if!
isDefaultColor()
.- Returns:
- Bukkit-adapted chat color
- Throws:
UnsupportedOperationException
- If !Environment.isBukkit()
-
spongeValue
public org.spongepowered.api.text.TextElement spongeValue()Gets the chat color adapted for Sponge environments.Will return
TextColors.RESET
if!
isDefaultColor()
.- Returns:
- Sponge-adapted chat color
- Throws:
UnsupportedOperationException
- If !Environment.isSponge()
-
bungeeValue
public net.md_5.bungee.api.ChatColor bungeeValue()Gets the chat color adapted for BungeeCord environments.This method supports hex colors (
!
isDefaultColor()
).- Returns:
- BungeeCord-adapted chat color
- Throws:
UnsupportedOperationException
- If !Environment.isBungeeCord()
-
velocityValue
public net.kyori.adventure.text.format.TextFormat velocityValue()Gets the chat color adapted for Velocity environments.This method supports hex colors (
!
isDefaultColor()
).- Returns:
- Velocity-adapted chat color
- Throws:
UnsupportedOperationException
- If !Environment.isVelocity()
-
name
Equivalent ofEnum.name()
.Will return a hex string (example: "#FF55FF") if
!
isDefaultColor()
.- Returns:
- Constant's name
-
ordinal
public int ordinal()Equivalent ofEnum.ordinal()
.Will return -1 if
!
isDefaultColor()
.- Returns:
- Constant's ordinal
-
getCode
Gets this color's code.Will return
null
if!
isDefaultColor()
.- Returns:
- Color's code
-
getColor
Gets this color'sColor
value.Will return
null
ifisFormatCode()
.Note: returned color has an alpha value of 255.
- Returns:
- Color's value
-
isDefaultColor
public boolean isDefaultColor()Checks if this is a default color.- Returns:
- Whether this is a default color
-
isFormatCode
public boolean isFormatCode()Checks if this is a format code.- Returns:
- Whether this is a format code
-
getClosestDefaultColor
Gets the default color closest to this color.Will return
this
if
.isDefaultColor()
||isFormatCode()
Note: this method uses the same algorithm of ViaVersion.
- Returns:
- Closest default color
-
of
Gets a chat color from givenColor
.May return one of the 16 default colors.
- Parameters:
color
- Color to transform- Returns:
- Chat color equivalent
-
of
Gets a chat color from given hex color code.May return one of the 16 default colors.
The following formats are supported: "#rrggbb", "rrggbb".
- Parameters:
hex
- Color's hex representation, with or without '#'- Returns:
- Chat color equivalent
- Throws:
NumberFormatException
- If the specified string's format is invalid
-
translate
Callstranslate(String, boolean)
, specifyingtrue
as the second argument.- Parameters:
string
- String to translate- Returns:
- Translated string
-
translate
Translates given string applying default ("&x") and hex ("&#rrggbb", "#rrggbb") color codes.- Parameters:
string
- String to translateretainNewLines
- Whether to retain new lines or to replace them with spaces- Returns:
- Translated string
-
translate
Translates given string list.- Parameters:
list
- List to translate- Returns:
- Translated string list
- See Also:
-
translate
Translates given string list.- Parameters:
list
- List to translateretainNewLines
- Whether to retain new lines or to replace them with spaces- Returns:
- Translated string list
- See Also:
-
stripColor
Strips a string from any color and/or formatting codes.- Parameters:
string
- String to strip- Returns:
- Stripped string
-
getLastColors
Gets the last colors contained in a string.Will return an empty string if there are no colors in the string.
- Parameters:
string
- String to check- Returns:
- Last colors in string
-
isColorCode
public static boolean isColorCode(char character) Checks if the specified character is a valid color code.- Parameters:
character
- Character to check- Returns:
- Whether the character is a color code
- See Also:
-
isFormatCode
public static boolean isFormatCode(char character) Checks if the specified character is a valid format code.- Parameters:
character
- Character to check- Returns:
- Whether the character is a format code
- See Also:
-
isColorString
Checks if the specified string contains color codes.- Parameters:
string
- String to check- Returns:
- Whether the string contains colors
-
getRandomColor
Gets a random color, format codes not included.Hex colors will be returned on 1.16+ environments.
- Returns:
- Random color
-
getByChar
Gets a default chat color by its code.Will return
null
if the code is invalid.- Parameters:
code
- Color's code- Returns:
- Corresponding color
-
valueOf
Equivalent ofEnum#valueOf(String)
, with the only difference that instead of throwingIllegalArgumentException
null
is returned if the constant's name is invalid.This method recognizes Bukkit's, Sponge's BungeeCord's and Velocity's IDs.
- Parameters:
name
- Constant's name- Returns:
- Enum constant
-
values
Equivalent ofEnum#values()
.- Returns:
- Enum constants
-