Interface MessageContext

All Known Subinterfaces:
AFKMessageContext, BallMessageContext, ChatMessageContext, ClearMessageContext, CoinMessageContext, ComponentMessageContext, DeletemessageMessageContext, DiceMessageContext, DiscordMessageContext, ExternalModerationMessageContext, GeolocateMessageContext, IgnoreMessageContext, JoinMessageContext, MailMessageContext, MaintenanceMessageContext, MinesweeperMessageContext, ModerationMessageContext, NicknameMessageContext, OnlineMessageContext, PollMessageContext, QuestionAnswerMessageContext, RightClickMessageContext, RockPaperScissorsMessageContext, SpyMessageContext, StreamMessageContext, StringMessageContext, TelegramMessageContext, TellMessageContext, TicTacToeMessageContext, TranslatetoMessageContext, TryMessageContext, TwitchMessageContext, UpdateMessageContext, VanillaMessageContext, VanishMessageContext, WhitelistMessageContext

public interface MessageContext
One message on its way to one receiver, carrying the raw text, who sent it, who reads it, the MiniMessage tags resolved so far and the flags that switch formatting steps on or off.

Contexts are immutable. The with* and add* methods return a modified copy, and richer variants such as StringMessageContext wrap a base context to carry extra data.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Identifies a rendered message so an identical one can be served from cache instead of being formatted again.
  • Method Summary

    Modifier and Type
    Method
    Description
    addFlag(@NonNull MessageFlag flag, boolean value)
    Returns a copy with one flag set, keeping the rest.
    addFlags(MessageFlag @NonNull [] flags, boolean @NonNull [] values)
    Returns a copy with several flags set, keeping the rest.
    addTagResolver(@Nullable net.kyori.adventure.text.minimessage.tag.resolver.TagResolver tagResolver)
    Returns a copy with one more tag resolver layered on top of the current ones.
    addTagResolvers(@NonNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... resolvers)
    Returns a copy with several tag resolvers layered on top of the current ones.
    The plain context underneath this one.
    static net.flectone.pulse.model.event.message.context.MessageContextImpl.MessageContextImplBuilder
    Starts building a message context.
    Builds the cache key for this context.
    default @NonNull Map<MessageFlag, Boolean>
    The formatting switches applied to this message.
    default boolean
    Whether a flag is on, falling back to the flag's own default when it was never set.
    default @NonNull String
    The raw, unrendered text.
    default @NonNull FPlayer
    Who this copy of the message is for.
    default @NonNull FEntity
    Who sent the message.
    default @NonNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
    The MiniMessage tags available while rendering this message.
    default net.flectone.pulse.model.event.message.context.MessageContextImpl.MessageContextImplBuilder
    Starts a builder pre-filled with this context's values.
    default @NonNull UUID
    The id shared by every per-receiver copy of the same message.
    withBase(@NonNull MessageContext base)
    Returns a copy with a different base context.
    withFlags(@NonNull Map<MessageFlag, Boolean> flags)
    Returns a copy with the flags replaced.
    withMessage(@NonNull String message)
    Returns a copy with different text.
    withReceiver(@NonNull FPlayer receiver)
    Returns a copy aimed at a different receiver.
    withSender(@NonNull FEntity sender)
    Returns a copy with a different sender.
    withTagResolver(@NonNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver tagResolver)
    Returns a copy with the tag resolver replaced.
    withUuid(@NonNull UUID uuid)
    Returns a copy with a different message id.
  • Method Details

    • builder

      static net.flectone.pulse.model.event.message.context.MessageContextImpl.MessageContextImplBuilder builder()
      Starts building a message context.
      Returns:
      a new builder
    • base

      The plain context underneath this one. Wrapping contexts delegate their shared fields to it.
      Returns:
      the base context
    • toBuilder

      default net.flectone.pulse.model.event.message.context.MessageContextImpl.MessageContextImplBuilder toBuilder()
      Starts a builder pre-filled with this context's values.
      Returns:
      the pre-filled builder
    • flags

      default @NonNull Map<MessageFlag, Boolean> flags()
      The formatting switches applied to this message.
      Returns:
      the flags, keyed by name
    • tagResolver

      default @NonNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver tagResolver()
      The MiniMessage tags available while rendering this message.
      Returns:
      the resolver
    • sender

      default @NonNull FEntity sender()
      Who sent the message.
      Returns:
      the sender
    • receiver

      default @NonNull FPlayer receiver()
      Who this copy of the message is for.
      Returns:
      the receiver
    • uuid

      default @NonNull UUID uuid()
      The id shared by every per-receiver copy of the same message.
      Returns:
      the message id
    • message

      default @NonNull String message()
      The raw, unrendered text.
      Returns:
      the message text
    • withBase

      default MessageContext withBase(@NonNull MessageContext base)
      Returns a copy with a different base context.
      Parameters:
      base - the new base
      Returns:
      the copy
    • withFlags

      default MessageContext withFlags(@NonNull Map<MessageFlag, Boolean> flags)
      Returns a copy with the flags replaced.
      Parameters:
      flags - the new flags
      Returns:
      the copy
    • withTagResolver

      default MessageContext withTagResolver(@NonNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver tagResolver)
      Returns a copy with the tag resolver replaced.
      Parameters:
      tagResolver - the new resolver
      Returns:
      the copy
    • withSender

      default MessageContext withSender(@NonNull FEntity sender)
      Returns a copy with a different sender.
      Parameters:
      sender - the new sender
      Returns:
      the copy
    • withReceiver

      default MessageContext withReceiver(@NonNull FPlayer receiver)
      Returns a copy aimed at a different receiver.
      Parameters:
      receiver - the new receiver
      Returns:
      the copy
    • withUuid

      default MessageContext withUuid(@NonNull UUID uuid)
      Returns a copy with a different message id.
      Parameters:
      uuid - the new id
      Returns:
      the copy
    • withMessage

      default MessageContext withMessage(@NonNull String message)
      Returns a copy with different text.
      Parameters:
      message - the new text
      Returns:
      the copy
    • isFlag

      default boolean isFlag(MessageFlag flag)
      Whether a flag is on, falling back to the flag's own default when it was never set.
      Parameters:
      flag - the flag to read
      Returns:
      the flag state
    • addFlag

      default MessageContext addFlag(@NonNull MessageFlag flag, boolean value)
      Returns a copy with one flag set, keeping the rest.
      Parameters:
      flag - the flag to set
      value - the new state
      Returns:
      the copy
    • addFlags

      default MessageContext addFlags(MessageFlag @NonNull [] flags, boolean @NonNull [] values)
      Returns a copy with several flags set, keeping the rest.
      Parameters:
      flags - the flags to set
      values - the matching states
      Returns:
      the copy, or this instance if either array is empty
      Throws:
      IllegalArgumentException - if the two arrays differ in length
    • addTagResolver

      default MessageContext addTagResolver(@Nullable net.kyori.adventure.text.minimessage.tag.resolver.TagResolver tagResolver)
      Returns a copy with one more tag resolver layered on top of the current ones.
      Parameters:
      tagResolver - the resolver to add, may be null
      Returns:
      the copy, or this instance if the resolver was null
    • addTagResolvers

      default MessageContext addTagResolvers(@NonNull net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... resolvers)
      Returns a copy with several tag resolvers layered on top of the current ones.
      Parameters:
      resolvers - the resolvers to add
      Returns:
      the copy, or this instance if nothing was passed
    • createCacheKey

      default MessageContext.CacheKey createCacheKey()
      Builds the cache key for this context.
      Returns:
      the key