[Bleeding] Added Conversations API. Addresses BUKKIT-864

By: rmichela <deltahat@gmail.com>
This commit is contained in:
Bukkit/Spigot
2012-01-22 02:35:42 -05:00
parent fb55ed2a78
commit 2280c6be2b
26 changed files with 1446 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
package org.bukkit.conversations;
import org.apache.commons.lang.StringUtils;
import java.util.Arrays;
import java.util.List;
/**
* FixedSetPrompt is the base class for any prompt that requires a fixed set response from the user.
*/
public abstract class FixedSetPrompt extends ValidatingPrompt {
protected List<String> fixedSet;
/**
* Creates a FixedSetPrompt from a set of strings.
* foo = new FixedSetPrompt("bar", "cheese", "panda");
* @param fixedSet A fixed set of strings, one of which the user must type.
*/
public FixedSetPrompt(String... fixedSet) {
super();
this.fixedSet = Arrays.asList(fixedSet);
}
private FixedSetPrompt() {}
@Override
protected boolean isInputValid(ConversationContext context, String input) {
return fixedSet.contains(input);
}
/**
* Utility function to create a formatted string containing all the options declared in the constructor.
* The result is formatted like "[bar, cheese, panda]"
* @return
*/
protected String formatFixedSet() {
return "[" + StringUtils.join(fixedSet, ", ") + "]";
}
}