Class KMessageSingle
KMessage
for single-line interactive messages.
This class represents a message consisting of a single line of text with optional interactive actions. It provides methods for combining messages, adding content, and creating messages with predefined interactive behaviors.
The class supports method chaining for fluent message construction and includes static factory methods for creating common types of interactive messages such as clickable commands, hover text, and URL links.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty single-line message.KMessageSingle
(@NotNull String line) Creates a new single-line message with the specified text.KMessageSingle
(@NotNull String line, @NotNull Action... actions) Creates a new single-line message with the specified text and actions.KMessageSingle
(@NotNull String line, @NotNull List<Action> actions) Creates a new single-line message with the specified text and action list. -
Method Summary
Modifier and TypeMethodDescription@NotNull KMessageSingle
add
(@NotNull KMessageSingle message) Adds another single-line message to this message.@NotNull KMessageSingle
Adds text content to this message.getLines()
Retrieves the lines of text that make up this message.static @NotNull KMessageSingle
ofClickOpenURL
(@NotNull String line, @NotNull String url) Creates a single-line message that opens a URL when clicked.static @NotNull KMessageSingle
ofClickRunCommand
(@NotNull String line, @NotNull String command) Creates a single-line message that executes a command when clicked.static @NotNull KMessageSingle
ofClickSuggestCommand
(@NotNull String line, @NotNull String suggestion) Creates a single-line message that suggests a command when clicked.static @NotNull KMessageSingle
ofHoverItem
(@NotNull String line, @NotNull ItemStack item) Creates a single-line message with hover item display.static @NotNull KMessageSingle
ofHoverText
(@NotNull String line, @NotNull String text) Creates a single-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
-
KMessageSingle
public KMessageSingle()Creates a new empty single-line message. -
KMessageSingle
Creates a new single-line message with the specified text.- Parameters:
line
- the text content of the message
-
KMessageSingle
Creates a new single-line message with the specified text and actions.- Parameters:
line
- the text content of the messageactions
- theAction
instances to attach to this message
-
KMessageSingle
Creates a new single-line message with the specified text and action list.- Parameters:
line
- the text content of the messageactions
- the list ofAction
instances to attach to this message
-
-
Method Details
-
add
Adds another single-line message to this message.This method concatenates the text content of the provided message to this message's line and adds all of its actions to this message's action list. This allows for combining multiple message parts into a single cohesive message.
- Parameters:
message
- theKMessageSingle
to add to this message- Returns:
- this
KMessageSingle
instance for method chaining
-
add
Adds text content to this message.This method appends the provided content to the existing message line. This is useful for building up message content incrementally or adding dynamic content to existing messages.
- Parameters:
content
- the text content to append to this message- Returns:
- this
KMessageSingle
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 single-line messages, this returns a list containing only the single line of text that makes up this message.
-
ofClickRunCommand
@NotNull public static @NotNull KMessageSingle ofClickRunCommand(@NotNull @NotNull String line, @NotNull @NotNull String command) Creates a single-line message that executes a command when clicked.This factory method creates a message where the entire line 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
KMessageSingle
with the click action configured
-
ofClickSuggestCommand
@NotNull public static @NotNull KMessageSingle ofClickSuggestCommand(@NotNull @NotNull String line, @NotNull @NotNull String suggestion) Creates a single-line message that suggests a command when clicked.This factory method creates a message where the entire line 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
KMessageSingle
with the click suggestion configured
-
ofClickOpenURL
@NotNull public static @NotNull KMessageSingle ofClickOpenURL(@NotNull @NotNull String line, @NotNull @NotNull String url) Creates a single-line message that opens a URL when clicked.This factory method creates a message where the entire line 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
KMessageSingle
with the URL click action configured
-
ofHoverText
@NotNull public static @NotNull KMessageSingle ofHoverText(@NotNull @NotNull String line, @NotNull @NotNull String text) Creates a single-line message with hover text.This factory method creates a message where the entire line 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
KMessageSingle
with the hover text configured
-
ofHoverItem
@NotNull public static @NotNull KMessageSingle ofHoverItem(@NotNull @NotNull String line, @NotNull @NotNull ItemStack item) Creates a single-line message with hover item display.This factory method creates a message where the entire line 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
KMessageSingle
with the hover item configured
-