Interface MultiComponent
- All Superinterfaces:
BaseBuilder<MultiComponent>,ChatComponent<MultiComponent>,Copyable<MultiComponent>
ChatComponent segments and allows fluent manipulation of all segments.
A MultiComponent extends ChatComponent to support
complex text containing interleaved click and hover directives. It also
implements Copyable to produce deep copies of itself.
Parsing and formatting is driven by a Format obtained via
getFormat(), which defaults to DEFAULT_FORMAT.
New instances can be created via the static fromString(...) methods.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface me.croabeast.takion.chat.ChatComponent
ChatComponent.Click -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringRegular expression for matching click actions in the format strings.static final Format<ChatComponent<?>> The defaultFormatinstance used by newMultiComponentobjects.static final StringDefault format pattern for parsing text with optional hover and click directives.Fields inherited from interface me.croabeast.takion.chat.ChatComponent
URL_PATTERN -
Method Summary
Modifier and TypeMethodDescriptiondefault @NotNull MultiComponentAppends an object'stoString()value as a text segment.@NotNull MultiComponentAppends a raw text segment to this component.@NotNull MultiComponentappend(@NotNull ChatComponent<?> component) Appends an existingChatComponentto this multi-component.static MultiComponentfromString(String message) Creates a newMultiComponentfrom the given raw message, using the defaultTakionLibsingleton.static MultiComponentfromString(TakionLib lib, String message) Creates a newMultiComponentfrom the given raw message, using the specifiedTakionLibinstance for formatting rules.@NotNull Format<ChatComponent<?>> Gets theFormatused to parse and render this component.booleanChecks if this component has any segments with events (click or hover).default @NotNull MultiComponentsetClickToAll(String input) Applies a click action (parsed from a single"action:argument"string) uniformly to all segments.default @NotNull MultiComponentsetClickToAll(String click, String input) Applies a click action (by name) uniformly to all segments.@NotNull MultiComponentsetClickToAll(ChatComponent.Click click, String input) Applies a click action uniformly to all segments in this component.@NotNull MultiComponentsetFormat(@NotNull Format<ChatComponent<?>> format) Sets a customFormatfor parsing this component.@NotNull MultiComponentsetHoverToAll(String string) Applies a single-line hover tooltip uniformly to all segments.default @NotNull MultiComponentsetHoverToAll(String... strings) Applies a hover tooltip (via varargs) uniformly to all segments.@NotNull MultiComponentsetHoverToAll(List<String> list) Applies a hover tooltip uniformly to all segments.default @NotNull MultiComponentsetMessage(@NotNull String message) Set the raw chat text of this component, replacing any existing content.default @NotNull StringConverts this multi-component into a single formatted string.Methods inherited from interface me.croabeast.common.builder.BaseBuilder
instanceMethods inherited from interface me.croabeast.takion.chat.ChatComponent
compile, getMessage, setClick, setClick, setClick, setHover, setHover, setHover
-
Field Details
-
CLICK_REGEX
Regular expression for matching click actions in the format strings.Supports aliases such as "run", "suggest", "url", "file", "page", "copy", etc.
- See Also:
-
DEFAULT_REGEX
Default format pattern for parsing text with optional hover and click directives.Matches constructs of the form:
<action:"argument"[|action:"argument"]>text</text>(case-insensitive).- See Also:
-
DEFAULT_FORMAT
The defaultFormatinstance used by newMultiComponentobjects.Uses
DEFAULT_REGEXand produces individualChatComponentsegments for each match.
-
-
Method Details
-
setMessage
Description copied from interface:ChatComponentSet the raw chat text of this component, replacing any existing content.This method mutates the component in place and returns
thisfor chaining.- Specified by:
setMessagein interfaceChatComponent<MultiComponent>- Parameters:
message- the new message text (nevernull)- Returns:
- this component, with the new message set
-
getFormat
Gets theFormatused to parse and render this component.- Returns:
- the current
Formatfor this multi-component (nevernull)
-
setFormat
Sets a customFormatfor parsing this component.Subsequent invocations of
append(String)or initial parsing viafromString(...)will use this format.- Parameters:
format- the new format to apply (must not benull)- Returns:
- this component, with the format updated
-
hasEvents
boolean hasEvents()Checks if this component has any segments with events (click or hover).- Specified by:
hasEventsin interfaceChatComponent<MultiComponent>- Returns:
trueif any segments have events,falseotherwise
-
append
Appends a raw text segment to this component.The segment is parsed by the current format and merged with existing segments.
- Parameters:
message- the raw text to append- Returns:
- this component, with the text appended
-
append
Appends an existingChatComponentto this multi-component.- Parameters:
component- the component to append (must not benull)- Returns:
- this component, with the segment appended
-
append
Appends an object'stoString()value as a text segment.- Parameters:
object- the object whose string form will be appended- Returns:
- this component, with the object's text appended
-
setClickToAll
Applies a click action uniformly to all segments in this component.- Parameters:
click- the click action type to applyinput- the argument for the click action- Returns:
- this component, with click events applied to every segment
-
setClickToAll
Applies a click action (by name) uniformly to all segments.- Parameters:
click- the click action name or aliasinput- the argument for the click action- Returns:
- this component, with click events applied to every segment
-
setClickToAll
Applies a click action (parsed from a single"action:argument"string) uniformly to all segments.- Parameters:
input- the combined action and argument string- Returns:
- this component, with click events applied to every segment
-
setHoverToAll
Applies a hover tooltip uniformly to all segments.- Parameters:
list- the lines of hover text- Returns:
- this component, with hover events applied to every segment
-
setHoverToAll
Applies a hover tooltip (via varargs) uniformly to all segments.- Parameters:
strings- the lines of hover text- Returns:
- this component, with hover events applied to every segment
-
setHoverToAll
Applies a single-line hover tooltip uniformly to all segments.- Parameters:
string- the hover text line- Returns:
- this component, with hover events applied to every segment
-
toFormattedString
Converts this multi-component into a single formatted string.The string is generated using the current format.
- Returns:
- the formatted string representation of this component
-
fromString
Creates a newMultiComponentfrom the given raw message, using the specifiedTakionLibinstance for formatting rules.- Parameters:
lib- theTakionLibproviding configurationmessage- the raw chat message (may include formatting tokens)- Returns:
- a new
MultiComponentparsed frommessage
-
fromString
Creates a newMultiComponentfrom the given raw message, using the defaultTakionLibsingleton.- Parameters:
message- the raw chat message (may include formatting tokens)- Returns:
- a new
MultiComponentparsed frommessage
-