Class ChatPrompt
java.lang.Object
tech.guilhermekaua.spigotboot.core.spigot.conversation.ChatPrompt
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 Summary
Modifier and TypeMethodDescriptionasync()Run the callback inline on the async chat thread instead of hopping to the main/region thread.firstPrompt(String markup) A message sent to the player the moment the conversation starts.voidonChat(@NotNull Consumer<ChatContext> callback) Starts the conversation.onEnd(BiConsumer<org.bukkit.entity.Player, EndReason> onEnd) Sets a hook that runs when the conversation ends for any reason.Sets a hook that runs, with the player, when the inactivity timeout elapses, just beforeonEnd.Inactivity timeout: if the player sends no message within this window the conversation ends withEndReason.TIMEOUT.
-
Method Details
-
firstPrompt
A message sent to the player the moment the conversation starts. Treated asChatMarkupsource (colours,#rrggbbhex, styles, click/hover).- Parameters:
markup- the prompt text;null/blank sends nothing- Returns:
- this builder
-
timeout
Inactivity timeout: if the player sends no message within this window the conversation ends withEndReason.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 millisecondunit- the time unit- Returns:
- this builder
- Throws:
IllegalArgumentException- ifdurationis not positive or is smaller than one millisecond inunit
-
onTimeout
Sets a hook that runs, with the player, when the inactivity timeout elapses, just beforeonEnd. 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 theonChatcallback, never this lifecycle hook.- Parameters:
onTimeout- run (with the player) when the timeout elapses, just beforeonEnd- Returns:
- this builder
-
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 byEndReason:TIMEOUTon the scheduler's entity/region thread,ENDEDon theonChatcallback's thread,DISCONNECTandPLUGIN_DISABLEon the server thread, andREPLACEDon whichever thread started the replacing conversation.async()affects only theonChatcallback, never this lifecycle hook.- Parameters:
onEnd- run when the conversation ends for any reason- Returns:
- this builder
-
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
Starts the conversation. Any conversation already active for this player ends withEndReason.REPLACED.- Parameters:
callback- invoked for each captured message
-