001 package org.bukkit.conversations;
002
003 import org.apache.commons.lang.ArrayUtils;
004 import org.apache.commons.lang.BooleanUtils;
005
006 /**
007 * BooleanPrompt is the base class for any prompt that requires a boolean
008 * response from the user.
009 */
010 public abstract class BooleanPrompt extends ValidatingPrompt{
011
012 public BooleanPrompt() {
013 super();
014 }
015
016 @Override
017 protected boolean isInputValid(ConversationContext context, String input) {
018 String[] accepted = {"true", "false", "on", "off", "yes", "no"};
019 return ArrayUtils.contains(accepted, input.toLowerCase());
020 }
021
022 @Override
023 protected Prompt acceptValidatedInput(ConversationContext context, String input) {
024 return acceptValidatedInput(context, BooleanUtils.toBoolean(input));
025 }
026
027 /**
028 * Override this method to perform some action with the user's boolean
029 * response.
030 *
031 * @param context Context information about the conversation.
032 * @param input The user's boolean response.
033 * @return The next {@link Prompt} in the prompt graph.
034 */
035 protected abstract Prompt acceptValidatedInput(ConversationContext context, boolean input);
036 }