java.lang.Object
tech.guilhermekaua.spigotboot.core.spigot.conversation.ChatPrompt

public final class ChatPrompt extends Object
Fluent builder for a chat conversation. Obtain one from ChatUtils.with(Player). The terminal onChat(Consumer) call starts the conversation.

While a conversation is active the player's chat is intercepted (never broadcast) and each message is delivered to the callback until it calls ChatContext.end(), the timeout elapses, or the player disconnects.

  • Method Details

    • firstPrompt

      public ChatPrompt firstPrompt(String markup)
      A message sent to the player the moment the conversation starts. Treated as ChatMarkup source (colours, #rrggbb hex, styles, click/hover).
      Parameters:
      markup - the prompt text; null/blank sends nothing
      Returns:
      this builder
    • timeout

      public ChatPrompt timeout(long duration, @NotNull @NotNull TimeUnit unit)
      Inactivity timeout: if the player sends no message within this window the conversation ends with EndReason.TIMEOUT. The window resets on every captured message.

      To run without a timeout, simply do not call this method (the default). Passing a value that resolves to less than one millisecond is rejected rather than silently disabling the timeout.

      Parameters:
      duration - the amount; must resolve to at least one millisecond
      unit - the time unit
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if duration is not positive or is smaller than one millisecond in unit
    • onTimeout

      public ChatPrompt onTimeout(Consumer<org.bukkit.entity.Player> onTimeout)
      Sets a hook that runs, with the player, when the inactivity timeout elapses, just before onEnd. It fires synchronously on the thread that detects the timeout (the scheduler's entity/region thread), not on the async chat thread: async() governs only the onChat callback, never this lifecycle hook.
      Parameters:
      onTimeout - run (with the player) when the timeout elapses, just before onEnd
      Returns:
      this builder
    • onEnd

      public ChatPrompt onEnd(BiConsumer<org.bukkit.entity.Player,EndReason> onEnd)
      Sets a hook that runs when the conversation ends for any reason. It fires synchronously on whichever thread triggers the end, so the thread context varies by EndReason: TIMEOUT on the scheduler's entity/region thread, ENDED on the onChat callback's thread, DISCONNECT and PLUGIN_DISABLE on the server thread, and REPLACED on whichever thread started the replacing conversation. async() affects only the onChat callback, never this lifecycle hook.
      Parameters:
      onEnd - run when the conversation ends for any reason
      Returns:
      this builder
    • async

      public ChatPrompt async()
      Run the callback inline on the async chat thread instead of hopping to the main/region thread. Only safe when the callback touches thread-safe API only.
      Returns:
      this builder
    • onChat

      public void onChat(@NotNull @NotNull Consumer<ChatContext> callback)
      Starts the conversation. Any conversation already active for this player ends with EndReason.REPLACED.
      Parameters:
      callback - invoked for each captured message