Class KMessage
- Direct Known Subclasses:
KMessageBlock
,KMessageSingle
This class provides the foundation for creating interactive messages with hover text, click actions, and other rich formatting features. Messages support a placeholder-based action system where specific text patterns are replaced with interactive elements during processing.
All methods in this class support method chaining for fluent message construction. The class handles both translation settings and action management, providing a complete framework for interactive messaging.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal @NotNull KMessage
Adds a single action to this message.final @NotNull KMessage
addActions
(@NotNull List<Action> actions) Adds multiple actions to this message.final @NotNull KMessage
addClickOpenURL
(@NotNull String placeholder, @NotNull String replacement, @NotNull String url) Adds a click-to-open-URL action with the specified placeholder and replacement.final @NotNull KMessage
addClickRunCommand
(@NotNull String placeholder, @NotNull String replacement, @NotNull String command) Adds a click-to-run-command action with the specified placeholder and replacement.final @NotNull KMessage
addClickSuggestCommand
(@NotNull String placeholder, @NotNull String replacement, @NotNull String suggestion) Adds a click-to-suggest-command action with the specified placeholder and replacement.final @NotNull KMessage
addHoverItem
(@NotNull String placeholder, @NotNull String replacement, @NotNull ItemStack item) Adds a hover item action with the specified placeholder and replacement.final @NotNull KMessage
addHoverText
(@NotNull String placeholder, @NotNull String replacement, @NotNull String text) Adds a hover text action with the specified placeholder and replacement.getLines()
Retrieves the lines of text that make up this message.
-
Constructor Details
-
KMessage
public KMessage()Creates a new empty message with no actions. -
KMessage
Creates a new message with the specified actions.- Parameters:
actions
- theAction
instances to attach to this message
-
KMessage
Creates a new message with the specified list of actions.- Parameters:
actions
- the list ofAction
instances to attach to this message
-
-
Method Details
-
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.
- Returns:
- the list of text lines that make up this message
-
addAction
Adds a single action to this message.Actions define interactive elements like hover text, click events, and other rich formatting features. The action's placeholder will be replaced with its replacement text during message processing.
-
addActions
Adds multiple actions to this message.This method adds all actions from the provided list to this message's action collection. Each action will be processed during message sending.
-
addHoverItem
@NotNull public final @NotNull KMessage addHoverItem(@NotNull @NotNull String placeholder, @NotNull @NotNull String replacement, @NotNull @NotNull ItemStack item) Adds a hover item action with the specified placeholder and replacement.This convenience method creates and adds an
Action
that displays an item tooltip when the replacement text is hovered over. The placeholder in the message will be replaced with the replacement text. -
addClickRunCommand
@NotNull public final @NotNull KMessage addClickRunCommand(@NotNull @NotNull String placeholder, @NotNull @NotNull String replacement, @NotNull @NotNull String command) Adds a click-to-run-command action with the specified placeholder and replacement.This convenience method creates and adds an
Action
that executes a command when the replacement text is clicked. The command will be run as if the player typed it in chat.- Parameters:
placeholder
- the placeholder text to replace in the messagereplacement
- the text to display in place of the placeholdercommand
- the command to execute when clicked (without leading slash)- Returns:
- this
KMessage
instance for method chaining
-
addClickSuggestCommand
@NotNull public final @NotNull KMessage addClickSuggestCommand(@NotNull @NotNull String placeholder, @NotNull @NotNull String replacement, @NotNull @NotNull String suggestion) Adds a click-to-suggest-command action with the specified placeholder and replacement.This convenience method creates and adds an
Action
that suggests a command in the player's chat input when the replacement text is clicked. The player can then modify or execute the suggested command.- Parameters:
placeholder
- the placeholder text to replace in the messagereplacement
- the text to display in place of the placeholdersuggestion
- the command to suggest when clicked (without leading slash)- Returns:
- this
KMessage
instance for method chaining
-
addClickOpenURL
@NotNull public final @NotNull KMessage addClickOpenURL(@NotNull @NotNull String placeholder, @NotNull @NotNull String replacement, @NotNull @NotNull String url) Adds a click-to-open-URL action with the specified placeholder and replacement.This convenience method creates and adds an
Action
that opens a URL in the player's default web browser when the replacement text is clicked.- Parameters:
placeholder
- the placeholder text to replace in the messagereplacement
- the text to display in place of the placeholderurl
- the URL to open when clicked- Returns:
- this
KMessage
instance for method chaining
-
addHoverText
@NotNull public final @NotNull KMessage addHoverText(@NotNull @NotNull String placeholder, @NotNull @NotNull String replacement, @NotNull @NotNull String text) Adds a hover text action with the specified placeholder and replacement.This convenience method creates and adds an
Action
that displays custom text in a tooltip when the replacement text is hovered over.- Parameters:
placeholder
- the placeholder text to replace in the messagereplacement
- the text to display in place of the placeholdertext
- the text to show in the hover tooltip- Returns:
- this
KMessage
instance for method chaining
-