Package org.bukkit.conversations
Class ValidatingPrompt
- java.lang.Object
-
- org.bukkit.conversations.ValidatingPrompt
-
- Direct Known Subclasses:
BooleanPrompt,FixedSetPrompt,NumericPrompt,PlayerNamePrompt,RegexPrompt
public abstract class ValidatingPrompt extends Object implements Prompt
ValidatingPrompt is the base class for any prompt that requires validation. ValidatingPrompt will keep replaying the prompt text until the user enters a valid response.
-
-
Field Summary
-
Fields inherited from interface org.bukkit.conversations.Prompt
END_OF_CONVERSATION
-
-
Constructor Summary
Constructors Constructor Description ValidatingPrompt()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description PromptacceptInput(ConversationContext context, String input)Accepts and processes input from the user and validates it.protected abstract PromptacceptValidatedInput(ConversationContext context, String input)Override this method to accept and processes the validated input from the user.booleanblocksForInput(ConversationContext context)Ensures that the prompt waits for the user to provide input.protected StringgetFailedValidationText(ConversationContext context, String invalidInput)Optionally override this method to display an additional message if the user enters an invalid input.protected abstract booleanisInputValid(ConversationContext context, String input)Override this method to check the validity of the player's input.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.bukkit.conversations.Prompt
getPromptText
-
-
-
-
Method Detail
-
acceptInput
@Nullable public Prompt acceptInput(@NotNull ConversationContext context, @Nullable String input)
Accepts and processes input from the user and validates it. If validation fails, this prompt is returned for re-execution, otherwise the next Prompt in the prompt graph is returned.- Specified by:
acceptInputin interfacePrompt- Parameters:
context- Context information about the conversation.input- The input text from the user.- Returns:
- This prompt or the next Prompt in the prompt graph.
-
blocksForInput
public boolean blocksForInput(@NotNull ConversationContext context)Ensures that the prompt waits for the user to provide input.- Specified by:
blocksForInputin interfacePrompt- Parameters:
context- Context information about the conversation.- Returns:
- True.
-
isInputValid
protected abstract boolean isInputValid(@NotNull ConversationContext context, @NotNull String input)Override this method to check the validity of the player's input.- Parameters:
context- Context information about the conversation.input- The player's raw console input.- Returns:
- True or false depending on the validity of the input.
-
acceptValidatedInput
@Nullable protected abstract Prompt acceptValidatedInput(@NotNull ConversationContext context, @NotNull String input)
Override this method to accept and processes the validated input from the user. Using the input, the next Prompt in the prompt graph should be returned.- Parameters:
context- Context information about the conversation.input- The validated input text from the user.- Returns:
- The next Prompt in the prompt graph.
-
getFailedValidationText
@Nullable protected String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput)
Optionally override this method to display an additional message if the user enters an invalid input.- Parameters:
context- Context information about the conversation.invalidInput- The invalid input provided by the user.- Returns:
- A message explaining how to correct the input.
-
-