Interface ChatComponent<C extends ChatComponent<C>>

Type Parameters:
C - concrete component type returned by the fluent methods, enabling type-safe chaining in subinterfaces
All Known Subinterfaces:
MultiComponent

public interface ChatComponent<C extends ChatComponent<C>>
A mutable, fluent Bungee/Spigot chat component that supports optional click and hover events.

A ChatComponent wraps a raw message string and lets you attach interactive events (setClick(me.croabeast.prismatic.chat.ChatComponent.Click, java.lang.String), setHover(java.util.List<java.lang.String>), setHoverItem(java.lang.String)) through a builder-style API. When you are done configuring the component, call compile(Player) to produce the BaseComponent array expected by player.spigot().sendMessage(...).

The simplest way to create an instance is through the factory methods:


 BaseComponent[] msg = PrismaticAPI.chatComponent("<#ff8800>Click me!")
         .setClick("run", "/help")
         .setHover("Open help<n>Second line")
         .compile(player);

 player.spigot().sendMessage(msg);
 

URLs found inside the message text are automatically converted into OPEN_URL click events during compile(Player).

Since:
1.5.0
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Enumeration of the click actions that a ChatComponent can carry.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Pattern
    URL detector used to automatically attach ChatComponent.Click.OPEN_URL click events to any URL-only segment found inside the raw message during compile(Player).
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull net.md_5.bungee.api.chat.BaseComponent[]
    compile(org.bukkit.entity.Player player)
    Compiles this component into a BaseComponent array ready for Spigot/Bungee chat APIs.
    static ChatComponent<?>
    fromString(String message)
    Creates a new ChatComponent backed by the default Prismatic processor.
    static ChatComponent<?>
    fromString(ChatProcessor processor, String message)
    Creates a new ChatComponent backed by the given ChatProcessor.
    @NotNull String
    Returns the raw, un-colorized message text stored in this component.
    boolean
    Returns true when this component has at least one click or hover event attached.
    Returns the concrete implementation instance of this component.
    default C
    Attaches a click event from a compact "action:payload" string.
    default C
    setClick(String click, String input)
    Attaches a click event to this component using a string alias for the action.
    Attaches a click event to this component.
    setHover(String string)
    Sets a text hover event from a single, optionally multi-line string.
    default C
    setHover(String... array)
    Sets a text hover event whose content is drawn from the provided lines.
    Sets a text hover event whose content is drawn from the provided lines.
    Sets an item hover event whose content is described by an NBT/SNBT JSON string.
    setMessage(@NotNull String message)
    Replaces the raw message text of this component.
  • Field Details

    • URL_PATTERN

      static final Pattern URL_PATTERN
      URL detector used to automatically attach ChatComponent.Click.OPEN_URL click events to any URL-only segment found inside the raw message during compile(Player).

      The pattern matches both http:// and https:// URLs as well as bare www. prefixed links.

  • Method Details

    • getMessage

      @NotNull @NotNull String getMessage()
      Returns the raw, un-colorized message text stored in this component.
      Returns:
      the raw message string; never null
    • setMessage

      @NotNull C setMessage(@NotNull @NotNull String message)
      Replaces the raw message text of this component.
      Parameters:
      message - the new raw message; must not be null
      Returns:
      this component for fluent chaining
    • setClick

      @NotNull C setClick(ChatComponent.Click click, String input)
      Attaches a click event to this component.
      Parameters:
      click - the click action to perform when the player clicks the text
      input - the payload delivered to the click action (command, URL, etc.)
      Returns:
      this component for fluent chaining
    • setClick

      @NotNull default C setClick(String click, String input)
      Attaches a click event to this component using a string alias for the action.

      The alias is resolved through ChatComponent.Click.fromName(String); unknown aliases fall back to ChatComponent.Click.SUGGEST.

      Parameters:
      click - a case-insensitive alias for the desired click action (e.g. "run", "suggest", "url")
      input - the payload delivered to the click action
      Returns:
      this component for fluent chaining
    • setClick

      @NotNull default C setClick(String input)
      Attaches a click event from a compact "action:payload" string.

      The string is split on the first ':' character; surrounding quotation marks are stripped before parsing. Example: "run:/spawn" or "url:https://example.com".

      Parameters:
      input - combined action and payload string
      Returns:
      this component for fluent chaining
    • setHover

      @NotNull C setHover(List<String> list)
      Sets a text hover event whose content is drawn from the provided lines.

      Each element in the list is rendered as a separate line in the tooltip shown to the player. The lines are colorized via the component's processor when the component is compiled.

      Parameters:
      list - ordered list of hover text lines; must not be null
      Returns:
      this component for fluent chaining
    • setHover

      @NotNull default C setHover(String... array)
      Sets a text hover event whose content is drawn from the provided lines.

      Convenience overload for setHover(List).

      Parameters:
      array - ordered hover text lines
      Returns:
      this component for fluent chaining
    • setHover

      @NotNull C setHover(String string)
      Sets a text hover event from a single, optionally multi-line string.

      The string is split into lines using the processor's line separator regex (default: <n>). Surrounding hover:"..." markup is stripped before splitting.

      Parameters:
      string - raw hover content, may contain <n> separators
      Returns:
      this component for fluent chaining
    • setHoverItem

      @NotNull C setHoverItem(String json)
      Sets an item hover event whose content is described by an NBT/SNBT JSON string.

      The payload can be provided either as a raw JSON string or as a Base64-encoded string prefixed with "b64:". This is useful for including special characters or complex item NBT without escaping issues.

      Parameters:
      json - raw item JSON or a "b64:<base64>" encoded payload
      Returns:
      this component for fluent chaining
    • hasEvents

      boolean hasEvents()
      Returns true when this component has at least one click or hover event attached.

      This can be used to decide whether to wrap the compiled output in additional markup or to skip unnecessary processing when no interactive events were configured.

      Returns:
      true if a click, text hover or item hover event is present
    • compile

      @NotNull @NotNull net.md_5.bungee.api.chat.BaseComponent[] compile(org.bukkit.entity.Player player)
      Compiles this component into a BaseComponent array ready for Spigot/Bungee chat APIs.

      The message text is colorized through the component's ChatProcessor using the provided player context so that player-aware hex fallback is applied correctly. URLs found inside the message are automatically converted to ChatComponent.Click.OPEN_URL events.

      Parameters:
      player - the player who will receive the message, used for version-aware color output; may be null to force the legacy fallback
      Returns:
      a non-empty array of compiled BaseComponent objects
    • instance

      @NotNull C instance()
      Returns the concrete implementation instance of this component.

      Implementations return this; this method exists so that fluent setters defined in default methods on sub-interfaces can return the correct concrete type.

      Returns:
      this component instance
    • fromString

      static ChatComponent<?> fromString(ChatProcessor processor, String message)
      Creates a new ChatComponent backed by the given ChatProcessor.
      Parameters:
      processor - the text processor used to colorize the message and hover content
      message - the initial raw message text
      Returns:
      a new ChatComponent instance
    • fromString

      static ChatComponent<?> fromString(String message)
      Creates a new ChatComponent backed by the default Prismatic processor.

      This is the recommended factory method for most use cases. It uses ChatProcessor.prismatic() which delegates colorization to PrismaticAPI.

      Parameters:
      message - the initial raw message text
      Returns:
      a new ChatComponent instance