Record Class ChatComponentSnapshot

java.lang.Object
java.lang.Record
nl.pim16aap2.lightkeeper.framework.ChatComponentSnapshot
Record Components:
json - Native component-codec JSON, retained verbatim.

public record ChatComponentSnapshot(String json) extends Record
Frozen native chat-component JSON with shared literal-text and effective-click interpretation.

Literal strings, component arrays and extra children are supported, including inherited click events. Translation keys, selectors, scores, keybinds and hover contents are not rendered as literal main-message text.

  • Constructor Details

    • ChatComponentSnapshot

      public ChatComponentSnapshot(String json)
      Validates the immutable JSON input reference without decoding it eagerly.
  • Method Details

    • clickRunCommand

      public Optional<String> clickRunCommand()
      Returns:
      First run-command payload, or empty for absent actions or malformed input.
    • clickSuggestedCommand

      public Optional<String> clickSuggestedCommand()
      Returns:
      First suggest-command payload verbatim, including trailing spaces; empty for malformed input.
    • clickActions

      public List<ChatComponentSnapshot.ClickAction> clickActions()
      Decodes contiguous literal runs and their effective click actions.

      Adjacent literal runs with the same action and payload are combined. Non-clickable text and opaque non-literal content prevent accidental association across unrelated portions of a message.

      Returns:
      Immutable literal click actions; textless style nodes may carry an empty text run.
      Throws:
      IllegalArgumentException - When JSON or supported component structure cannot be decoded.
    • hasClickableText

      public boolean hasClickableText(String fragment)
      Matches decoded literal text associated with an effective click event.
      Parameters:
      fragment - Nonempty literal text fragment.
      Returns:
      Whether a matching clickable literal run exists.
    • hasRunCommand

      public boolean hasRunCommand(String fragment, String command)
      Matches literal text and its exact run-command payload.
      Parameters:
      fragment - Nonempty literal text fragment.
      command - Exact command payload.
      Returns:
      Whether the same effective click action matches both requirements.
    • hasSuggestedCommand

      public boolean hasSuggestedCommand(String fragment, String command)
      Matches literal text and its exact suggest-command payload, preserving spaces.
      Parameters:
      fragment - Nonempty literal text fragment.
      command - Exact suggested payload.
      Returns:
      Whether the same effective click action matches both requirements.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • json

      public String json()
      Returns the value of the json record component.
      Returns:
      the value of the json record component