Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
RegexPrompt.java
1 package org.bukkit.conversations;
2 
3 import java.util.regex.Pattern;
4 
5 /**
6  * RegexPrompt is the base class for any prompt that requires an input
7  * validated by a regular expression.
8  */
9 public abstract class RegexPrompt extends ValidatingPrompt {
10 
11  private Pattern pattern;
12 
13  public RegexPrompt(String regex) {
14  this(Pattern.compile(regex));
15  }
16 
17  public RegexPrompt(Pattern pattern) {
18  super();
19  this.pattern = pattern;
20  }
21 
22  private RegexPrompt() {}
23 
24  @Override
25  protected boolean isInputValid(ConversationContext context, String input) {
26  return pattern.matcher(input).matches();
27  }
28 }