Class ChatInputRequest<T>

java.lang.Object
org.bukkit.conversations.ValidatingPrompt
dev.demeng.pluginbase.input.ChatInputRequest<T>
Type Parameters:
T - The expected return type for the input request
All Implemented Interfaces:
Cloneable, org.bukkit.conversations.Prompt

public class ChatInputRequest<T> extends org.bukkit.conversations.ValidatingPrompt
Requests a chat input from players, with the ability to map the string input into the object you require and a retry system for invalid inputs. Created using the Bukkit Conversation API.
  • Constructor Details

    • ChatInputRequest

      public ChatInputRequest()
  • Method Details

    • create

      @NotNull public static <T> @NotNull ChatInputRequest<T> create(@NotNull @NotNull Function<@NotNull String,@Nullable T> parser)
      Creates a new chat input request builder.
      Type Parameters:
      T - The expected return type for the input request
      Parameters:
      parser - The input parser that returns the expected object, or null if the string input is invalid
      Returns:
      A new chat input request builder
    • withTitle

      @NotNull public @NotNull ChatInputRequest<T> withTitle(@Nullable @Nullable String title)
      Sets the title that is sent when input is requested. If not set, PluginBase uses its built-in default.
      Parameters:
      title - The title sent on input request
      Returns:
      this
    • withSubtitle

      @NotNull public @NotNull ChatInputRequest<T> withSubtitle(@Nullable @Nullable String subtitle)
      Sets the subtitle that is sent when input is requested. If not set, PluginBase uses its built-in default.
      Parameters:
      subtitle - The subtitle sent on input request
      Returns:
      this
    • withInitialMessage

      @NotNull public @NotNull ChatInputRequest<T> withInitialMessage(@Nullable @Nullable String initialMessage)
      The message that is sent the first time input is requested. If not set, an empty message will be used.
      Parameters:
      initialMessage - The message sent on initial request
      Returns:
      this
    • withRetryMessage

      @NotNull public @NotNull ChatInputRequest<T> withRetryMessage(@Nullable @Nullable String retryMessage)
      The message that is sent after an invalid input. If not set, PluginBase uses its built-in default.
      Parameters:
      retryMessage - The message sent on invalid input
      Returns:
      this
    • withTimeoutMessage

      @NotNull public @NotNull ChatInputRequest<T> withTimeoutMessage(@Nullable @Nullable String timeoutMessage)
      The message that is sent after the request timeout of 5 minutes. If not set, PluginBase uses its built-in default.
      Parameters:
      timeoutMessage - The message sent on timeout
      Returns:
      this
    • withExitValue

      @NotNull public @NotNull ChatInputRequest<T> withExitValue(@Nullable @Nullable String exitValue)
      Sets the escape sequence that cancels the input request. If not set, PluginBase uses its built-in default.
      Parameters:
      exitValue - The string a player can type to cancel the request
      Returns:
      this
    • onFinish

      @NotNull public @NotNull ChatInputRequest<T> onFinish(@Nullable @Nullable Consumer<T> consumer)
      The consumer that is accepted with the parsed input when a valid input has been provided. This utility will automatically clear the title and subtitle (if applicable) and end the Conversation.
      Parameters:
      consumer - The consumer to be accepted with the input
      Returns:
      this
    • onExit

      @NotNull public @NotNull ChatInputRequest<T> onExit(@Nullable @Nullable Runnable exitRunnable)
      The runnable ran on exit (conversation abandon). This is called both when an input is accepted and when the input request is cancelled using the configured escape sequence.
      Parameters:
      exitRunnable - The runnable to run on exit
      Returns:
      this
    • start

      public void start(@NotNull @NotNull org.bukkit.entity.Player p)
      Requests the specified player for input.
      Parameters:
      p - The player to request input from
    • isInputValid

      protected boolean isInputValid(@NotNull @NotNull org.bukkit.conversations.ConversationContext context, @NotNull @NotNull String str)
      Specified by:
      isInputValid in class org.bukkit.conversations.ValidatingPrompt
    • acceptValidatedInput

      @Nullable protected @Nullable org.bukkit.conversations.Prompt acceptValidatedInput(@NotNull @NotNull org.bukkit.conversations.ConversationContext context, @NotNull @NotNull String str)
      Specified by:
      acceptValidatedInput in class org.bukkit.conversations.ValidatingPrompt
    • getPromptText

      @NotNull public @NotNull String getPromptText(@NotNull @NotNull org.bukkit.conversations.ConversationContext context)