143 lines
4.2 KiB
Java
143 lines
4.2 KiB
Java
package net.knarcraft.paidsigns.utility;
|
|
|
|
import net.knarcraft.paidsigns.PaidSigns;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
/**
|
|
* A helper class for providing common tab complete options
|
|
*/
|
|
public final class TabCompleteHelper {
|
|
|
|
private TabCompleteHelper() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Finds tab complete values that contain the typed text
|
|
*
|
|
* @param values <p>The values to filter</p>
|
|
* @param typedText <p>The text the player has started typing</p>
|
|
* @return <p>The given string values that contain the player's typed text</p>
|
|
*/
|
|
public static List<String> filterMatchingContains(List<String> values, String typedText) {
|
|
List<String> configValues = new ArrayList<>();
|
|
for (String value : values) {
|
|
if (value.toLowerCase().contains(typedText.toLowerCase())) {
|
|
configValues.add(value);
|
|
}
|
|
}
|
|
return configValues;
|
|
}
|
|
|
|
/**
|
|
* Finds tab complete values that match the start of the typed text
|
|
*
|
|
* @param values <p>The values to filter</p>
|
|
* @param typedText <p>The text the player has started typing</p>
|
|
* @return <p>The given string values that start with the player's typed text</p>
|
|
*/
|
|
public static List<String> filterMatchingStartsWith(List<String> values, String typedText) {
|
|
List<String> configValues = new ArrayList<>();
|
|
for (String value : values) {
|
|
if (value.toLowerCase().startsWith(typedText.toLowerCase())) {
|
|
configValues.add(value);
|
|
}
|
|
}
|
|
return configValues;
|
|
}
|
|
|
|
/**
|
|
* Gets the available boolean values for tab completion
|
|
*
|
|
* @return <p>The available boolean values</p>
|
|
*/
|
|
public static List<String> getBooleans() {
|
|
List<String> booleans = new ArrayList<>();
|
|
booleans.add("true");
|
|
booleans.add("false");
|
|
return booleans;
|
|
}
|
|
|
|
/**
|
|
* Gets the available option states for tab completion
|
|
*
|
|
* @return <p>The available option states</p>
|
|
*/
|
|
public static List<String> getOptionStates() {
|
|
List<String> optionStates = getBooleans();
|
|
optionStates.add("default");
|
|
return optionStates;
|
|
}
|
|
|
|
/**
|
|
* Gets the names of all registered paid signs
|
|
*
|
|
* @return <p>The names of all registered paid signs</p>
|
|
*/
|
|
public static List<String> getPaidSignNames() {
|
|
Set<String> paidSignNames = PaidSigns.getInstance().getSignManager().getAllPaidSigns().keySet();
|
|
List<String> quotedNames = new ArrayList<>(paidSignNames.size());
|
|
for (String paidSignName : paidSignNames) {
|
|
quotedNames.add("\"" + paidSignName + "\"");
|
|
}
|
|
return quotedNames;
|
|
}
|
|
|
|
/**
|
|
* Gets all the choices for lines on a sign
|
|
*
|
|
* @return <p>All the line indices of a sign</p>
|
|
*/
|
|
public static List<String> getSignLines() {
|
|
List<String> lines = new ArrayList<>();
|
|
for (int i = 1; i < 5; i++) {
|
|
lines.add(String.valueOf(i));
|
|
}
|
|
return lines;
|
|
}
|
|
|
|
/**
|
|
* Gets some valid costs as example values
|
|
*
|
|
* @return <p>Some valid costs</p>
|
|
*/
|
|
public static List<String> getCosts() {
|
|
List<String> costs = new ArrayList<>();
|
|
costs.add("1");
|
|
costs.add("5");
|
|
costs.add("10");
|
|
costs.add("15");
|
|
return costs;
|
|
}
|
|
|
|
/**
|
|
* Gets some example paid sign names for auto-completion
|
|
*
|
|
* @return <p>Some example paid sign names</p>
|
|
*/
|
|
public static List<String> getExamplePaidSignNames() {
|
|
List<String> names = new ArrayList<>();
|
|
names.add("sign1");
|
|
names.add("\"lift up sign\"");
|
|
names.add("\"lift down sign\"");
|
|
return names;
|
|
}
|
|
|
|
/**
|
|
* Gets some example condition matching strings for tab completion
|
|
*
|
|
* @return <p>Some example "stringToMatch" values</p>
|
|
*/
|
|
public static List<String> getExampleConditionStrings() {
|
|
List<String> conditionStrings = new ArrayList<>();
|
|
conditionStrings.add("[Gate]");
|
|
conditionStrings.add("\"[Lift Up]\"");
|
|
conditionStrings.add("\"[Lift Down]\"");
|
|
return conditionStrings;
|
|
}
|
|
|
|
}
|