Class KMessageBlock
KMessage
for multi-line interactive messages.
This class represents a message consisting of multiple lines of text with optional interactive actions. It provides methods for adding lines dynamically and includes static factory methods for creating common types of interactive multi-line messages such as clickable commands, hover text, and URL links.
The class supports method chaining for fluent message construction and handles line management for complex multi-line displays like help text, menus, or information panels.
-
Constructor Summary
ConstructorsConstructorDescriptionKMessageBlock
(@NotNull String line) Creates a new multi-line message with a single initial line.KMessageBlock
(@NotNull String... lines) Creates a new multi-line message with the specified lines.KMessageBlock
(@NotNull String line, @NotNull Action... actions) Creates a new multi-line message with a single line and actions.KMessageBlock
(@NotNull String line, @NotNull List<Action> actions) Creates a new multi-line message with a single line and action list.KMessageBlock
(@NotNull List<String> lines) Creates a new multi-line message with the specified list of lines.KMessageBlock
(@NotNull List<String> lines, @NotNull Action... actions) Creates a new multi-line message with the specified lines and actions.KMessageBlock
(@NotNull List<String> lines, @NotNull List<Action> actions) Creates a new multi-line message with the specified lines and action list. -
Method Summary
Modifier and TypeMethodDescription@NotNull KMessageBlock
Adds a new line to this multi-line message.getLines()
Retrieves the lines of text that make up this message.static @NotNull KMessageBlock
ofClickOpenURL
(@NotNull String line, @NotNull String url) Creates a multi-line message that opens a URL when clicked.static @NotNull KMessageBlock
ofClickRunCommand
(@NotNull String line, @NotNull String command) Creates a multi-line message that executes a command when clicked.static @NotNull KMessageBlock
ofClickSuggestCommand
(@NotNull String line, @NotNull String suggestion) Creates a multi-line message that suggests a command when clicked.static @NotNull KMessageBlock
ofHoverItem
(@NotNull String line, @NotNull ItemStack item) Creates a multi-line message with hover item display.static @NotNull KMessageBlock
ofHoverText
(@NotNull String line, @NotNull String text) Creates a multi-line message with hover text.Methods inherited from class com.kamikazejam.kamicommon.nms.abstraction.chat.KMessage
addAction, addActions, addClickOpenURL, addClickRunCommand, addClickSuggestCommand, addHoverItem, addHoverText
-
Constructor Details
-
KMessageBlock
Creates a new multi-line message with a single initial line.- Parameters:
line
- the initial line of text for the message
-
KMessageBlock
Creates a new multi-line message with the specified lines.Note: This constructor converts the varargs array to a string representation and adds it as a single line. For multiple separate lines, use the
List
constructor instead.- Parameters:
lines
- the lines to include in the message
-
KMessageBlock
Creates a new multi-line message with the specified list of lines.- Parameters:
lines
- the list of text lines for the message
-
KMessageBlock
Creates a new multi-line message with a single line and actions.- Parameters:
line
- the initial line of text for the messageactions
- theAction
instances to attach to this message
-
KMessageBlock
Creates a new multi-line message with a single line and action list.- Parameters:
line
- the initial line of text for the messageactions
- the list ofAction
instances to attach to this message
-
KMessageBlock
Creates a new multi-line message with the specified lines and actions.- Parameters:
lines
- the list of text lines for the messageactions
- theAction
instances to attach to this message
-
KMessageBlock
Creates a new multi-line message with the specified lines and action list.- Parameters:
lines
- the list of text lines for the messageactions
- the list ofAction
instances to attach to this message
-
-
Method Details
-
addLine
Adds a new line to this multi-line message.This method appends the specified line to the end of the current line list. This is useful for building up message content dynamically or adding lines based on runtime conditions.
- Parameters:
line
- the text line to add to this message- Returns:
- this
KMessageBlock
instance for method chaining
-
getLines
Retrieves the lines of text that make up this message.This abstract method must be implemented by subclasses to define how the message content is structured. For single-line messages, this returns a list with one element. For multi-line messages, this returns all lines in order.
For multi-line messages, this returns the complete list of lines that make up this message block.
-
ofClickRunCommand
@NotNull public static @NotNull KMessageBlock ofClickRunCommand(@NotNull @NotNull String line, @NotNull @NotNull String command) Creates a multi-line message that executes a command when clicked.This factory method creates a message where the entire content is clickable and executes the specified command when clicked by the player. The command will be run as if the player typed it in chat.
- Parameters:
line
- the text content to display and make clickablecommand
- the command to execute when clicked (without leading slash)- Returns:
- a new
KMessageBlock
with the click action configured
-
ofClickSuggestCommand
@NotNull public static @NotNull KMessageBlock ofClickSuggestCommand(@NotNull @NotNull String line, @NotNull @NotNull String suggestion) Creates a multi-line message that suggests a command when clicked.This factory method creates a message where the entire content is clickable and suggests the specified command in the player's chat input when clicked. The player can then modify or execute the suggested command.
- Parameters:
line
- the text content to display and make clickablesuggestion
- the command to suggest when clicked (without leading slash)- Returns:
- a new
KMessageBlock
with the click suggestion configured
-
ofClickOpenURL
@NotNull public static @NotNull KMessageBlock ofClickOpenURL(@NotNull @NotNull String line, @NotNull @NotNull String url) Creates a multi-line message that opens a URL when clicked.This factory method creates a message where the entire content is clickable and opens the specified URL in the player's default web browser when clicked.
- Parameters:
line
- the text content to display and make clickableurl
- the URL to open when clicked- Returns:
- a new
KMessageBlock
with the URL click action configured
-
ofHoverText
@NotNull public static @NotNull KMessageBlock ofHoverText(@NotNull @NotNull String line, @NotNull @NotNull String text) Creates a multi-line message with hover text.This factory method creates a message where the entire content shows custom hover text when the player hovers their cursor over it.
- Parameters:
line
- the text content to display and make hoverabletext
- the text to show in the hover tooltip- Returns:
- a new
KMessageBlock
with the hover text configured
-
ofHoverItem
@NotNull public static @NotNull KMessageBlock ofHoverItem(@NotNull @NotNull String line, @NotNull @NotNull ItemStack item) Creates a multi-line message with hover item display.This factory method creates a message where the entire content shows an item tooltip when the player hovers their cursor over it.
- Parameters:
line
- the text content to display and make hoverableitem
- theItemStack
to show in the hover tooltip- Returns:
- a new
KMessageBlock
with the hover item configured
-