Package dev.demeng.pluginbase.input
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.-
Field Summary
Fields inherited from interface org.bukkit.conversations.Prompt
END_OF_CONVERSATION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable org.bukkit.conversations.PromptacceptValidatedInput(@NotNull org.bukkit.conversations.ConversationContext context, @NotNull String str) static <T> @NotNull ChatInputRequest<T>Creates a new chat input request builder.@NotNull StringgetPromptText(@NotNull org.bukkit.conversations.ConversationContext context) protected booleanisInputValid(@NotNull org.bukkit.conversations.ConversationContext context, @NotNull String str) @NotNull ChatInputRequest<T>The runnable ran on exit (conversation abandon).@NotNull ChatInputRequest<T>The consumer that is accepted with the parsed input when a valid input has been provided.voidstart(@NotNull org.bukkit.entity.Player p) Requests the specified player for input.@NotNull ChatInputRequest<T>withExitValue(@Nullable String exitValue) Sets the escape sequence that cancels the input request.@NotNull ChatInputRequest<T>withInitialMessage(@Nullable String initialMessage) The message that is sent the first time input is requested.@NotNull ChatInputRequest<T>withRetryMessage(@Nullable String retryMessage) The message that is sent after an invalid input.@NotNull ChatInputRequest<T>withSubtitle(@Nullable String subtitle) Sets the subtitle that is sent when input is requested.@NotNull ChatInputRequest<T>withTimeoutMessage(@Nullable String timeoutMessage) The message that is sent after the request timeout of 5 minutes.@NotNull ChatInputRequest<T>Sets the title that is sent when input is requested.Methods inherited from class org.bukkit.conversations.ValidatingPrompt
acceptInput, blocksForInput, getFailedValidationText
-
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
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
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
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
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 theConversation.- Parameters:
consumer- The consumer to be accepted with the input- Returns:
- this
-
onExit
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:
isInputValidin classorg.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:
acceptValidatedInputin classorg.bukkit.conversations.ValidatingPrompt
-
getPromptText
@NotNull public @NotNull String getPromptText(@NotNull @NotNull org.bukkit.conversations.ConversationContext context)
-