Interface Message
- All Known Implementing Classes:
InvalidMessage,ValidMessage
A sealed interface representing a message that can be composed using macros
and sent to a valid recipient.
Messages are constructed dynamically using the fluent API exposed by
com.winterhavenmc.library.messagebuilder.bootstrap.MessageBuilder, and are
resolved at runtime using a combination of a message template, a macro object map,
and a validated Recipient.
The Message interface has two implementations:
ValidMessage– A fully-constructed message with a resolvable template and a valid recipientInvalidMessage– A placeholder or sentinel used when the message cannot be composed
Fluent Macro Assignment
Macros can be added to the message using thesetMacro methods. These allow
rich contextual data such as strings, durations, quantities, and domain objects to be bound
to placeholders in the final rendered message.
Sending
Once composed, thesend() method dispatches the message to the resolved recipient,
if one is available and valid.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Messageempty()Returns an emptyMessageinstance that performs no action when sent.Returns theValidMessageKeyidentifying the message template used in composition.Returns theMacroObjectMapof macro values bound to this message.Returns theRecipient.Sendableto whom the message will be sent.booleansend()Sends the composed message to the resolved recipient, if valid.setMacro(int quantity, K macro, V value) Associates a macro string with a value and explicit quantity, useful for pluralization or contextual substitution that depends on numeric counts.setMacro(K macro, Duration duration, ChronoUnit precision) Associates a duration with the given macro string, using a defined precision.setMacro(K macro, V value) Associates a macro string with a value for later substitution during message rendering.
-
Method Details
-
setMacro
Associates a macro string with a value for later substitution during message rendering.- Type Parameters:
K- the enum type of the macroV- the value type- Parameters:
macro- the macro string to assignvalue- the value to associate with the macro- Returns:
- the same
Messageinstance, for fluent chaining
-
setMacro
Associates a macro string with a value and explicit quantity, useful for pluralization or contextual substitution that depends on numeric counts.- Type Parameters:
K- the enum type of the macroV- the value type- Parameters:
quantity- the quantity associated with the valuemacro- the macro stringvalue- the object to associate- Returns:
- the same
Messageinstance, for fluent chaining
-
setMacro
Associates a duration with the given macro string, using a defined precision.- Type Parameters:
K- the enum type of the macro- Parameters:
macro- the macro stringduration- theDurationto be formatted and resolvedprecision- theChronoUnitto control formatting granularity- Returns:
- the same
Messageinstance, for fluent chaining
-
send
boolean send()Sends the composed message to the resolved recipient, if valid.No-op if the message is invalid or the recipient is missing or unsupported.
-
getMessageKey
ValidMessageKey getMessageKey()Returns theValidMessageKeyidentifying the message template used in composition.- Returns:
- the message string
-
getRecipient
Recipient.Sendable getRecipient()Returns theRecipient.Sendableto whom the message will be sent.- Returns:
- the message recipient
-
getObjectMap
MacroObjectMap getObjectMap()Returns theMacroObjectMapof macro values bound to this message.- Returns:
- the macro object map
-
empty
Returns an emptyMessageinstance that performs no action when sent. Used as a fallback when message construction fails.- Returns:
- an
InvalidMessagerepresenting an inert or failed message
-