All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.conversations.FixedSetPrompt Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
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 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. * * @return the options formatted like "[bar, cheese, panda]" if bar, * cheese, and panda were the options used */ protected String formatFixedSet() { return "[" + StringUtils.join(fixedSet, ", ") + "]"; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy