Record Class InvalidMessage

java.lang.Object
java.lang.Record
com.winterhavenmc.library.messagebuilder.model.message.InvalidMessage
Record Components:
reason - the reason this message is considered invalid
All Implemented Interfaces:
Message

public record InvalidMessage(String reason) extends Record implements Message
A fallback Message implementation representing an invalid or unrenderable message.

This is returned by the system when a message cannot be composed — for example, due to a null recipient or missing configuration.

Calling send() on an InvalidMessage results in a no-op. The reason for failure is stored in the reason field for debugging or logging purposes.

This class is typically returned by:

  • Message.empty()
  • Internal pipeline safeguards during failed message composition
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of a InvalidMessage record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a reusable InvalidMessage instance representing an empty message caused by a null recipient passed to the compose() method.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the RecordKey identifying the message template used in composition.
    Returns the MacroObjectMap of macro values bound to this message.
    Returns the Recipient.Sendable to whom the message will be sent.
    final int
    Returns a hash code value for this object.
    Returns the value of the reason record component.
    void
    Sends the composed message to the resolved recipient, if valid.
    <K extends Enum<K>, V>
    Message
    setMacro(int quantity, K macro, V value)
    Associates a macro key with a value and explicit quantity, useful for pluralization or contextual substitution that depends on numeric counts.
    <K extends Enum<K>>
    Message
    setMacro(K macro, Duration duration, ChronoUnit lowerBound)
    Associates a duration with the given macro key, using a defined precision.
    <K extends Enum<K>, V>
    Message
    setMacro(K macro, V value)
    Associates a macro key with a value for later substitution during message rendering.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • InvalidMessage

      public InvalidMessage(String reason)
      Creates an instance of a InvalidMessage record class.
      Parameters:
      reason - the value for the reason record component
  • Method Details

    • empty

      public static InvalidMessage empty()
      Returns a reusable InvalidMessage instance representing an empty message caused by a null recipient passed to the compose() method.
      Returns:
      a shared instance of an InvalidMessage with a standard failure reason
    • setMacro

      public <K extends Enum<K>, V> Message setMacro(K macro, V value)
      Description copied from interface: Message
      Associates a macro key with a value for later substitution during message rendering.
      Specified by:
      setMacro in interface Message
      Type Parameters:
      K - the enum type of the macro
      V - the value type
      Parameters:
      macro - the macro key to assign
      value - the value to associate with the macro
      Returns:
      the same Message instance, for fluent chaining
    • setMacro

      public <K extends Enum<K>, V> Message setMacro(int quantity, K macro, V value)
      Description copied from interface: Message
      Associates a macro key with a value and explicit quantity, useful for pluralization or contextual substitution that depends on numeric counts.
      Specified by:
      setMacro in interface Message
      Type Parameters:
      K - the enum type of the macro
      V - the value type
      Parameters:
      quantity - the quantity associated with the value
      macro - the macro key
      value - the object to associate
      Returns:
      the same Message instance, for fluent chaining
    • setMacro

      public <K extends Enum<K>> Message setMacro(K macro, Duration duration, ChronoUnit lowerBound)
      Description copied from interface: Message
      Associates a duration with the given macro key, using a defined precision.
      Specified by:
      setMacro in interface Message
      Type Parameters:
      K - the enum type of the macro
      Parameters:
      macro - the macro key
      duration - the Duration to be formatted and resolved
      lowerBound - the ChronoUnit to control formatting granularity
      Returns:
      the same Message instance, for fluent chaining
    • send

      public void send()
      Description copied from interface: Message
      Sends the composed message to the resolved recipient, if valid.

      No-op if the message is invalid or the recipient is missing or unsupported.

      Specified by:
      send in interface Message
    • getMessageKey

      public RecordKey getMessageKey()
      Description copied from interface: Message
      Returns the RecordKey identifying the message template used in composition.
      Specified by:
      getMessageKey in interface Message
      Returns:
      the message key
    • getRecipient

      public Recipient.Sendable getRecipient()
      Description copied from interface: Message
      Returns the Recipient.Sendable to whom the message will be sent.
      Specified by:
      getRecipient in interface Message
      Returns:
      the message recipient
    • getObjectMap

      public MacroObjectMap getObjectMap()
      Description copied from interface: Message
      Returns the MacroObjectMap of macro values bound to this message.
      Specified by:
      getObjectMap in interface Message
      Returns:
      the macro object map
    • 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.
    • reason

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