diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMainPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMainPrompt.java index 3f7d9ac17..d211a25b5 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMainPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMainPrompt.java @@ -36,6 +36,7 @@ import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.Prompt; import org.bukkit.conversations.StringPrompt; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.AbstractMap; import java.util.Arrays; @@ -72,7 +73,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { @Override public String getTitle(final ConversationContext context) { - return (String) context.getSessionData(CK.Q_NAME) + " | " + Lang.get("stageEditorStage") + " " + stageNum; + return context.getSessionData(CK.Q_NAME) + " | " + Lang.get("stageEditorStage") + " " + stageNum; } @Override @@ -88,17 +89,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { case 8: return ChatColor.BLUE; case 9: - if (!hasObjective) { - return ChatColor.GRAY; - } else { - return ChatColor.BLUE; - } case 10: - if (!hasObjective) { - return ChatColor.GRAY; - } else { - return ChatColor.BLUE; - } case 11: if (!hasObjective) { return ChatColor.GRAY; @@ -286,47 +277,56 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { if (context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; + final StringBuilder text = new StringBuilder("\n"); final LinkedList locations = (LinkedList) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS); final LinkedList radii = (LinkedList) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_RADIUS); final LinkedList names = (LinkedList) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_NAMES); - for (int i = 0; i < locations.size(); i++) { - text += ChatColor.GRAY + " - " + Lang.get("stageEditorReachRadii1") + " " + ChatColor.BLUE - + radii.get(i) + ChatColor.GRAY + " " + Lang.get("stageEditorReachRadii2") + " " - + ChatColor.AQUA + names.get(i) + ChatColor.GRAY + " (" + ChatColor.DARK_AQUA - + locations.get(i) + ChatColor.GRAY + ")\n"; + if (locations != null && radii != null && names != null) { + for (int i = 0; i < locations.size(); i++) { + text.append(ChatColor.GRAY).append(" - ").append(Lang.get("stageEditorReachRadii1")) + .append(" ").append(ChatColor.BLUE).append(radii.get(i)).append(ChatColor.GRAY) + .append(" ").append(Lang.get("stageEditorReachRadii2")).append(" ") + .append(ChatColor.AQUA).append(names.get(i)).append(ChatColor.GRAY).append(" (") + .append(ChatColor.DARK_AQUA).append(locations.get(i)).append(ChatColor.GRAY) + .append(")\n"); + } } - return text; + return text.toString(); } case 7: if (context.getSessionData(stagePrefix + CK.S_PASSWORD_PHRASES) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; + StringBuilder text = new StringBuilder("\n"); final LinkedList passPhrases = (LinkedList) context.getSessionData(stagePrefix + CK.S_PASSWORD_PHRASES); final LinkedList passDisplays = (LinkedList) context.getSessionData(stagePrefix + CK.S_PASSWORD_DISPLAYS); - for (int i = 0; i < passDisplays.size(); i++) { - text += ChatColor.AQUA + " - \"" + passDisplays.get(i) + "\"\n"; - text += ChatColor.DARK_AQUA + " - " + passPhrases.get(i) + "\n"; + if (passPhrases != null && passDisplays != null) { + for (int i = 0; i < passDisplays.size(); i++) { + text.append(ChatColor.AQUA).append(" - \"").append(passDisplays.get(i)).append("\"\n"); + text.append(ChatColor.DARK_AQUA).append(" - ").append(passPhrases.get(i)).append("\n"); + } } - return text; + return text.toString(); } case 8: if (context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; - final LinkedList customObjs + final StringBuilder text = new StringBuilder("\n"); + final LinkedList customObj = (LinkedList) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES); - for (final String s : customObjs) { - text += ChatColor.LIGHT_PURPLE + " - " + ChatColor.GOLD + s + "\n"; + if (customObj != null) { + for (final String s : customObj) { + text.append(ChatColor.LIGHT_PURPLE).append(" - ").append(ChatColor.GOLD).append(s) + .append("\n"); + } } - return text; + return text.toString(); } case 9: if (!hasObjective) { @@ -356,8 +356,12 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { if (context.getSessionData(stagePrefix + CK.S_DELAY) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - final long time = (Long) context.getSessionData(stagePrefix + CK.S_DELAY); - return ChatColor.GRAY + "(" + ChatColor.AQUA + MiscUtil.getTime(time) + ChatColor.GRAY + ")"; + final Long time = (Long) context.getSessionData(stagePrefix + CK.S_DELAY); + if (time == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + return ChatColor.GRAY + "(" + ChatColor.AQUA + MiscUtil.getTime(time) + ChatColor.GRAY + ")"; + } } } case 12: @@ -401,13 +405,18 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } } else { - String text = "\n"; - final LinkedList overrides = new LinkedList(); - overrides.addAll((List) context.getSessionData(stagePrefix + CK.S_OVERRIDE_DISPLAY)); - for (int i = 0; i < overrides.size(); i++) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + overrides.get(i) + "\n"; + final StringBuilder text = new StringBuilder("\n"); + if (stagePrefix != null) { + final List overrides + = (List) context.getSessionData(stagePrefix + CK.S_OVERRIDE_DISPLAY); + if (overrides != null) { + for (String override : overrides) { + text.append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(override) + .append("\n"); + } + } } - return text; + return text.toString(); } case 16: case 17: @@ -419,13 +428,13 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { @SuppressWarnings("unchecked") @Override - public String getPromptText(final ConversationContext context) { + public @NotNull String getPromptText(final ConversationContext context) { final String input = (String) context.getSessionData(classPrefix + "-override"); if (input != null && !input.equalsIgnoreCase(Lang.get("cancel"))) { if (input.equalsIgnoreCase(Lang.get("clear"))) { context.setSessionData(stagePrefix + CK.S_OVERRIDE_DISPLAY, null); } else { - final LinkedList overrides = new LinkedList(); + final LinkedList overrides = new LinkedList<>(); if (context.getSessionData(stagePrefix + CK.S_OVERRIDE_DISPLAY) != null) { overrides.addAll((List) context.getSessionData(stagePrefix + CK.S_OVERRIDE_DISPLAY)); } @@ -436,22 +445,23 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } context.setSessionData(stagePrefix, Boolean.TRUE); checkObjective(context); - - final QuestsEditorPostOpenNumericPromptEvent event - = new QuestsEditorPostOpenNumericPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); - - String text = ChatColor.LIGHT_PURPLE + "- " + ChatColor.AQUA - + getTitle(context).replaceFirst(" \\| ", ChatColor.LIGHT_PURPLE + " | ") + " -"; - for (int i = 1; i <= size; i++) { - text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + " " + getAdditionalText(context, i); + + if (context.getPlugin() != null) { + final QuestsEditorPostOpenNumericPromptEvent event + = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); } - return text; + + final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + "- " + ChatColor.AQUA + + getTitle(context).replaceFirst(" \\| ", ChatColor.LIGHT_PURPLE + " | ") + " -"); + for (int i = 1; i <= size; i++) { + text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ").append(getAdditionalText(context, i)); + } + return text.toString(); } @Override - protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) { + protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) { switch (input.intValue()) { case 1: return new BlocksPrompt(stageNum, context); @@ -576,18 +586,20 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context); } @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { try { final int i = Integer.parseInt(input); if (i < 0) { @@ -601,7 +613,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { .replace("", input)); return new KillPlayerPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_PLAYER_KILL, null); } return new StageMainPrompt(stageNum, context); @@ -668,33 +680,44 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { if (context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS) == null) { return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; - for (final String s : (List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS)) { - text += ChatColor.GRAY + " - " + ChatColor.DARK_AQUA + s + "\n"; + final StringBuilder text = new StringBuilder("\n"); + final List locations + = (List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS); + if (locations != null) { + for (final String s : locations) { + text.append(ChatColor.GRAY).append(" - ").append(ChatColor.DARK_AQUA).append(s) + .append("\n"); + } } - return text; + return text.toString(); } case 2: if (context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_RADIUS) == null) { return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; - for (final Integer i : (List) context - .getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_RADIUS)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n"; + final StringBuilder text = new StringBuilder("\n"); + final List radius + = (List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_RADIUS); + if (radius != null) { + for (final Integer i : radius) { + text.append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(i).append("\n"); + } } - return text; + return text.toString(); } case 3: if (context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_NAMES) == null) { return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; - for (final String s : (List) context.getSessionData(stagePrefix - + CK.S_REACH_LOCATIONS_NAMES)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + final StringBuilder text = new StringBuilder("\n"); + final List names + = (List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_NAMES); + if (names != null) { + for (final String s : names) { + text.append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s).append("\n"); + } } - return text; + return text.toString(); } case 4: case 5: @@ -705,22 +728,25 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenNumericPromptEvent event - = new QuestsEditorPostOpenNumericPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); - - String text = ChatColor.AQUA + "- " + getTitle(context) + " -"; - for (int i = 1; i <= size; i++) { - text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + " " + getAdditionalText(context, i); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenNumericPromptEvent event + = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); } - return text; + + final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -"); + for (int i = 1; i <= size; i++) { + text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) + .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ") + .append(getAdditionalText(context, i)); + } + return text.toString(); } @SuppressWarnings("unchecked") @Override - protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) { + protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) { switch(input.intValue()) { case 1: if (context.getForWhom() instanceof Player) { @@ -757,18 +783,24 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { int one; int two; int three; - if (context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS) != null) { - one = ((List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS)).size(); + final List locations + = (List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS); + final List radius + = (List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_RADIUS); + final List names + = (List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_NAMES); + if (locations != null) { + one = locations.size(); } else { one = 0; } - if (context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_RADIUS) != null) { - two = ((List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_RADIUS)).size(); + if (radius != null) { + two = radius.size(); } else { two = 0; } - if (context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_NAMES) != null) { - three = ((List) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS_NAMES)).size(); + if (names != null) { + three = names.size(); } else { three = 0; } @@ -801,10 +833,12 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context); } @@ -813,18 +847,20 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdAdd"))) { + if (input != null && input.equalsIgnoreCase(Lang.get("cmdAdd"))) { final Block block = plugin.getQuestFactory().getSelectedReachLocations().get(player.getUniqueId()); if (block != null) { final Location loc = block.getLocation(); - LinkedList locs; + LinkedList locations; if (context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS) != null) { - locs = (LinkedList) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS); + locations = (LinkedList) context.getSessionData(stagePrefix + CK.S_REACH_LOCATIONS); } else { - locs = new LinkedList(); + locations = new LinkedList<>(); } - locs.add(ConfigUtil.getLocationInfo(loc)); - context.setSessionData(stagePrefix + CK.S_REACH_LOCATIONS, locs); + if (locations != null) { + locations.add(ConfigUtil.getLocationInfo(loc)); + } + context.setSessionData(stagePrefix + CK.S_REACH_LOCATIONS, locations); final Map temp = plugin.getQuestFactory().getSelectedReachLocations(); temp.remove(player.getUniqueId()); plugin.getQuestFactory().setSelectedReachLocations(temp); @@ -833,7 +869,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { return new ReachLocationPrompt(context); } return new ReachListPrompt(context); - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { final Map temp = plugin.getQuestFactory().getSelectedReachLocations(); temp.remove(player.getUniqueId()); plugin.getQuestFactory().setSelectedReachLocations(temp); @@ -861,10 +897,12 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context); } @@ -872,8 +910,8 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - final LinkedList radii = new LinkedList(); + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + final LinkedList radii = new LinkedList<>(); for (final String s : input.split(" ")) { try { final int i = Integer.parseInt(s); @@ -911,19 +949,20 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context); } @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { - final LinkedList locNames = new LinkedList(); - locNames.addAll(Arrays.asList(input.split(Lang.get("charSemi")))); + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + final LinkedList locNames = new LinkedList<>(Arrays.asList(input.split(Lang.get("charSemi")))); context.setSessionData(stagePrefix + CK.S_REACH_LOCATIONS_NAMES, locNames); } return new ReachListPrompt(context); @@ -987,23 +1026,31 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { if (context.getSessionData(stagePrefix + CK.S_PASSWORD_DISPLAYS) == null) { return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; - for (final String display : (List) context.getSessionData(stagePrefix - + CK.S_PASSWORD_DISPLAYS)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + display + "\n"; + final StringBuilder text = new StringBuilder("\n"); + final List displays = (List) context.getSessionData(stagePrefix + + CK.S_PASSWORD_DISPLAYS); + if (displays != null) { + for (final String display : displays) { + text.append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(display) + .append("\n"); + } } - return text; + return text.toString(); } case 2: if (context.getSessionData(stagePrefix + CK.S_PASSWORD_PHRASES) == null) { return ChatColor.GRAY + " (" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; - for (final String phrase : (List) context.getSessionData(stagePrefix - + CK.S_PASSWORD_PHRASES)) { - text += ChatColor.GRAY + " - " + ChatColor.DARK_AQUA + phrase + "\n"; + final StringBuilder text = new StringBuilder("\n"); + final List phrases = (List) context.getSessionData(stagePrefix + + CK.S_PASSWORD_PHRASES); + if (phrases != null) { + for (final String phrase : phrases) { + text.append(ChatColor.GRAY).append(" - ").append(ChatColor.DARK_AQUA).append(phrase) + .append("\n"); + } } - return text; + return text.toString(); } case 3: case 4: @@ -1014,22 +1061,25 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenNumericPromptEvent event - = new QuestsEditorPostOpenNumericPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); - - String text = ChatColor.AQUA + "- " + getTitle(context) + " -"; - for (int i = 1; i <= size; i++) { - text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + " " + getAdditionalText(context, i); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenNumericPromptEvent event + = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); } - return text; + + final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -"); + for (int i = 1; i <= size; i++) { + text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) + .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ") + .append(getAdditionalText(context, i)); + } + return text.toString(); } @SuppressWarnings("unchecked") @Override - protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) { + protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) { switch(input.intValue()) { case 1: return new PasswordDisplayPrompt(context); @@ -1048,13 +1098,16 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { case 4: int one; int two; - if (context.getSessionData(stagePrefix + CK.S_PASSWORD_DISPLAYS) != null) { - one = ((List) context.getSessionData(stagePrefix + CK.S_PASSWORD_DISPLAYS)).size(); + final List displays + = (List) context.getSessionData(stagePrefix + CK.S_PASSWORD_DISPLAYS); + final List phrases = (List) context.getSessionData(stagePrefix + CK.S_PASSWORD_PHRASES); + if (displays != null) { + one = displays.size(); } else { one = 0; } - if (context.getSessionData(stagePrefix + CK.S_PASSWORD_PHRASES) != null) { - two = ((List) context.getSessionData(stagePrefix + CK.S_PASSWORD_PHRASES)).size(); + if (phrases != null) { + two = phrases.size(); } else { two = 0; } @@ -1087,25 +1140,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context) + "\n"; } @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))) { if (context.getSessionData(stagePrefix + CK.S_PASSWORD_DISPLAYS) != null) { @SuppressWarnings("unchecked") final List displays = (List) context.getSessionData(stagePrefix + CK.S_PASSWORD_DISPLAYS); - displays.add(input); + if (displays != null) { + displays.add(input); + } context.setSessionData(stagePrefix + CK.S_PASSWORD_DISPLAYS, displays); } else { - final List displays = new LinkedList(); + final List displays = new LinkedList<>(); displays.add(input); context.setSessionData(stagePrefix + CK.S_PASSWORD_DISPLAYS, displays); } @@ -1132,25 +1189,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context) + "\n"; } @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))) { if (context.getSessionData(stagePrefix + CK.S_PASSWORD_PHRASES) != null) { @SuppressWarnings("unchecked") final List phrases = (List) context.getSessionData(stagePrefix + CK.S_PASSWORD_PHRASES); - phrases.add(input); + if (phrases != null) { + phrases.add(input); + } context.setSessionData(stagePrefix + CK.S_PASSWORD_PHRASES, phrases); } else { - final List phrases = new LinkedList(); + final List phrases = new LinkedList<>(); phrases.add(input); context.setSessionData(stagePrefix + CK.S_PASSWORD_PHRASES, phrases); } @@ -1227,68 +1288,72 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { if (context.getSessionData(stagePrefix + CK.S_START_EVENT) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - return ChatColor.YELLOW + "(" + ChatColor.AQUA + ((String) context.getSessionData(stagePrefix - + CK.S_START_EVENT)) + ChatColor.YELLOW + ")\n"; + return ChatColor.YELLOW + "(" + ChatColor.AQUA + context.getSessionData(stagePrefix + + CK.S_START_EVENT) + ChatColor.YELLOW + ")\n"; } case 2: if (context.getSessionData(stagePrefix + CK.S_FINISH_EVENT) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - return ChatColor.YELLOW + "(" + ChatColor.AQUA + ((String) context.getSessionData(stagePrefix - + CK.S_FINISH_EVENT)) + ChatColor.YELLOW + ")\n"; + return ChatColor.YELLOW + "(" + ChatColor.AQUA + context.getSessionData(stagePrefix + + CK.S_FINISH_EVENT) + ChatColor.YELLOW + ")\n"; } case 3: if (context.getSessionData(stagePrefix + CK.S_FAIL_EVENT) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - return ChatColor.YELLOW + "(" + ChatColor.AQUA + ((String) context.getSessionData(stagePrefix - + CK.S_FAIL_EVENT)) + ChatColor.YELLOW + ")\n"; + return ChatColor.YELLOW + "(" + ChatColor.AQUA + context.getSessionData(stagePrefix + + CK.S_FAIL_EVENT) + ChatColor.YELLOW + ")\n"; } case 4: if (context.getSessionData(stagePrefix + CK.S_DEATH_EVENT) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - return ChatColor.YELLOW + "(" + ChatColor.AQUA + ((String) context.getSessionData(stagePrefix - + CK.S_DEATH_EVENT)) + ChatColor.YELLOW + ")\n"; + return ChatColor.YELLOW + "(" + ChatColor.AQUA + context.getSessionData(stagePrefix + + CK.S_DEATH_EVENT) + ChatColor.YELLOW + ")\n"; } case 5: if (context.getSessionData(stagePrefix + CK.S_DISCONNECT_EVENT) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - return ChatColor.YELLOW + "(" + ChatColor.AQUA + ((String) context.getSessionData(stagePrefix - + CK.S_DISCONNECT_EVENT)) + ChatColor.YELLOW + ")\n"; + return ChatColor.YELLOW + "(" + ChatColor.AQUA + context.getSessionData(stagePrefix + + CK.S_DISCONNECT_EVENT) + ChatColor.YELLOW + ")\n"; } case 6: if (context.getSessionData(stagePrefix + CK.S_CHAT_EVENTS) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; + final StringBuilder text = new StringBuilder("\n"); final LinkedList chatEvents = (LinkedList) context.getSessionData(stagePrefix + CK.S_CHAT_EVENTS); final LinkedList chatEventTriggers = (LinkedList) context.getSessionData(stagePrefix + CK.S_CHAT_EVENT_TRIGGERS); - for (final String event : chatEvents) { - text += ChatColor.AQUA + " - " + event + ChatColor.BLUE + " (" - + Lang.get("stageEditorTriggeredBy") + ": \"" - + chatEventTriggers.get(chatEvents.indexOf(event)) + "\")\n"; + if (chatEvents != null && chatEventTriggers != null) { + for (final String event : chatEvents) { + text.append(ChatColor.AQUA).append(" - ").append(event).append(ChatColor.BLUE) + .append(" (").append(Lang.get("stageEditorTriggeredBy")).append(": \"") + .append(chatEventTriggers.get(chatEvents.indexOf(event))).append("\")\n"); + } } - return text; + return text.toString(); } case 7: if (context.getSessionData(stagePrefix + CK.S_COMMAND_EVENTS) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = "\n"; + final StringBuilder text = new StringBuilder("\n"); final LinkedList commandEvents = (LinkedList) context.getSessionData(stagePrefix + CK.S_COMMAND_EVENTS); final LinkedList commandEventTriggers = (LinkedList) context.getSessionData(stagePrefix + CK.S_COMMAND_EVENT_TRIGGERS); - for (final String event : commandEvents) { - text += ChatColor.AQUA + " - " + event + ChatColor.BLUE + " (" - + Lang.get("stageEditorTriggeredBy") + ": \"" - + commandEventTriggers.get(commandEvents.indexOf(event)) + "\")\n"; + if (commandEvents != null && commandEventTriggers != null) { + for (final String event : commandEvents) { + text.append(ChatColor.AQUA).append(" - ").append(event).append(ChatColor.BLUE) + .append(" (").append(Lang.get("stageEditorTriggeredBy")).append(": \"") + .append(commandEventTriggers.get(commandEvents.indexOf(event))).append("\")\n"); + } } - return text; + return text.toString(); } case 8: return ""; @@ -1298,21 +1363,24 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenNumericPromptEvent event - = new QuestsEditorPostOpenNumericPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); - - String text = ChatColor.AQUA + "- " + getTitle(context) + " -"; - for (int i = 1; i <= size; i++) { - text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + " " + getAdditionalText(context, i); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenNumericPromptEvent event + = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); } - return text; + + final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -"); + for (int i = 1; i <= size; i++) { + text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) + .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ") + .append(getAdditionalText(context, i)); + } + return text.toString(); } @Override - protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) { + protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) { switch(input.intValue()) { case 1: return new StartActionPrompt(context); @@ -1353,27 +1421,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } - String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -\n"); if (plugin.getLoadedActions().isEmpty()) { - text += ChatColor.RED + "- " + Lang.get("none") + "\n"; + text.append(ChatColor.RED).append("- ").append(Lang.get("none")).append("\n"); } else { for (final Action a : plugin.getLoadedActions()) { - text += ChatColor.GREEN + "- " + a.getName() + "\n"; + text.append(ChatColor.GREEN).append("- ").append(a.getName()).append("\n"); } } - return text + ChatColor.YELLOW + getQueryText(context); + return text.toString() + ChatColor.YELLOW + getQueryText(context); } @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { Action found = null; for (final Action a : plugin.getLoadedActions()) { if (a.getName().equalsIgnoreCase(input)) { @@ -1389,9 +1459,9 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { context.setSessionData(stagePrefix + CK.S_START_EVENT, found.getName()); return new ActionListPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new ActionListPrompt(context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_START_EVENT, null); player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared")); return new ActionListPrompt(context); @@ -1418,27 +1488,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } - String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -\n"); if (plugin.getLoadedActions().isEmpty()) { - text += ChatColor.RED + "- " + Lang.get("none"); + text.append(ChatColor.RED).append("- ").append(Lang.get("none")); } else { for (final Action a : plugin.getLoadedActions()) { - text += ChatColor.GREEN + "- " + a.getName() + "\n"; + text.append(ChatColor.GREEN).append("- ").append(a.getName()).append("\n"); } } - return text + ChatColor.YELLOW + getQueryText(context); + return text.toString() + ChatColor.YELLOW + getQueryText(context); } @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { Action found = null; for (final Action a : plugin.getLoadedActions()) { if (a.getName().equalsIgnoreCase(input)) { @@ -1454,9 +1526,9 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { context.setSessionData(stagePrefix + CK.S_FINISH_EVENT, found.getName()); return new ActionListPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new ActionListPrompt(context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_FINISH_EVENT, null); player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared")); return new ActionListPrompt(context); @@ -1483,27 +1555,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } - String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -\n"); if (plugin.getLoadedActions().isEmpty()) { - text += ChatColor.RED + "- " + Lang.get("none"); + text.append(ChatColor.RED).append("- ").append(Lang.get("none")); } else { for (final Action a : plugin.getLoadedActions()) { - text += ChatColor.GREEN + "- " + a.getName() + "\n"; + text.append(ChatColor.GREEN).append("- ").append(a.getName()).append("\n"); } } - return text + ChatColor.YELLOW + getQueryText(context); + return text.toString() + ChatColor.YELLOW + getQueryText(context); } @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { Action found = null; for (final Action a : plugin.getLoadedActions()) { if (a.getName().equalsIgnoreCase(input)) { @@ -1519,9 +1593,9 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { context.setSessionData(stagePrefix + CK.S_FAIL_EVENT, found.getName()); return new ActionListPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new ActionListPrompt(context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_FAIL_EVENT, null); player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared")); return new ActionListPrompt(context); @@ -1548,27 +1622,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } - String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -\n"); if (plugin.getLoadedActions().isEmpty()) { - text += ChatColor.RED + "- " + Lang.get("none") + "\n"; + text.append(ChatColor.RED).append("- ").append(Lang.get("none")).append("\n"); } else { for (final Action a : plugin.getLoadedActions()) { - text += ChatColor.GREEN + "- " + a.getName() + "\n"; + text.append(ChatColor.GREEN).append("- ").append(a.getName()).append("\n"); } } - return text + ChatColor.YELLOW + getQueryText(context); + return text.toString() + ChatColor.YELLOW + getQueryText(context); } @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { Action found = null; for (final Action a : plugin.getLoadedActions()) { if (a.getName().equalsIgnoreCase(input)) { @@ -1584,9 +1660,9 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { context.setSessionData(stagePrefix + CK.S_DEATH_EVENT, found.getName()); return new ActionListPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new ActionListPrompt(context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_DEATH_EVENT, null); player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared")); return new ActionListPrompt(context); @@ -1613,27 +1689,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } - String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -\n"); if (plugin.getLoadedActions().isEmpty()) { - text += ChatColor.RED + "- " + Lang.get("none"); + text.append(ChatColor.RED).append("- ").append(Lang.get("none")); } else { for (final Action a : plugin.getLoadedActions()) { - text += ChatColor.GREEN + "- " + a.getName() + "\n"; + text.append(ChatColor.GREEN).append("- ").append(a.getName()).append("\n"); } } - return text + ChatColor.YELLOW + getQueryText(context); + return text.toString() + ChatColor.YELLOW + getQueryText(context); } @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { Action found = null; for (final Action a : plugin.getLoadedActions()) { if (a.getName().equalsIgnoreCase(input)) { @@ -1649,9 +1727,9 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { context.setSessionData(stagePrefix + CK.S_DISCONNECT_EVENT, found.getName()); return new ActionListPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new ActionListPrompt(context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_DISCONNECT_EVENT, null); player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorEventCleared")); return new ActionListPrompt(context); @@ -1678,26 +1756,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } - String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -\n"); if (plugin.getLoadedActions().isEmpty()) { - text += ChatColor.RED + "- " + Lang.get("none"); + text.append(ChatColor.RED).append("- ").append(Lang.get("none")); } else { for (final Action a : plugin.getLoadedActions()) { - text += ChatColor.GREEN + "- " + a.getName() + "\n"; + text.append(ChatColor.GREEN).append("- ").append(a.getName()).append("\n"); } } - return text + ChatColor.YELLOW + getQueryText(context); + return text.toString() + ChatColor.YELLOW + getQueryText(context); } @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { Action found = null; for (final Action a : plugin.getLoadedActions()) { if (a.getName().equalsIgnoreCase(input)) { @@ -1713,9 +1794,9 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { context.setSessionData(stagePrefix + CK.S_CHAT_TEMP_EVENT, found.getName()); return new ChatActionTriggerPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new ActionListPrompt(context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_CHAT_EVENTS, null); context.setSessionData(stagePrefix + CK.S_CHAT_EVENT_TRIGGERS, null); player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorChatEventsCleared")); @@ -1740,29 +1821,38 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { @Override public String getQueryText(final ConversationContext context) { final String tempEvent = (String) context.getSessionData(stagePrefix + CK.S_CHAT_TEMP_EVENT); - return Lang.get("stageEditorChatEventsTriggerPrompt").replace("", tempEvent) - .replace("", tempEvent); + if (tempEvent != null) { + return Lang.get("stageEditorChatEventsTriggerPrompt").replace("", tempEvent) + .replace("", tempEvent); + } else { + return Lang.get("stageEditorChatEventsTriggerPrompt"); + } } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } final String tempEvent = (String) context.getSessionData(stagePrefix + CK.S_CHAT_TEMP_EVENT); String text = ChatColor.GOLD + "- " + getTitle(context) + " -\n"; - text += ChatColor.YELLOW + getQueryText(context) - .replaceFirst(tempEvent, ChatColor.AQUA + tempEvent + ChatColor.YELLOW); + if (tempEvent != null) { + text += ChatColor.YELLOW + getQueryText(context) + .replaceFirst(tempEvent, ChatColor.AQUA + tempEvent + ChatColor.YELLOW); + } return text; } @SuppressWarnings("unchecked") @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))) { if (context.getSessionData(stagePrefix + CK.S_CHAT_EVENTS) == null) { - final LinkedList chatEvents = new LinkedList(); - final LinkedList chatEventTriggers = new LinkedList(); + final LinkedList chatEvents = new LinkedList<>(); + final LinkedList chatEventTriggers = new LinkedList<>(); final String event = (String) context.getSessionData(stagePrefix + CK.S_CHAT_TEMP_EVENT); chatEvents.add(event); chatEventTriggers.add(input.trim()); @@ -1775,13 +1865,15 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { final LinkedList chatEventTriggers = (LinkedList) context.getSessionData(stagePrefix + CK.S_CHAT_EVENT_TRIGGERS); final String event = (String) context.getSessionData(stagePrefix + CK.S_CHAT_TEMP_EVENT); - chatEvents.add(event); - chatEventTriggers.add(input.trim()); - context.setSessionData(stagePrefix + CK.S_CHAT_EVENTS, chatEvents); - context.setSessionData(stagePrefix + CK.S_CHAT_EVENT_TRIGGERS, chatEventTriggers); + if (chatEvents != null && chatEventTriggers != null) { + chatEvents.add(event); + chatEventTriggers.add(input.trim()); + context.setSessionData(stagePrefix + CK.S_CHAT_EVENTS, chatEvents); + context.setSessionData(stagePrefix + CK.S_CHAT_EVENT_TRIGGERS, chatEventTriggers); + } return new ActionListPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new ActionListPrompt(context); } else { return new ChatActionTriggerPrompt(context); @@ -1806,26 +1898,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } - String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -\n"); if (plugin.getLoadedActions().isEmpty()) { - text += ChatColor.RED + "- " + Lang.get("none"); + text.append(ChatColor.RED).append("- ").append(Lang.get("none")); } else { for (final Action a : plugin.getLoadedActions()) { - text += ChatColor.GREEN + "- " + a.getName() + "\n"; + text.append(ChatColor.GREEN).append("- ").append(a.getName()).append("\n"); } } - return text + ChatColor.YELLOW + getQueryText(context); + return text.toString() + ChatColor.YELLOW + getQueryText(context); } @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { Action found = null; for (final Action a : plugin.getLoadedActions()) { if (a.getName().equalsIgnoreCase(input)) { @@ -1841,9 +1936,9 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { context.setSessionData(stagePrefix + CK.S_COMMAND_TEMP_EVENT, found.getName()); return new CommandActionTriggerPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new ActionListPrompt(context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_COMMAND_EVENTS, null); context.setSessionData(stagePrefix + CK.S_COMMAND_EVENT_TRIGGERS, null); player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorCommandEventsCleared")); @@ -1868,29 +1963,39 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { @Override public String getQueryText(final ConversationContext context) { final String tempEvent = (String) context.getSessionData(stagePrefix + CK.S_COMMAND_TEMP_EVENT); - return Lang.get("stageEditorCommandEventsTriggerPrompt").replace("", tempEvent) - .replace("", tempEvent); + if (tempEvent != null) { + return Lang.get("stageEditorCommandEventsTriggerPrompt").replace("", tempEvent) + .replace("", tempEvent); + } else { + return Lang.get("stageEditorCommandEventsTriggerPrompt"); + } } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } + final String tempEvent = (String) context.getSessionData(stagePrefix + CK.S_COMMAND_TEMP_EVENT); String text = ChatColor.GOLD + "- " + getTitle(context) + " -\n"; - text += ChatColor.YELLOW + getQueryText(context) - .replaceFirst(tempEvent, ChatColor.AQUA + tempEvent + ChatColor.YELLOW); + if (tempEvent != null) { + text += ChatColor.YELLOW + getQueryText(context) + .replaceFirst(tempEvent, ChatColor.AQUA + tempEvent + ChatColor.YELLOW); + } return text; } @SuppressWarnings("unchecked") @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))) { if (context.getSessionData(stagePrefix + CK.S_COMMAND_EVENTS) == null) { - final LinkedList commandEvents = new LinkedList(); - final LinkedList commandEventTriggers = new LinkedList(); + final LinkedList commandEvents = new LinkedList<>(); + final LinkedList commandEventTriggers = new LinkedList<>(); final String event = (String) context.getSessionData(stagePrefix + CK.S_COMMAND_TEMP_EVENT); commandEvents.add(event); commandEventTriggers.add(input.trim()); @@ -1903,13 +2008,15 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { final LinkedList commandEventTriggers = (LinkedList) context.getSessionData(stagePrefix + CK.S_COMMAND_EVENT_TRIGGERS); final String event = (String) context.getSessionData(stagePrefix + CK.S_COMMAND_TEMP_EVENT); - commandEvents.add(event); - commandEventTriggers.add(input.trim()); - context.setSessionData(stagePrefix + CK.S_COMMAND_EVENTS, commandEvents); - context.setSessionData(stagePrefix + CK.S_COMMAND_EVENT_TRIGGERS, commandEventTriggers); + if (commandEvents != null && commandEventTriggers != null) { + commandEvents.add(event); + commandEventTriggers.add(input.trim()); + context.setSessionData(stagePrefix + CK.S_COMMAND_EVENTS, commandEvents); + context.setSessionData(stagePrefix + CK.S_COMMAND_EVENT_TRIGGERS, commandEventTriggers); + } return new ActionListPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new ActionListPrompt(context); } else { return new CommandActionTriggerPrompt(context); @@ -1934,27 +2041,29 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } - String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -\n"); if (plugin.getLoadedConditions().isEmpty()) { - text += ChatColor.RED + "- " + Lang.get("none") + "\n"; + text.append(ChatColor.RED).append("- ").append(Lang.get("none")).append("\n"); } else { for (final Condition c : plugin.getLoadedConditions()) { - text += ChatColor.GREEN + "- " + c.getName() + "\n"; + text.append(ChatColor.GREEN).append("- ").append(c.getName()).append("\n"); } } - return text + ChatColor.YELLOW + getQueryText(context); + return text.toString() + ChatColor.YELLOW + getQueryText(context); } @Override public Prompt acceptInput(final ConversationContext context, final String input) { final Player player = (Player) context.getForWhom(); - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { Condition found = null; for (final Condition c : plugin.getLoadedConditions()) { if (c.getName().equalsIgnoreCase(input)) { @@ -1970,9 +2079,9 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { context.setSessionData(stagePrefix + CK.S_CONDITION, found.getName()); return new StageMainPrompt(stageNum, context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) { return new StageMainPrompt(stageNum, context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_CONDITION, null); player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorConditionCleared")); return new StageMainPrompt(stageNum, context); @@ -1999,39 +2108,44 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { + public @NotNull String getPromptText(final @NotNull ConversationContext context) { final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + if (context.getPlugin() != null) { + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context); } @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { - return new StageMainPrompt(stageNum, context); - } - if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { - context.setSessionData(stagePrefix + CK.S_DELAY, null); - context.getForWhom().sendRawMessage(ChatColor.GREEN + Lang.get("stageEditorDelayCleared")); - return new StageMainPrompt(stageNum, context); - } - long stageDelay; - try { - final int i = Integer.parseInt(input); - stageDelay = i * 1000; - } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("", input)); - return new DelayPrompt(context); - } - if (stageDelay < 1000) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum").replace("", "1")); - return new DelayPrompt(context); - } else { - context.setSessionData(stagePrefix + CK.S_DELAY, stageDelay); - return new StageMainPrompt(stageNum, context); + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null) { + if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { + return new StageMainPrompt(stageNum, context); + } + if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + context.setSessionData(stagePrefix + CK.S_DELAY, null); + context.getForWhom().sendRawMessage(ChatColor.GREEN + Lang.get("stageEditorDelayCleared")); + return new StageMainPrompt(stageNum, context); + } + long stageDelay; + try { + final int i = Integer.parseInt(input); + stageDelay = i * 1000L; + } catch (final NumberFormatException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("", input)); + return new DelayPrompt(context); + } + if (stageDelay < 1000) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum").replace("", "1")); + return new DelayPrompt(context); + } else { + context.setSessionData(stagePrefix + CK.S_DELAY, stageDelay); + return new StageMainPrompt(stageNum, context); + } } + return new StageMainPrompt(stageNum, context); } } @@ -2052,21 +2166,23 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context); } @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_DELAY_MESSAGE, input); return new StageMainPrompt(stageNum, context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_DELAY_MESSAGE, null); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorMessageCleared")); return new StageMainPrompt(stageNum, context); @@ -2094,21 +2210,23 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context); } @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_START_MESSAGE, input); return new StageMainPrompt(stageNum, context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_START_MESSAGE, null); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorMessageCleared")); return new StageMainPrompt(stageNum, context); @@ -2135,21 +2253,23 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } return ChatColor.YELLOW + getQueryText(context); } @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_COMPLETE_MESSAGE, input); return new StageMainPrompt(stageNum, context); - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_COMPLETE_MESSAGE, null); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorMessageCleared")); return new StageMainPrompt(stageNum, context); @@ -2204,28 +2324,30 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); - - String text = ChatColor.YELLOW + getQueryText(context) + " (" + ChatColor.RED + Lang.get("stageEditorStage") - + " " + stageNum + ChatColor.YELLOW + ")\n" + ChatColor.GOLD + "(" - + Lang.get("stageEditorConfirmStageNote") + ")\n"; - for (int i = 1; i <= size; i++) { - text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i) + "\n"; + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); } - return text; + + final StringBuilder text = new StringBuilder(ChatColor.YELLOW + getQueryText(context) + " (" + + ChatColor.RED + Lang.get("stageEditorStage") + " " + stageNum + ChatColor.YELLOW + ")\n" + + ChatColor.GOLD + "(" + Lang.get("stageEditorConfirmStageNote") + ")\n"); + for (int i = 1; i <= size; i++) { + text.append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(ChatColor.RESET) + .append(" - ").append(getSelectionText(context, i)).append("\n"); + } + return text.toString(); } @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord")))) { new StageMenuPrompt(context).deleteStage(context, stageNum); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorDeleteSucces")); return new StageMenuPrompt(context); - } else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) { + } else if (input != null && (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord")))) { return new StageMainPrompt(stageNum, context); } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidOption")); @@ -2251,29 +2373,31 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event - = new QuestsEditorPostOpenStringPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + } - String text = ChatColor.LIGHT_PURPLE + "- " + getTitle(context) + " -\n"; + final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + "- " + getTitle(context) + " -\n"); if (plugin.getCustomObjectives().isEmpty()) { - text += "" + ChatColor.DARK_AQUA + ChatColor.UNDERLINE - + "https://pikamug.gitbook.io/quests/casual/modules\n"; - text += ChatColor.DARK_PURPLE + "(" + Lang.get("stageEditorNoModules") + ") "; + text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE) + .append("https://pikamug.gitbook.io/quests/casual/modules\n"); + text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules")).append(") "); } else { for (final CustomObjective co : plugin.getCustomObjectives()) { - text += ChatColor.DARK_PURPLE + " - " + co.getName() + "\n"; + text.append(ChatColor.DARK_PURPLE).append(" - ").append(co.getName()).append("\n"); } } - return text + ChatColor.YELLOW + getQueryText(context); + return text.toString() + ChatColor.YELLOW + getQueryText(context); } @SuppressWarnings("unchecked") @Override - public Prompt acceptInput(final ConversationContext context, final String input) { - if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false - && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { + public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { + if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel")) + && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { CustomObjective found = null; // Check if we have a custom objective with the specified name for (final CustomObjective co : plugin.getCustomObjectives()) { @@ -2296,18 +2420,19 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { // The custom objective may already have been added, so let's check that final LinkedList list = (LinkedList) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES); - final LinkedList> datamapList + final LinkedList> dataMapList = (LinkedList>) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA); final LinkedList countList = (LinkedList) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_COUNT); - if (list.contains(found.getName()) == false) { + if (list != null && !list.contains(found.getName()) && dataMapList != null + && countList != null) { // Hasn't been added yet, so let's do it list.add(found.getName()); - datamapList.addAll(found.getData()); + dataMapList.addAll(found.getData()); countList.add(-999); context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES, list); - context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList); + context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA, dataMapList); } else { // Already added, so inform user context.getForWhom().sendRawMessage(ChatColor.YELLOW @@ -2316,21 +2441,20 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { } } else { // The custom objective hasn't been added yet, so let's do it - final LinkedList> datamapList = new LinkedList>(); - final LinkedList countList = new LinkedList(); - datamapList.addAll(found.getData()); + final LinkedList countList = new LinkedList<>(); + final LinkedList> dataMapList = new LinkedList<>(found.getData()); countList.add(-999); - final LinkedList list = new LinkedList(); + final LinkedList list = new LinkedList<>(); list.add(found.getName()); context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES, list); - context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList); + context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA, dataMapList); context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_COUNT, countList); } // Send user to the count prompt / custom data prompt if there is any needed if (found.canShowCount()) { return new CustomObjectiveCountPrompt(); } - if (found.getData().isEmpty() == false) { + if (!found.getData().isEmpty()) { context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found .getDescriptions()); return new ObjectiveCustomDataListPrompt(); @@ -2339,7 +2463,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorModuleNotFound")); return new CustomObjectivesPrompt(context); } - } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { + } else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES, null); context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA, null); context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, null); @@ -2352,22 +2476,24 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { private class CustomObjectiveCountPrompt extends StringPrompt { @Override - public String getPromptText(final ConversationContext context) { + public @NotNull String getPromptText(final ConversationContext context) { String text = ChatColor.BOLD + "" + ChatColor.AQUA + "- "; @SuppressWarnings("unchecked") final LinkedList list = (LinkedList) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES); - final String objName = list.getLast(); - text += objName + " -\n"; - CustomObjective found = null; - for (final CustomObjective co : plugin.getCustomObjectives()) { - if (co.getName().equals(objName)) { - found = co; - break; + if (list != null && plugin != null) { + final String objName = list.getLast(); + text += objName + " -\n"; + CustomObjective found = null; + for (final CustomObjective co : plugin.getCustomObjectives()) { + if (co.getName().equals(objName)) { + found = co; + break; + } + } + if (found != null) { + text += ChatColor.BLUE + found.getCountPrompt() + "\n\n"; } - } - if (found != null) { - text += ChatColor.BLUE + found.getCountPrompt().toString() + "\n\n"; } return text; } @@ -2379,9 +2505,47 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { final int num = Integer.parseInt(input); final LinkedList counts = (LinkedList) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_COUNT); - counts.set(counts.size() - 1, num); final LinkedList list = (LinkedList) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES); + if (counts != null && list != null && plugin != null) { + counts.set(counts.size() - 1, num); + final String objName = list.getLast(); + CustomObjective found = null; + for (final CustomObjective co : plugin.getCustomObjectives()) { + if (co.getName().equals(objName)) { + found = co; + break; + } + } + if (found != null && !found.getData().isEmpty()) { + context.setSessionData(stagePrefix + + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.getDescriptions()); + return new ObjectiveCustomDataListPrompt(); + } else { + return new StageMainPrompt(stageNum, context); + } + } + } catch (final NumberFormatException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber") + .replace("", input)); + return new CustomObjectiveCountPrompt(); + } + return new StageMainPrompt(stageNum, context); + } + } + + private class ObjectiveCustomDataListPrompt extends StringPrompt { + + @SuppressWarnings("unchecked") + @Override + public @NotNull String getPromptText(final ConversationContext context) { + StringBuilder text = new StringBuilder(ChatColor.GOLD + "- "); + final LinkedList list = (LinkedList) context.getSessionData(stagePrefix + + CK.S_CUSTOM_OBJECTIVES); + final LinkedList> dataMapList + = (LinkedList>) context.getSessionData(stagePrefix + + CK.S_CUSTOM_OBJECTIVES_DATA); + if (list != null && plugin != null) { final String objName = list.getLast(); CustomObjective found = null; for (final CustomObjective co : plugin.getCustomObjectives()) { @@ -2390,62 +2554,34 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { break; } } - if (found != null && found.getData().isEmpty() == false) { - context.setSessionData(stagePrefix - + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.getDescriptions()); - return new ObjectiveCustomDataListPrompt(); - } else { - return new StageMainPrompt(stageNum, context); + if (found == null) { + return "Could not find custom objective"; } - } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber") - .replace("", input)); - return new CustomObjectiveCountPrompt(); - } - } - } - - private class ObjectiveCustomDataListPrompt extends StringPrompt { - - @SuppressWarnings("unchecked") - @Override - public String getPromptText(final ConversationContext context) { - String text = ChatColor.GOLD + "- "; - final LinkedList list = (LinkedList) context.getSessionData(stagePrefix - + CK.S_CUSTOM_OBJECTIVES); - final LinkedList> datamapList - = (LinkedList>) context.getSessionData(stagePrefix - + CK.S_CUSTOM_OBJECTIVES_DATA); - final String objName = list.getLast(); - CustomObjective found = null; - for (final CustomObjective co : plugin.getCustomObjectives()) { - if (co.getName().equals(objName)) { - found = co; - break; - } - } - if (found == null) { - return "Could not find custom objective"; - } - text += objName + " -\n"; - int index = 1; - for (final Entry datamap : found.getData()) { - for (final Entry currentData : datamapList) { - if (currentData.getKey().equals(datamap.getKey())) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + index + ChatColor.RESET + ChatColor.YELLOW - + " - " + datamap.getKey(); - if (currentData.getValue() != null) { - text += ChatColor.GRAY + " (" + ChatColor.AQUA + ChatColor.translateAlternateColorCodes('&', - currentData.getValue().toString()) + ChatColor.GRAY + ")\n"; - } else { - text += ChatColor.GRAY + " (" + Lang.get("noneSet") + ChatColor.GRAY + ")\n"; - } - index++; + text.append(objName).append(" -\n"); + int index = 1; + for (final Entry dataMap : found.getData()) { + if (dataMapList != null) { + for (final Entry currentData : dataMapList) { + if (currentData.getKey().equals(dataMap.getKey())) { + text.append(ChatColor.BLUE).append(ChatColor.BOLD).append(index).append(ChatColor.RESET) + .append(ChatColor.YELLOW).append(" - ").append(dataMap.getKey()); + if (currentData.getValue() != null) { + text.append(ChatColor.GRAY).append(" (").append(ChatColor.AQUA) + .append(ChatColor.translateAlternateColorCodes('&', + currentData.getValue().toString())).append(ChatColor.GRAY).append(")\n"); + } else { + text.append(ChatColor.GRAY).append(" (").append(Lang.get("noneSet")) + .append(ChatColor.GRAY).append(")\n"); + } + index++; + } + } } } + text.append(ChatColor.GREEN).append(ChatColor.BOLD).append(index).append(ChatColor.YELLOW) + .append(" - ").append(Lang.get("done")); } - text += ChatColor.GREEN + "" + ChatColor.BOLD + index + ChatColor.YELLOW + " - " + Lang.get("done"); - return text; + return text.toString(); } @SuppressWarnings("unchecked") @@ -2453,56 +2589,62 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { public Prompt acceptInput(final ConversationContext context, final String input) { final LinkedList list = (LinkedList) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES); - final String objName = list.getLast(); - CustomObjective found = null; - for (final CustomObjective co : plugin.getCustomObjectives()) { - if (co.getName().equals(objName)) { - found = co; - break; - } - } - if (found == null) { - plugin.getLogger().severe("Could not find custom objective following input: " + input); - return new ObjectiveCustomDataListPrompt(); - } - final LinkedList> datamapList = found.getData(); - - int numInput; - try { - numInput = Integer.parseInt(input); - } catch (final NumberFormatException nfe) { - return new ObjectiveCustomDataListPrompt(); - } - if (numInput < 1 || numInput > datamapList.size() + 1) { - return new ObjectiveCustomDataListPrompt(); - } - if (numInput < datamapList.size() + 1) { - final LinkedList datamapKeys = new LinkedList(); - for (final Entry datamap : datamapList) { - datamapKeys.add(datamap.getKey()); - } - // Collections.sort(datamapKeys); - final String selectedKey = datamapKeys.get(numInput - 1); - context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, selectedKey); - return new ObjectiveCustomDataPrompt(); - } else { - for (final Entry datamap - : (LinkedList>) context.getSessionData(stagePrefix - + CK.S_CUSTOM_OBJECTIVES_DATA)) { - if (datamap.getValue() == null) { - return new ObjectiveCustomDataListPrompt(); + if (list != null && plugin != null) { + final String objName = list.getLast(); + CustomObjective found = null; + for (final CustomObjective co : plugin.getCustomObjectives()) { + if (co.getName().equals(objName)) { + found = co; + break; } } - context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, null); - return new StageMainPrompt(stageNum, context); + if (found == null) { + plugin.getLogger().severe("Could not find custom objective following input: " + input); + return new ObjectiveCustomDataListPrompt(); + } + final LinkedList> dataMapList = found.getData(); + + int numInput; + try { + numInput = Integer.parseInt(input); + } catch (final NumberFormatException nfe) { + return new ObjectiveCustomDataListPrompt(); + } + if (numInput < 1 || numInput > dataMapList.size() + 1) { + return new ObjectiveCustomDataListPrompt(); + } + if (numInput < dataMapList.size() + 1) { + final LinkedList dataMapKeys = new LinkedList<>(); + for (final Entry dataMap : dataMapList) { + dataMapKeys.add(dataMap.getKey()); + } + // Collections.sort(dataMapKeys); + final String selectedKey = dataMapKeys.get(numInput - 1); + context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, selectedKey); + return new ObjectiveCustomDataPrompt(); + } else { + final LinkedList> dataMaps + = (LinkedList>) context.getSessionData(stagePrefix + + CK.S_CUSTOM_OBJECTIVES_DATA); + if (dataMaps != null) { + for (final Entry dataMap : dataMaps) { + if (dataMap.getValue() == null) { + return new ObjectiveCustomDataListPrompt(); + } + } + } + context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, null); + return new StageMainPrompt(stageNum, context); + } } + return new StageMainPrompt(stageNum, context); } } private class ObjectiveCustomDataPrompt extends StringPrompt { @Override - public String getPromptText(final ConversationContext context) { + public @NotNull String getPromptText(final ConversationContext context) { String text = ""; final String temp = (String) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP); @SuppressWarnings("unchecked") @@ -2510,7 +2652,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { Map descriptions = (Map) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS); - if (descriptions.get(temp) != null) { + if (descriptions != null && descriptions.get(temp) != null) { text += ChatColor.GOLD + descriptions.get(temp) + "\n"; } String msg = Lang.get("stageEditorCustomDataPrompt"); @@ -2523,16 +2665,18 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt { public Prompt acceptInput(final ConversationContext context, final String input) { @SuppressWarnings("unchecked") final - LinkedList> datamapList + LinkedList> dataMapList = (LinkedList>) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA); - final LinkedList> promptList = new LinkedList>(); + final LinkedList> promptList = new LinkedList<>(); final String temp = (String) context.getSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP); - for (final Entry datamap : datamapList) { - if (datamap.getKey().equals(temp)) { - promptList.add(new AbstractMap.SimpleEntry(datamap.getKey(), input)); - } else { - promptList.add(new AbstractMap.SimpleEntry(datamap.getKey(), datamap.getValue())); + if (dataMapList != null) { + for (final Entry dataMap : dataMapList) { + if (dataMap.getKey().equals(temp)) { + promptList.add(new AbstractMap.SimpleEntry<>(dataMap.getKey(), input)); + } else { + promptList.add(new AbstractMap.SimpleEntry<>(dataMap.getKey(), dataMap.getValue())); + } } } context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA, promptList); diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMenuPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMenuPrompt.java index c70361abf..e2dd64a36 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMenuPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/stages/StageMenuPrompt.java @@ -21,6 +21,7 @@ import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.Lang; +import org.jetbrains.annotations.NotNull; public class StageMenuPrompt extends QuestsEditorNumericPrompt { @@ -46,11 +47,11 @@ public class StageMenuPrompt extends QuestsEditorNumericPrompt { public ChatColor getNumberColor(final ConversationContext context, final int number) { final int stages = getStages(context); if (number > 0) { - if (number < (stages + 1)) { + if (number < stages + 1) { return ChatColor.BLUE; - } else if (number == (stages + 1)) { + } else if (number == stages + 1) { return ChatColor.BLUE; - } else if (number == (stages + 2)) { + } else if (number == stages + 2) { return ChatColor.GREEN; } } @@ -61,11 +62,11 @@ public class StageMenuPrompt extends QuestsEditorNumericPrompt { public String getSelectionText(final ConversationContext context, final int number) { final int stages = getStages(context); if (number > 0) { - if (number < (stages + 1) && number > 0) { + if (number < stages + 1) { return ChatColor.GOLD + Lang.get("stageEditorEditStage") + " " + number; - } else if (number == (stages + 1)) { + } else if (number == stages + 1) { return ChatColor.YELLOW + Lang.get("stageEditorNewStage"); - } else if (number == (stages + 2)) { + } else if (number == stages + 2) { return ChatColor.YELLOW + Lang.get("done"); } } @@ -78,20 +79,23 @@ public class StageMenuPrompt extends QuestsEditorNumericPrompt { } @Override - public String getPromptText(final ConversationContext context) { - final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); - context.getPlugin().getServer().getPluginManager().callEvent(event); - - String text = ChatColor.LIGHT_PURPLE + "- " + getTitle(context) + " -"; - for (int i = 1; i <= (getStages(context) + size); i++) { - text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " - + getSelectionText(context, i); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenNumericPromptEvent event + = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); } - return text; + + final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + "- " + getTitle(context) + " -"); + for (int i = 1; i <= (getStages(context) + size); i++) { + text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) + .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)); + } + return text.toString(); } @Override - protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) { + protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) { final int i = input.intValue(); final int stages = getStages(context); if (i > 0) { @@ -123,10 +127,7 @@ public class StageMenuPrompt extends QuestsEditorNumericPrompt { int current = stageNum; String pref = "stage" + current; String newPref; - boolean last = false; - if (stageNum == stages) { - last = true; - } + boolean last = stageNum == stages; while (true) { if (!last) { current++;