java.lang.Object
com.kamikazejam.kamicommon.nms.abstraction.chat.KMessage
Direct Known Subclasses:
KMessageBlock, KMessageSingle

public abstract class KMessage extends Object
Abstract base class for interactive messages that can contain rich text, actions, and events for enhanced player communication.

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 Details

    • KMessage

      public KMessage()
      Creates a new empty message with no actions.
    • KMessage

      public KMessage(@NotNull @NotNull Action... actions)
      Creates a new message with the specified actions.
      Parameters:
      actions - the Action instances to attach to this message
    • KMessage

      public KMessage(@NotNull @NotNull List<Action> actions)
      Creates a new message with the specified list of actions.
      Parameters:
      actions - the list of Action instances to attach to this message
  • Method Details

    • getLines

      @NotNull public abstract @NotNull List<String> 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

      @NotNull public final @NotNull KMessage addAction(@NotNull @NotNull Action action)
      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.

      Parameters:
      action - the Action to add to this message
      Returns:
      this KMessage instance for method chaining
    • addActions

      @NotNull public final @NotNull KMessage addActions(@NotNull @NotNull List<Action> actions)
      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.

      Parameters:
      actions - the list of Action instances to add
      Returns:
      this KMessage instance for method chaining
    • 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.

      Parameters:
      placeholder - the placeholder text to replace in the message
      replacement - the text to display in place of the placeholder
      item - the ItemStack to show in the hover tooltip
      Returns:
      this KMessage instance for method chaining
    • 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 message
      replacement - the text to display in place of the placeholder
      command - 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 message
      replacement - the text to display in place of the placeholder
      suggestion - 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 message
      replacement - the text to display in place of the placeholder
      url - 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 message
      replacement - the text to display in place of the placeholder
      text - the text to show in the hover tooltip
      Returns:
      this KMessage instance for method chaining