java.lang.Object
com.kamikazejam.kamicommon.nms.abstraction.chat.KMessage
com.kamikazejam.kamicommon.nms.abstraction.chat.impl.KMessageSingle

public class KMessageSingle extends KMessage
Implementation of 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 Details

    • KMessageSingle

      public KMessageSingle()
      Creates a new empty single-line message.
    • KMessageSingle

      public KMessageSingle(@NotNull @NotNull String line)
      Creates a new single-line message with the specified text.
      Parameters:
      line - the text content of the message
    • KMessageSingle

      public KMessageSingle(@NotNull @NotNull String line, @NotNull @NotNull Action... actions)
      Creates a new single-line message with the specified text and actions.
      Parameters:
      line - the text content of the message
      actions - the Action instances to attach to this message
    • KMessageSingle

      public KMessageSingle(@NotNull @NotNull String line, @NotNull @NotNull List<Action> actions)
      Creates a new single-line message with the specified text and action list.
      Parameters:
      line - the text content of the message
      actions - the list of Action instances to attach to this message
  • Method Details

    • add

      @NotNull public @NotNull KMessageSingle add(@NotNull @NotNull KMessageSingle message)
      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 - the KMessageSingle to add to this message
      Returns:
      this KMessageSingle instance for method chaining
    • add

      @NotNull public @NotNull KMessageSingle add(@NotNull @NotNull String content)
      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

      @NotNull public @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.

      For single-line messages, this returns a list containing only the single line of text that makes up this message.

      Specified by:
      getLines in class KMessage
      Returns:
      the list of text lines that make 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 clickable
      command - 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 clickable
      suggestion - 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 clickable
      url - 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 hoverable
      text - 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 hoverable
      item - the ItemStack to show in the hover tooltip
      Returns:
      a new KMessageSingle with the hover item configured