Package me.neznamy.tab.api.chat
Class IChatBaseComponent
java.lang.Object
me.neznamy.tab.api.chat.IChatBaseComponent
- Direct Known Subclasses:
ChatComponentEntity,DeserializedChatComponent,WrappedChatComponent
A class representing the n.m.s.IChatBaseComponent class to make work with it much easier
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new empty componentIChatBaseComponent(String text) Constructs new instance with given textIChatBaseComponent(IChatBaseComponent component) Constructs a new component which is a clone of provided component -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExtra(IChatBaseComponent child) Appends provided component as extra componentstatic IChatBaseComponentdeserialize(String json) Deserializes string and returns created component.static IChatBaseComponentfromColoredText(String originalText) Returns organized component from colored textgetExtra()Returns list of extra components.Returns chat modifier of this componentgetText()Returns text of this componentstatic IChatBaseComponentoptimizedComponent(String text) Returns the most optimized component based on text.setExtra(List<IChatBaseComponent> components) Sets full list of extra components to given list.voidsetModifier(ChatModifier modifier) Sets modifier to provided valuevoidChanges text of this componentConverts the component into flat text with used colors (including rgb) and magic codesConverts this component into a simple text with legacy colors (the closest match if color is set to RGB)Returns raw text without colors, only works correctly when component is organizedtoString()Converts the component to a string representing the serialized component.toString(ProtocolVersion clientVersion) Serializes this component with colors based on client version.toString(ProtocolVersion clientVersion, boolean sendTranslatableIfEmpty) Serializes this component with colors based on client version.
-
Constructor Details
-
IChatBaseComponent
public IChatBaseComponent()Constructs a new empty component -
IChatBaseComponent
Constructs a new component which is a clone of provided component- Parameters:
component- component to clone
-
IChatBaseComponent
Constructs new instance with given text- Parameters:
text- text to display
-
-
Method Details
-
getExtra
Returns list of extra components. If no extra components are defined, returns empty list.- Returns:
- list of extra components
-
setExtra
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- ifcomponentsis an empty list
-
addExtra
Appends provided component as extra component- Parameters:
child- component to append
-
getText
Returns text of this component- Returns:
- text of this component
-
getModifier
Returns chat modifier of this component- Returns:
- chat modifier of this component
-
setModifier
Sets modifier to provided value- Parameters:
modifier- modifier to set value to- Throws:
IllegalArgumentException- ifmodifieris null
-
setText
Changes text of this component- Parameters:
text- text to show
-
deserialize
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
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. -
toString
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
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 forsendTranslatableIfEmpty- whether empty translatable should be sent if text is empty or not- Returns:
- serialized string
-
fromColoredText
Returns organized component from colored text- Parameters:
originalText- text to convert- Returns:
- organized component from colored text
-
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
Returns raw text without colors, only works correctly when component is organized- Returns:
- raw text in this component and all child components
-
toFlatText
Converts the component into flat text with used colors (including rgb) and magic codes- Returns:
- converted text
-
optimizedComponent
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
-