Disallow empty quest/action names from external sources

This commit is contained in:
PikaMug 2020-02-22 22:45:05 -05:00
parent d3aea3ee3b
commit 8531d4031c
2 changed files with 20 additions and 2 deletions

View File

@ -250,8 +250,8 @@ public class QuestFactory implements ConversationAbandonedListener {
}
public String getTitle(ConversationContext context) {
return Lang.get("quest") + ": " + context.getSessionData(CK.Q_NAME) + " " + ChatColor.GRAY
+ (context.getSessionData(CK.Q_ID) != null ? "(" + Lang.get("id") + ":"
return Lang.get("quest") + ": " + context.getSessionData(CK.Q_NAME) + "" + ChatColor.GRAY
+ (context.getSessionData(CK.Q_ID) != null ? " (" + Lang.get("id") + ":"
+ context.getSessionData(CK.Q_ID) + ")": "");
}
@ -529,6 +529,11 @@ public class QuestFactory implements ConversationAbandonedListener {
@Override
public Prompt acceptInput(ConversationContext context, String input) {
if (input == null) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
return new QuestSelectCreatePrompt(plugin, context, QuestFactory.this);
}
input = input.trim();
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
for (Quest q : plugin.getQuests()) {
if (q.getName().equalsIgnoreCase(input)) {
@ -544,6 +549,10 @@ public class QuestFactory implements ConversationAbandonedListener {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName"));
return new QuestSelectCreatePrompt(plugin, context, QuestFactory.this);
}
if (input.equals("")) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
return new QuestSelectCreatePrompt(plugin, context, QuestFactory.this);
}
context.setSessionData(CK.Q_NAME, input);
names.add(input);
return new QuestMainPrompt(plugin, context, QuestFactory.this);

View File

@ -462,6 +462,11 @@ public class ActionFactory implements ConversationAbandonedListener {
@Override
public Prompt acceptInput(ConversationContext context, String input) {
if (input == null) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
return new ActionSelectCreatePrompt(context, ActionFactory.this);
}
input = input.trim();
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
for (Action e : plugin.getActions()) {
if (e.getName().equalsIgnoreCase(input)) {
@ -477,6 +482,10 @@ public class ActionFactory implements ConversationAbandonedListener {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorAlpha"));
return new ActionSelectCreatePrompt(context, ActionFactory.this);
}
if (input.equals("")) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
return new ActionSelectCreatePrompt(context, ActionFactory.this);
}
context.setSessionData(CK.E_NAME, input);
names.add(input);
return new ActionMainPrompt(context, ActionFactory.this);