Interface MultiComponent
- All Superinterfaces:
ChatComponent<MultiComponent>
ChatComponent that splits a raw message into interactive segments
and manages them as a unified, fluent unit.
MultiComponent understands a compact markup language for attaching click and
hover events to specific portions of text. The default markup format is:
<action:"argument">visible text</text>
<action:"arg1"|action2:"arg2">visible text</text>
For example:
BaseComponent[] msg = PrismaticAPI
.multiComponent(
"<run:\"/spawn\">&aGo to Spawn</text>" +
" &7| " +
"<suggest:\"/msg \">&bSend a Message</text>"
)
.compile(player);
player.spigot().sendMessage(msg);
Segments that contain no markup tags are treated as plain text. URLs found in plain
segments are automatically wrapped in an OPEN_URL
click event.
The setClick* / setHover* / setHoverItem* methods come in two
flavors: ones that target only the last segment (matching the behavior of
ChatComponent) and ones suffixed with ToAll that apply the event to
every segment in the component.
Color continuity is maintained automatically: if a segment does not start with an explicit color code, the last color from the preceding segment is prepended, preventing unexpected color resets between segments.
- Since:
- 1.5.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface me.croabeast.prismatic.chat.ChatComponent
ChatComponent.Click -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringRegex fragment that matches all recognized click-action aliases accepted in markup.static final ChatFormat<ChatComponent<?>> The defaultChatFormatinstance used when aMultiComponentis created without an explicit format.static final StringThe default markup regex used byDEFAULT_FORMATto identify interactive segments.Fields inherited from interface me.croabeast.prismatic.chat.ChatComponent
URL_PATTERN -
Method Summary
Modifier and TypeMethodDescriptiondefault @NotNull MultiComponentAppends the string representation of an object as a new raw-text segment.@NotNull MultiComponentParses the given raw text and appends the resulting segments to this component.@NotNull MultiComponentappend(@NotNull ChatComponent<?> component) Appends an existingChatComponentas a new segment at the end of this component.@NotNull MultiComponentcopy()Returns a deep copy of this multi-component, including all current segments and the current format.static MultiComponentfromString(String message) Creates a newMultiComponentbacked by the default Prismatic processor.static MultiComponentfromString(ChatProcessor processor, String message) Creates a newMultiComponentbacked by a customChatProcessor.@NotNull ChatFormat<ChatComponent<?>> Returns theChatFormatused by this component to parse markup and serialize segments back to their string representation.default @NotNull MultiComponentsetClickToAll(String input) Applies a click event to every segment from a compact"action:payload"string.default @NotNull MultiComponentsetClickToAll(String click, String input) Applies a click event to every segment in this component using a string alias.@NotNull MultiComponentsetClickToAll(ChatComponent.Click click, String input) Applies a click event to every segment in this component.@NotNull MultiComponentsetFormat(@NotNull ChatFormat<ChatComponent<?>> format) Replaces theChatFormatused by this component.@NotNull MultiComponentsetHoverItemToAll(String json) Applies an item hover event to every segment in this component.@NotNull MultiComponentsetHoverToAll(String string) Applies a text hover event to every segment from a single, optionally multi-line string.default @NotNull MultiComponentsetHoverToAll(String... strings) Applies a text hover event to every segment in this component.@NotNull MultiComponentsetHoverToAll(List<String> list) Applies a text hover event to every segment in this component.default @NotNull MultiComponentsetMessage(@NotNull String message) Unsupported — the message of aMultiComponentis derived from its individual segments and cannot be replaced as a single string.default @NotNull StringSerializes this component back to its formatted markup string using the currentChatFormat.Methods inherited from interface me.croabeast.prismatic.chat.ChatComponent
compile, getMessage, hasEvents, instance, setClick, setClick, setClick, setHover, setHover, setHover, setHoverItem
-
Field Details
-
CLICK_REGEX
Regex fragment that matches all recognized click-action aliases accepted in markup.This fragment is incorporated into
DEFAULT_REGEXand can be reused by customChatFormatimplementations that want to extend the default syntax while staying consistent with the recognized action names.Recognized aliases include:
execute,click,run,run_command,suggest,suggest_command,url,open_url,file,open_file,page,change_page,copyandcopy_to_clipboard.- See Also:
-
DEFAULT_REGEX
The default markup regex used byDEFAULT_FORMATto identify interactive segments.A segment matches when it is wrapped in opening and closing tags of the form:
<action:"argument">text</text> <action:"arg1"|action2:"arg2">text</text>Recognized opening-tag actions are:
hover_item,hoverand any alias listed inCLICK_REGEX. The closing tag is always</text>.- See Also:
-
DEFAULT_FORMAT
The defaultChatFormatinstance used when aMultiComponentis created without an explicit format.It parses
DEFAULT_REGEXmarkup and wires up the correspondingChatComponentevents. It also implementsChatFormat.toFormattedString(T)so that components can be round-tripped back to markup.
-
-
Method Details
-
getFormat
Returns theChatFormatused by this component to parse markup and serialize segments back to their string representation.- Returns:
- the current format; never
null
-
setFormat
Replaces theChatFormatused by this component.Changing the format does not reparse already-created segments. It only affects how subsequent calls to
append(String)parse new text, and howtoFormattedString()serializes the component.- Parameters:
format- the new format; must not benull- Returns:
- this component for fluent chaining
-
copy
Returns a deep copy of this multi-component, including all current segments and the current format.Modifying the copy does not affect the original.
- Returns:
- a new
MultiComponentwith the same segments and format
-
append
Parses the given raw text and appends the resulting segments to this component.The text is processed by the current
ChatFormat: markup segments are extracted and interactive events are wired up, while plain text spans are kept as-is. URLs in plain spans are automatically turned intoChatComponent.Click.OPEN_URLevents.- Parameters:
message- the raw text to parse and append- Returns:
- this component for fluent chaining
-
append
Appends an existingChatComponentas a new segment at the end of this component.The component is not re-parsed; it is added directly. Color continuity is still maintained between the new segment and its predecessor.
- Parameters:
component- the component to append; must not benull- Returns:
- this component for fluent chaining
-
append
Appends the string representation of an object as a new raw-text segment.Equivalent to
append(String.valueOf(object)).- Parameters:
object- the value whosetoString()is appended- Returns:
- this component for fluent chaining
-
setClickToAll
Applies a click event to every segment in this component.- Parameters:
click- the click actioninput- the click payload- Returns:
- this component for fluent chaining
-
setClickToAll
Applies a click event to every segment in this component using a string alias.The alias is resolved via
ChatComponent.Click.fromName(String).- Parameters:
click- a case-insensitive click-action aliasinput- the click payload- Returns:
- this component for fluent chaining
-
setClickToAll
Applies a click event to every segment from a compact"action:payload"string.- Parameters:
input- combined action and payload string (e.g."run:/spawn")- Returns:
- this component for fluent chaining
-
setHoverToAll
Applies a text hover event to every segment in this component.- Parameters:
list- ordered list of hover text lines- Returns:
- this component for fluent chaining
-
setHoverToAll
Applies a text hover event to every segment in this component.Convenience overload for
setHoverToAll(List).- Parameters:
strings- ordered hover text lines- Returns:
- this component for fluent chaining
-
setHoverToAll
Applies a text hover event to every segment from a single, optionally multi-line string.The string is split into lines using the processor's line-separator regex (default:
<n>).- Parameters:
string- raw hover content; may contain<n>separators- Returns:
- this component for fluent chaining
-
setHoverItemToAll
Applies an item hover event to every segment in this component.- Parameters:
json- raw item JSON or"b64:<base64>"encoded payload- Returns:
- this component for fluent chaining
-
toFormattedString
Serializes this component back to its formatted markup string using the currentChatFormat.The result can be passed to
fromString(String)to reconstruct an equivalent component, making it useful for persistence or network transport.- Returns:
- the formatted markup string representation of this component
-
setMessage
Unsupported — the message of aMultiComponentis derived from its individual segments and cannot be replaced as a single string.- Specified by:
setMessagein interfaceChatComponent<MultiComponent>- Parameters:
message- ignored- Returns:
- never returns normally
- Throws:
IllegalStateException- always
-
fromString
Creates a newMultiComponentbacked by a customChatProcessor.The raw message is immediately parsed using
DEFAULT_FORMAT.- Parameters:
processor- the text processor used to colorize segments and hover contentmessage- the initial raw message text, parsed into segments on construction- Returns:
- a new
MultiComponentinstance
-
fromString
Creates a newMultiComponentbacked by the default Prismatic processor.This is the recommended factory method for most use cases. The raw message is immediately parsed using
DEFAULT_FORMAT.- Parameters:
message- the initial raw message text, parsed into segments on construction- Returns:
- a new
MultiComponentinstance
-