Class ChatInputHandler
java.lang.Object
com.github.darksoulq.abyssallib.server.chat.ChatInputHandler
Utility class for capturing asynchronous player chat input.
This handler allows for "waiting" on a player's next chat message to use as functional input, supporting custom prompts, timeouts, and automatic cancellation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAwaits a chat input from the specified player using a default prompt and no timeout.static voidAwaits a chat input from the specified player with a default prompt and a timeout.static voidawait(org.bukkit.entity.Player player, Consumer<String> inputHandler, net.kyori.adventure.text.Component prompt) Awaits a chat input from the specified player with a custom prompt and no timeout.static voidawait(org.bukkit.entity.Player player, Consumer<String> inputHandler, net.kyori.adventure.text.Component prompt, long timeoutTicks) Awaits a chat input from the specified player with a custom prompt and a timeout.static booleancancel(org.bukkit.entity.Player player) Cancels any pending input request for the specified player.voidonChat(io.papermc.paper.event.player.AsyncChatEvent event) Listens for the PaperAsyncChatEventto intercept player messages.
-
Constructor Details
-
ChatInputHandler
public ChatInputHandler()
-
-
Method Details
-
await
-
await
public static void await(org.bukkit.entity.Player player, Consumer<String> inputHandler, net.kyori.adventure.text.Component prompt) Awaits a chat input from the specified player with a custom prompt and no timeout.- Parameters:
player- ThePlayerto await input from.inputHandler- TheConsumerto execute when input is received.prompt- TheComponentmessage to send as a prompt.
-
await
public static void await(org.bukkit.entity.Player player, Consumer<String> inputHandler, long timeoutTicks) Awaits a chat input from the specified player with a default prompt and a timeout.- Parameters:
player- ThePlayerto await input from.inputHandler- TheConsumerto execute when input is received.timeoutTicks- The duration in server ticks before the request expires.
-
await
public static void await(org.bukkit.entity.Player player, Consumer<String> inputHandler, net.kyori.adventure.text.Component prompt, long timeoutTicks) Awaits a chat input from the specified player with a custom prompt and a timeout.- Parameters:
player- ThePlayerto await input from.inputHandler- TheConsumerto execute when input is received.prompt- TheComponentmessage to send as a prompt.timeoutTicks- The duration in server ticks before the request expires.
-
cancel
public static boolean cancel(org.bukkit.entity.Player player) Cancels any pending input request for the specified player.- Parameters:
player- ThePlayerwhose input request should be removed.- Returns:
trueif a request was active and successfully removed.
-
onChat
public void onChat(io.papermc.paper.event.player.AsyncChatEvent event) Listens for the PaperAsyncChatEventto intercept player messages.If the player has a pending input request, the event is cancelled and the message is passed to the registered handler on the primary server thread.
- Parameters:
event- The chat event.
-