Class ChatComponent
java.lang.Object
com.saicone.rtag.util.ChatComponent
Class to invoke CraftChatMessage methods across versions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectComponent codec.static final String[]Default color palette for pretty nbt.static final String[]Color palette with hex colors introduced on MC 1.16 using Bungeecord chat format.static final String[]Color palette with hex colors introduced on MC 1.16.static final String[]Color palette using Adventure MiniMessage format. -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectConvert json component string to chat component.
Supports any old representation of text component.static ObjectfromString(String string) Convert string to chat component.static ObjectConvert nbt to chat component.
Supports newer representation of text component on older server versions.static booleanisChatComponent(Object object) Check if the provided object is instance of chat component
or is a String that follow the ChatComponent format.static StringConvert String or chat component to json component.static StringtoJsonOrNull(Object component) Convert String or chat component to json component.static ObjecttoPrettyComponent(Object tag, String indent) Format the provided tag into pretty string as chat component.static ObjecttoPrettyComponent(Object tag, String indent, String[] palette) Format the provided tag into pretty string as chat component.static StringtoPrettyJson(Object tag, String indent) Format the provided tag into pretty string as json component.static StringtoPrettyJson(Object tag, String indent, String[] palette) Format the provided tag into pretty string as json component.static StringtoPrettyString(Object tag, String indent) Format the provided tag into pretty string.static StringtoPrettyString(Object tag, String indent, String[] palette) Format the provided tag into pretty string.static StringConvert json String or chat component to string.static StringtoStringOrNull(Object component) Convert json String or chat component to string.static ObjectConvert chat component to nbt.static ObjecttoTagOrNull(Object component) Convert chat component to nbt.
-
Field Details
-
NBT_PALETTE
Default color palette for pretty nbt. -
NBT_PALETTE_HEX
Color palette with hex colors introduced on MC 1.16. -
NBT_PALETTE_BUNGEE
Color palette with hex colors introduced on MC 1.16 using Bungeecord chat format. -
NBT_PALETTE_MINIMESSAGE
Color palette using Adventure MiniMessage format. -
CODEC
Component codec.
-
-
Method Details
-
isChatComponent
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
-
fromString
-
fromTag
-
toJson
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
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
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
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
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
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
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
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
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
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
-
toPrettyString
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.
-