Interface Recipient
- All Known Implementing Classes:
Recipient.Invalid,Recipient.Proxied,Recipient.Valid
A sealed interface and its related types that represent different categories
of message recipients in a player message context.
This model encapsulates information about the origin of a command or message recipient and classifies it into one of three known types:
Recipient.Valid– A recognized sender type capable of receiving messages directly (e.g.,Player,ConsoleCommandSender)Recipient.Proxied– A special wrapper forProxiedCommandSenderthat maintains both the proxied and originating senderRecipient.Invalid– An unrecognized ornullsender, with an accompanying reason
This design follows a data-driven pattern: recipients are validated and categorized
during construction via the static factory method of(CommandSender), which guarantees
type safety and clarity at the call site.
Typical usage:
Recipient recipient = Recipient.of(sender);
if (recipient instanceof Recipient.Sendable sendable) {
sendable.sender().sendMessage("Hello!");
}
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordRepresents an invalid or unrecognized message recipient.static enumIndicates the reason aRecipientwas deemed invalid.static final recordRepresents a proxied command sender (e.g., from another plugin or dispatch chain).static interfaceA marker subinterface forRecipienttypes that are capable of receiving messages directly.static final recordRepresents a valid, recognized message recipient such as a player, console, or command block. -
Method Summary
-
Method Details
-
of
Factory method that analyzes the givenCommandSenderand returns a categorizedRecipientinstance.- If the sender is a
Player,ConsoleCommandSender, orBlockCommandSender, aRecipient.Validrecipient is returned - If the sender is a
ProxiedCommandSender, aRecipient.Proxiedrecipient is returned - If the sender is
null, anRecipient.Invalidrecipient with reasonNULLis returned - Otherwise, an
Recipient.Invalidrecipient with reasonOTHERis returned
- Parameters:
sender- theCommandSenderto classify- Returns:
- a concrete
Recipientrepresenting the sender’s classification
- If the sender is a
-