Class ChatInputHandler

java.lang.Object
com.github.darksoulq.abyssallib.server.chat.ChatInputHandler

public class ChatInputHandler extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    await(org.bukkit.entity.Player player, Consumer<String> inputHandler)
    Awaits a chat input from the specified player using a default prompt and no timeout.
    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.
    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.
    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.
    static boolean
    cancel(org.bukkit.entity.Player player)
    Cancels any pending input request for the specified player.
    void
    onChat(io.papermc.paper.event.player.AsyncChatEvent event)
    Listens for the Paper AsyncChatEvent to intercept player messages.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ChatInputHandler

      public ChatInputHandler()
  • Method Details

    • await

      public static void await(org.bukkit.entity.Player player, Consumer<String> inputHandler)
      Awaits a chat input from the specified player using a default prompt and no timeout.
      Parameters:
      player - The Player to await input from.
      inputHandler - The Consumer to execute when input is received.
    • 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 - The Player to await input from.
      inputHandler - The Consumer to execute when input is received.
      prompt - The Component message 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 - The Player to await input from.
      inputHandler - The Consumer to 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 - The Player to await input from.
      inputHandler - The Consumer to execute when input is received.
      prompt - The Component message 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 - The Player whose input request should be removed.
      Returns:
      true if a request was active and successfully removed.
    • onChat

      public void onChat(io.papermc.paper.event.player.AsyncChatEvent event)
      Listens for the Paper AsyncChatEvent to 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.