Better input validation for some Options and Requirements prompts

This commit is contained in:
PikaMug 2020-02-24 20:37:48 -05:00
parent e5829acad7
commit 7fbd793c85
3 changed files with 11 additions and 18 deletions

View File

@ -162,16 +162,14 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
try {
boolean b = Boolean.parseBoolean(input);
if (input.equalsIgnoreCase("t") || input.equalsIgnoreCase("true")
|| input.equalsIgnoreCase(Lang.get("true"))
|| input.equalsIgnoreCase(Lang.get("yesWord"))) {
b = true;
}
context.setSessionData(tempKey, b);
} catch (Exception e) {
e.printStackTrace();
if (input.startsWith("t") || input.equalsIgnoreCase(Lang.get("true"))
|| input.equalsIgnoreCase(Lang.get("yesWord"))) {
context.setSessionData(tempKey, true);
} else if (input.startsWith("f") || input.equalsIgnoreCase(Lang.get("false"))
|| input.equalsIgnoreCase(Lang.get("noWord"))) {
context.setSessionData(tempKey, false);
} else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
return new TrueFalsePrompt(plugin, context, factory);
}
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {

View File

@ -663,18 +663,14 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
String[] args = input.split(" ");
LinkedList<Boolean> booleans = new LinkedList<Boolean>();
for (String s : args) {
if (input.equalsIgnoreCase("t") || input.equalsIgnoreCase("true")
|| s.equalsIgnoreCase(Lang.get("true"))
if (input.startsWith("t") || s.equalsIgnoreCase(Lang.get("true"))
|| s.equalsIgnoreCase(Lang.get("yesWord"))) {
booleans.add(true);
} else if (input.equalsIgnoreCase("f") || input.equalsIgnoreCase("false")
|| s.equalsIgnoreCase(Lang.get("false"))
} else if (input.startsWith("f") || s.equalsIgnoreCase(Lang.get("false"))
|| s.equalsIgnoreCase(Lang.get("noWord"))) {
booleans.add(false);
} else {
String text = Lang.get("reqTrueFalseError");
text = text.replace("<input>", ChatColor.LIGHT_PURPLE + s + ChatColor.RED);
context.getForWhom().sendRawMessage(ChatColor.RED + text);
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
return new RemoveItemsPrompt();
}
}

View File

@ -435,7 +435,6 @@ reqHeroesPrimaryDisplay: "Primary Class:"
reqHeroesSecondaryDisplay: "Secondary Class:"
reqNotAQuestName: "<quest> is not a Quest name!"
reqItemCleared: "Item requirements cleared."
reqTrueFalseError: '<input> is not a true or false value!%br%Example: true false true true'
reqCustomAlreadyAdded: "That custom requirement has already been added!"
reqCustomNotFound: "Custom requirement module not found."
reqCustomCleared: "Custom requirements cleared."