Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
BooleanPrompt.java
1 package org.bukkit.conversations;
2 
3 import org.apache.commons.lang.ArrayUtils;
4 import org.apache.commons.lang.BooleanUtils;
5 
6 /**
7  * BooleanPrompt is the base class for any prompt that requires a boolean
8  * response from the user.
9  */
10 public abstract class BooleanPrompt extends ValidatingPrompt{
11 
12  public BooleanPrompt() {
13  super();
14  }
15 
16  @Override
17  protected boolean isInputValid(ConversationContext context, String input) {
18  String[] accepted = {"true", "false", "on", "off", "yes", "no"};
19  return ArrayUtils.contains(accepted, input.toLowerCase());
20  }
21 
22  @Override
23  protected Prompt acceptValidatedInput(ConversationContext context, String input) {
24  return acceptValidatedInput(context, BooleanUtils.toBoolean(input));
25  }
26 
27  /**
28  * Override this method to perform some action with the user's boolean
29  * response.
30  *
31  * @param context Context information about the conversation.
32  * @param input The user's boolean response.
33  * @return The next {@link Prompt} in the prompt graph.
34  */
35  protected abstract Prompt acceptValidatedInput(ConversationContext context, boolean input);
36 }