From c40372cb4b4abf7bc3f4ca423a65a4e352bdaecd Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Tue, 21 Apr 2020 02:44:34 -0400 Subject: [PATCH] Supply external conversation hooks, part 25 --- .../convo/quests/objectives/BlocksPrompt.java | 46 + .../convo/quests/objectives/ItemsPrompt.java | 10 + .../convo/quests/objectives/MobsPrompt.java | 887 ++++++++++++------ .../convo/quests/objectives/NPCsPrompt.java | 480 ++++++---- main/src/main/resources/strings.yml | 3 - 5 files changed, 936 insertions(+), 490 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java index cec2829f3..3b59d95ff 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java @@ -19,6 +19,7 @@ import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt; import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; +import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; @@ -371,6 +372,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -425,6 +429,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -472,6 +479,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -675,6 +685,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -729,6 +742,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -776,6 +792,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -979,6 +998,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -1033,6 +1055,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -1080,6 +1105,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -1283,6 +1311,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -1337,6 +1368,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -1384,6 +1418,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -1587,6 +1624,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -1641,6 +1681,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -1688,6 +1731,9 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/objectives/ItemsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/ItemsPrompt.java index df059151f..5ca1b5fa8 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/objectives/ItemsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/ItemsPrompt.java @@ -20,6 +20,7 @@ import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt; import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; +import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; @@ -599,6 +600,9 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt { @SuppressWarnings("deprecation") @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + String text = ChatColor.LIGHT_PURPLE + "- " + ChatColor.DARK_PURPLE + getTitle(context) + ChatColor.LIGHT_PURPLE + " -\n"; for (int i = 0; i < Enchantment.values().length; i++) { @@ -654,6 +658,9 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } @@ -701,6 +708,9 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt { @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + return ChatColor.YELLOW + getQueryText(context); } diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/objectives/MobsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/MobsPrompt.java index ff46c4c79..f3e26ccc4 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/objectives/MobsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/MobsPrompt.java @@ -23,17 +23,17 @@ import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.FixedSetPrompt; import org.bukkit.conversations.Prompt; -import org.bukkit.conversations.StringPrompt; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; import me.blackvein.quests.Quests; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt; import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; +import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ConfigUtil; import me.blackvein.quests.util.Lang; @@ -197,15 +197,15 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { protected Prompt acceptValidatedInput(ConversationContext context, Number input) { switch(input.intValue()) { case 1: - return new MobListPrompt(); + return new MobListPrompt(context); case 2: - return new TameListPrompt(); + return new TameListPrompt(context); case 3: - return new FishPrompt(); + return new FishPrompt(context); case 4: - return new CowsPrompt(); + return new CowsPrompt(context); case 5: - return new ShearListPrompt(); + return new ShearListPrompt(context); case 6: try { return new StageMainPrompt(stageNum, context); @@ -217,131 +217,161 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { return new MobsPrompt(stageNum, context); } } - - private class MobListPrompt extends FixedSetPrompt { + public class MobListPrompt extends QuestsEditorNumericPrompt { + + public MobListPrompt(ConversationContext context) { + super(context); + } - public MobListPrompt() { - super("1", "2", "3", "4", "5", "6", "7"); + private final int size = 7; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("stageEditorKillMobs"); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + case 3: + case 4: + case 5: + return ChatColor.BLUE; + case 6: + return ChatColor.RED; + case 7: + return ChatColor.GREEN; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch(number) { + case 1: + return ChatColor.YELLOW + Lang.get("stageEditorSetMobTypes"); + case 2: + return ChatColor.YELLOW + Lang.get("stageEditorSetMobAmounts"); + case 3: + return ChatColor.YELLOW + Lang.get("stageEditorSetKillLocations"); + case 4: + return ChatColor.YELLOW + Lang.get("stageEditorSetKillLocationRadii"); + case 5: + return ChatColor.YELLOW + Lang.get("stageEditorSetKillLocationNames"); + case 6: + return ChatColor.GREEN + Lang.get("cancel"); + case 7: + return ChatColor.GREEN + Lang.get("done"); + default: + return null; + } + } + + @SuppressWarnings("unchecked") + public String getAdditionalText(ConversationContext context, int number) { + switch(number) { + case 1: + if (context.getSessionData(pref + CK.S_MOB_TYPES) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (String s : (List) context.getSessionData(pref + CK.S_MOB_TYPES)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + return text; + } + case 2: + if (context.getSessionData(pref + CK.S_MOB_AMOUNTS) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (Integer i : (List) context.getSessionData(pref + CK.S_MOB_AMOUNTS)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n"; + } + return text; + } + case 3: + if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (String s : (List) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + return text; + } + case 4: + if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (int i : (List) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n"; + } + return text; + } + case 5: + if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (String s : (List) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + return text; + } + case 6: + case 7: + return ""; + default: + return null; + } } @Override public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("stageEditorKillMobs") + " -\n"; - if (context.getSessionData(pref + CK.S_MOB_TYPES) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetMobTypes") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetMobAmounts") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.GRAY + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.GRAY + " - " - + Lang.get("stageEditorSetKillLocations") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.GRAY + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.GRAY + " - " - + Lang.get("stageEditorSetKillLocationRadii") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.GRAY + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.GRAY + " - " - + Lang.get("stageEditorSetKillLocationNames") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.RED + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "7" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetMobTypes") + "\n"; - for (String s : getMobTypes(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; - } - if (context.getSessionData(pref + CK.S_MOB_AMOUNTS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetMobAmounts") + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetMobAmounts") + "\n"; - for (Integer i : getMobAmounts(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n"; - } - } - if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorSetKillLocations") + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorSetKillLocations") + "\n"; - for (String s : getKillLocations(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; - } - } - if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorSetKillLocationRadii") + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorSetKillLocationRadii") + "\n"; - for (int i : getKillRadii(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n"; - } - } - if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorSetKillLocationNames") + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorSetKillLocationNames") + "\n"; - for (String s : getKillLocationNames(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; - } - } - text += ChatColor.RED + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "7" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); + QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; } return text; } - + @SuppressWarnings("unchecked") @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { - return new MobTypesPrompt(); - } else if (input.equalsIgnoreCase("2")) { - if (context.getSessionData(pref + CK.S_MOB_TYPES) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoMobTypes")); - return new MobListPrompt(); - } else { - return new MobAmountsPrompt(); - } - } else if (input.equalsIgnoreCase("3")) { - if (context.getSessionData(pref + CK.S_MOB_TYPES) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoMobTypes")); - return new MobListPrompt(); - } else { - Map temp = plugin.getQuestFactory().getSelectedKillLocations(); - temp.put(((Player) context.getForWhom()).getUniqueId(), null); - plugin.getQuestFactory().setSelectedKillLocations(temp); - return new MobLocationPrompt(); - } - } else if (input.equalsIgnoreCase("4")) { - if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoKillLocations")); - return new MobListPrompt(); - } else { - return new MobRadiiPrompt(); - } - } else if (input.equalsIgnoreCase("5")) { - if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoKillLocations")); - return new MobListPrompt(); - } else { - return new MobLocationNamesPrompt(); - } - } else if (input.equalsIgnoreCase("6")) { + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + switch(input.intValue()) { + case 1: + return new MobTypesPrompt(context); + case 2: + return new MobAmountsPrompt(context); + case 3: + Map temp = plugin.getQuestFactory().getSelectedKillLocations(); + temp.put(((Player) context.getForWhom()).getUniqueId(), null); + plugin.getQuestFactory().setSelectedKillLocations(temp); + return new MobLocationPrompt(context); + case 4: + return new MobRadiiPrompt(context); + case 5: + return new MobLocationNamesPrompt(context); + case 6: context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); context.setSessionData(pref + CK.S_MOB_TYPES, null); context.setSessionData(pref + CK.S_MOB_AMOUNTS, null); context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS, null); context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS, null); context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, null); - return new MobListPrompt(); - } else if (input.equalsIgnoreCase("7")) { + return new MobListPrompt(context); + case 7: int one; int two; int three; @@ -378,50 +408,43 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { return new StageMainPrompt(stageNum, context); } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); - return new MobListPrompt(); + return new MobListPrompt(context); } } else { return new StageMainPrompt(stageNum, context); } } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); - return new MobListPrompt(); + return new MobListPrompt(context); } + default: + return new MobsPrompt(stageNum, context); } - return null; - } - - @SuppressWarnings("unchecked") - private List getMobTypes(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_MOB_TYPES); - } - - @SuppressWarnings("unchecked") - private List getMobAmounts(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_MOB_AMOUNTS); - } - - @SuppressWarnings("unchecked") - private List getKillLocations(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS); - } - - @SuppressWarnings("unchecked") - private List getKillRadii(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS); - } - - @SuppressWarnings("unchecked") - private List getKillLocationNames(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES); } } - private class MobTypesPrompt extends StringPrompt { + public class MobTypesPrompt extends QuestsEditorStringPrompt { + + public MobTypesPrompt(ConversationContext context) { + super(context); + } + @Override + public String getTitle(ConversationContext context) { + return Lang.get("eventEditorMobsTitle"); + } + + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorMobsPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - String mobs = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorMobsTitle") + "\n"; + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + String mobs = ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"; LinkedList mobArr = new LinkedList(Arrays.asList(EntityType.values())); LinkedList toRemove = new LinkedList(); for (int i = 0; i < mobArr.size(); i++) { @@ -438,7 +461,7 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name()) + "\n"; } } - return mobs + ChatColor.YELLOW + Lang.get("stageEditorMobsPrompt"); + return mobs + ChatColor.YELLOW + getQueryText(context); } @Override @@ -452,20 +475,37 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { } else { player.sendMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + Lang.get("stageEditorInvalidMob")); - return new MobTypesPrompt(); + return new MobTypesPrompt(context); } } context.setSessionData(pref + CK.S_MOB_TYPES, mobTypes); } - return new MobListPrompt(); + return new MobListPrompt(context); } } - private class MobAmountsPrompt extends StringPrompt { + public class MobAmountsPrompt extends QuestsEditorStringPrompt { + + public MobAmountsPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorMobAmountsPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("stageEditorMobAmountsPrompt"); + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + return ChatColor.YELLOW + getQueryText(context); } @Override @@ -479,25 +519,42 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { if (i < 1) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum") .replace("", "1")); - return new MobAmountsPrompt(); + return new MobAmountsPrompt(context); } mobAmounts.add(i); } catch (NumberFormatException e) { player.sendMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("", input)); - return new MobAmountsPrompt(); + return new MobAmountsPrompt(context); } } context.setSessionData(pref + CK.S_MOB_AMOUNTS, mobAmounts); } - return new MobListPrompt(); + return new MobListPrompt(context); } } - private class MobLocationPrompt extends StringPrompt { + public class MobLocationPrompt extends QuestsEditorStringPrompt { + + public MobLocationPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorMobLocationPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("stageEditorMobLocationPrompt"); + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + return ChatColor.YELLOW + getQueryText(context); } @SuppressWarnings("unchecked") @@ -521,25 +578,42 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { plugin.getQuestFactory().setSelectedKillLocations(temp); } else { player.sendMessage(ChatColor.RED + Lang.get("stageEditorNoBlock")); - return new MobLocationPrompt(); + return new MobLocationPrompt(context); } - return new MobListPrompt(); + return new MobListPrompt(context); } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { Map temp = plugin.getQuestFactory().getSelectedKillLocations(); temp.remove(player.getUniqueId()); plugin.getQuestFactory().setSelectedKillLocations(temp); - return new MobListPrompt(); + return new MobListPrompt(context); } else { - return new MobLocationPrompt(); + return new MobLocationPrompt(context); } } } - private class MobRadiiPrompt extends StringPrompt { + public class MobRadiiPrompt extends QuestsEditorStringPrompt { + + public MobRadiiPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorMobLocationRadiiPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("stageEditorMobLocationRadiiPrompt"); + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + return ChatColor.YELLOW + getQueryText(context); } @Override @@ -553,26 +627,43 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { if (i < 1) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum") .replace("", "1")); - return new MobRadiiPrompt(); + return new MobRadiiPrompt(context); } radii.add(i); } catch (NumberFormatException e) { player.sendMessage(ChatColor.LIGHT_PURPLE + input + " " + ChatColor.RED + Lang.get("stageEditorInvalidItemName")); - return new MobRadiiPrompt(); + return new MobRadiiPrompt(context); } } context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS, radii); } - return new MobListPrompt(); + return new MobListPrompt(context); } } - private class MobLocationNamesPrompt extends StringPrompt { + public class MobLocationNamesPrompt extends QuestsEditorStringPrompt { + + public MobLocationNamesPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorMobLocationNamesPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("stageEditorMobLocationNamesPrompt"); + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + return ChatColor.YELLOW + getQueryText(context); } @Override @@ -582,15 +673,32 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { locNames.addAll(Arrays.asList(input.split(Lang.get("charSemi")))); context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, locNames); } - return new MobListPrompt(); + return new MobListPrompt(context); } } - private class FishPrompt extends StringPrompt { + public class FishPrompt extends QuestsEditorStringPrompt { + + public FishPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorCatchFishPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("stageEditorCatchFishPrompt"); + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + return ChatColor.YELLOW + getQueryText(context); } @Override @@ -601,14 +709,14 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { int i = Integer.parseInt(input); if (i < 0) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorPositiveAmount")); - return new FishPrompt(); + return new FishPrompt(context); } else if (i > 0) { context.setSessionData(pref + CK.S_FISH, i); } } catch (NumberFormatException e) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber") .replace("", input)); - return new FishPrompt(); + return new FishPrompt(context); } } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(pref + CK.S_FISH, null); @@ -617,11 +725,28 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { } } - private class CowsPrompt extends StringPrompt { + public class CowsPrompt extends QuestsEditorStringPrompt { + + public CowsPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorMilkCowsPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("stageEditorMilkCowsPrompt"); + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + return ChatColor.YELLOW + getQueryText(context); } @Override @@ -632,14 +757,14 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { int i = Integer.parseInt(input); if (i < 0) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorPositiveAmount")); - return new CowsPrompt(); + return new CowsPrompt(context); } else if (i > 0) { context.setSessionData(pref + CK.S_COW_MILK, i); } } catch (NumberFormatException e) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber") .replace("", input)); - return new CowsPrompt(); + return new CowsPrompt(context); } } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(pref + CK.S_COW_MILK, null); @@ -648,66 +773,109 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { } } - private class TameListPrompt extends FixedSetPrompt { + public class TameListPrompt extends QuestsEditorNumericPrompt { - public TameListPrompt() { - super("1", "2", "3", "4"); + public TameListPrompt(ConversationContext context) { + super(context); + } + + private final int size = 4; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("stageEditorTameMobs"); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + return ChatColor.BLUE; + case 3: + return ChatColor.RED; + case 4: + return ChatColor.GREEN; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch(number) { + case 1: + return ChatColor.YELLOW + Lang.get("stageEditorSetMobTypes"); + case 2: + return ChatColor.YELLOW + Lang.get("stageEditorSetTameAmounts"); + case 3: + return ChatColor.GREEN + Lang.get("cancel"); + case 4: + return ChatColor.GREEN + Lang.get("done"); + default: + return null; + } + } + + @SuppressWarnings("unchecked") + public String getAdditionalText(ConversationContext context, int number) { + switch(number) { + case 1: + if (context.getSessionData(pref + CK.S_TAME_TYPES) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (String s : (List) context.getSessionData(pref + CK.S_TAME_TYPES)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + return text; + } + case 2: + if (context.getSessionData(pref + CK.S_TAME_AMOUNTS) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (Integer i : (List) context.getSessionData(pref + CK.S_TAME_AMOUNTS)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n"; + } + return text; + } + case 3: + case 4: + return ""; + default: + return null; + } } @Override public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("stageEditorTameMobs") + " -\n"; - if (context.getSessionData(pref + CK.S_TAME_TYPES) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetMobTypes") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + " - " - + Lang.get("stageEditorSetTameAmounts") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetMobTypes") + "\n"; - for (String s : getTameTypes(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; - } - if (context.getSessionData(pref + CK.S_TAME_AMOUNTS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetTameAmounts") + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetTameAmounts") + "\n"; - for (Integer i : getTameAmounts(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n"; - } - } - text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); + QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; } return text; } - + @SuppressWarnings("unchecked") @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { - return new TameTypesPrompt(); - } else if (input.equalsIgnoreCase("2")) { - if (context.getSessionData(pref + CK.S_TAME_TYPES) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoMobTypes")); - return new TameListPrompt(); - } else { - return new TameAmountsPrompt(); - } - } else if (input.equalsIgnoreCase("3")) { + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + switch(input.intValue()) { + case 1: + return new TameTypesPrompt(context); + case 2: + return new TameAmountsPrompt(context); + case 3: context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); context.setSessionData(pref + CK.S_TAME_TYPES, null); context.setSessionData(pref + CK.S_TAME_AMOUNTS, null); - return new TameListPrompt(); - } else if (input.equalsIgnoreCase("4")) { + return new TameListPrompt(context); + case 4: int one; int two; if (context.getSessionData(pref + CK.S_TAME_TYPES) != null) { @@ -724,28 +892,36 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { return new StageMainPrompt(stageNum, context); } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); - return new TameListPrompt(); + return new TameListPrompt(context); } + default: + return new MobsPrompt(stageNum, context); } - return null; - } - - @SuppressWarnings("unchecked") - private List getTameTypes(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_TAME_TYPES); - } - - @SuppressWarnings("unchecked") - private List getTameAmounts(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_TAME_AMOUNTS); } } - private class TameTypesPrompt extends StringPrompt { + public class TameTypesPrompt extends QuestsEditorStringPrompt { + + public TameTypesPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return Lang.get("eventEditorMobsTitle"); + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorMobsPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - String mobs = ChatColor.LIGHT_PURPLE + Lang.get("eventEditorMobsTitle") + "\n"; + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + String mobs = ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"; final EntityType[] mobArr = EntityType.values(); for (int i = 0; i < mobArr.length; i++) { final EntityType type = mobArr[i]; @@ -755,7 +931,7 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { mobs += MiscUtil.snakeCaseToUpperCamelCase(mobArr[i].name()) + ", "; } mobs = mobs.substring(0, mobs.length() - 2) + "\n"; - return mobs + ChatColor.YELLOW + Lang.get("stageEditorMobsPrompt"); + return mobs + ChatColor.YELLOW + getQueryText(context); } @Override @@ -772,24 +948,41 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { } else { player.sendMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + Lang.get("stageEditorInvalidMob")); - return new TameTypesPrompt(); + return new TameTypesPrompt(context); } } else { player.sendMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + Lang.get("stageEditorInvalidMob")); - return new TameTypesPrompt(); + return new TameTypesPrompt(context); } } } - return new TameListPrompt(); + return new TameListPrompt(context); } } - private class TameAmountsPrompt extends StringPrompt { + public class TameAmountsPrompt extends QuestsEditorStringPrompt { + + public TameAmountsPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorTameAmountsPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("stageEditorTameAmountsPrompt"); + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + return ChatColor.YELLOW + getQueryText(context); } @Override @@ -803,81 +996,124 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { if (i < 1) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum") .replace("", "1")); - return new TameAmountsPrompt(); + return new TameAmountsPrompt(context); } mobAmounts.add(i); } catch (NumberFormatException e) { player.sendMessage(ChatColor.RED + Lang.get("reqNotANumber") .replace("", input)); - return new TameAmountsPrompt(); + return new TameAmountsPrompt(context); } } context.setSessionData(pref + CK.S_TAME_AMOUNTS, mobAmounts); } - return new TameListPrompt(); + return new TameListPrompt(context); } } - private class ShearListPrompt extends FixedSetPrompt { + public class ShearListPrompt extends QuestsEditorNumericPrompt { - public ShearListPrompt() { - super("1", "2", "3", "4"); + public ShearListPrompt(ConversationContext context) { + super(context); } - - @Override - public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("stageEditorShearSheep") + " -\n"; - if (context.getSessionData(pref + CK.S_SHEAR_COLORS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetShearColors") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + " - " - + Lang.get("stageEditorSetShearAmounts") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetShearColors") + "\n"; - for (String s : getShearColors(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; - } - if (context.getSessionData(pref + CK.S_SHEAR_AMOUNTS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetShearAmounts") + " (" + Lang.get("noneSet") + ")\n"; + + private final int size = 4; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("stageEditorShearSheep"); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + return ChatColor.BLUE; + case 3: + return ChatColor.RED; + case 4: + return ChatColor.GREEN; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch(number) { + case 1: + return ChatColor.YELLOW + Lang.get("stageEditorSetShearColors"); + case 2: + return ChatColor.YELLOW + Lang.get("stageEditorSetShearAmounts"); + case 3: + return ChatColor.GREEN + Lang.get("cancel"); + case 4: + return ChatColor.GREEN + Lang.get("done"); + default: + return null; + } + } + + @SuppressWarnings("unchecked") + public String getAdditionalText(ConversationContext context, int number) { + switch(number) { + case 1: + if (context.getSessionData(pref + CK.S_SHEAR_COLORS) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetShearAmounts") + "\n"; - for (Integer i : getShearAmounts(context)) { + String text = "\n"; + for (String s : (List) context.getSessionData(pref + CK.S_SHEAR_COLORS)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; + } + return text; + } + case 2: + if (context.getSessionData(pref + CK.S_SHEAR_AMOUNTS) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (Integer i : (List) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS)) { text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n"; } + return text; } - text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); + case 3: + case 4: + return ""; + default: + return null; + } + } + + @Override + public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; } return text; } - + @SuppressWarnings("unchecked") @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { - return new ShearColorsPrompt(); - } else if (input.equalsIgnoreCase("2")) { - if (context.getSessionData(pref + CK.S_SHEAR_COLORS) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoColors")); - return new ShearListPrompt(); - } else { - return new ShearAmountsPrompt(); - } - } else if (input.equalsIgnoreCase("3")) { + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + switch(input.intValue()) { + case 1: + return new ShearColorsPrompt(context); + case 2: + return new ShearAmountsPrompt(context); + case 3: context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); context.setSessionData(pref + CK.S_SHEAR_COLORS, null); context.setSessionData(pref + CK.S_SHEAR_AMOUNTS, null); - return new ShearListPrompt(); - } else if (input.equalsIgnoreCase("4")) { + return new ShearListPrompt(context); + case 4: int one; int two; if (context.getSessionData(pref + CK.S_SHEAR_COLORS) != null) { @@ -894,28 +1130,36 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { return new StageMainPrompt(stageNum, context); } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); - return new ShearListPrompt(); + return new ShearListPrompt(context); } + default: + return new MobsPrompt(stageNum, context); } - return null; - } - - @SuppressWarnings("unchecked") - private List getShearColors(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_SHEAR_COLORS); - } - - @SuppressWarnings("unchecked") - private List getShearAmounts(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS); } } - private class ShearColorsPrompt extends StringPrompt { + public class ShearColorsPrompt extends QuestsEditorStringPrompt { + + public ShearColorsPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return Lang.get("stageEditorColors"); + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorShearColorsPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - String cols = ChatColor.LIGHT_PURPLE + "- " + Lang.get("stageEditorColors") + " - \n"; + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + String cols = ChatColor.LIGHT_PURPLE + "- " + getTitle(context) + " - \n"; final DyeColor[] colArr = DyeColor.values(); for (int i = 0; i < colArr.length; i++) { if (i < (colArr.length - 1)) { @@ -924,7 +1168,7 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { cols += MiscUtil.snakeCaseToUpperCamelCase(colArr[i].name()) + "\n"; } } - return cols + ChatColor.YELLOW + Lang.get("stageEditorShearColorsPrompt"); + return cols + ChatColor.YELLOW + getQueryText(context); } @Override @@ -939,19 +1183,36 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { } else { player.sendMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + Lang.get("stageEditorInvalidDye")); - return new ShearColorsPrompt(); + return new ShearColorsPrompt(context); } } } - return new ShearListPrompt(); + return new ShearListPrompt(context); } } - private class ShearAmountsPrompt extends StringPrompt { + public class ShearAmountsPrompt extends QuestsEditorStringPrompt { + + public ShearAmountsPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorShearAmountsPrompt"); + } + @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("stageEditorShearAmountsPrompt"); + QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + return ChatColor.YELLOW + getQueryText(context); } @Override @@ -965,17 +1226,17 @@ public class MobsPrompt extends QuestsEditorNumericPrompt { if (i < 1) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum") .replace("", "1")); - return new ShearAmountsPrompt(); + return new ShearAmountsPrompt(context); } shearAmounts.add(i); } catch (NumberFormatException e) { player.sendMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("", input)); - return new ShearAmountsPrompt(); + return new ShearAmountsPrompt(context); } } context.setSessionData(pref + CK.S_SHEAR_AMOUNTS, shearAmounts); } - return new ShearListPrompt(); + return new ShearListPrompt(context); } } } diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/objectives/NPCsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/NPCsPrompt.java index c783a75fd..5af6a09a4 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/objectives/NPCsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/objectives/NPCsPrompt.java @@ -20,15 +20,14 @@ import java.util.UUID; import org.bukkit.ChatColor; import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.FixedSetPrompt; import org.bukkit.conversations.Prompt; -import org.bukkit.conversations.StringPrompt; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import me.blackvein.quests.Quests; import me.blackvein.quests.convo.generic.ItemStackPrompt; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; +import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt; import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.util.CK; @@ -173,21 +172,21 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { switch(input.intValue()) { case 1: if (plugin.getDependencies().getCitizens() != null) { - return new DeliveryListPrompt(); + return new DeliveryListPrompt(context); } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoCitizens")); return new StageMainPrompt(stageNum, context); } case 2: if (plugin.getDependencies().getCitizens() != null) { - return new NPCIDsToTalkToPrompt(); + return new NPCIDsToTalkToPrompt(context); } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoCitizens")); return new StageMainPrompt(stageNum, context); } case 3: if (plugin.getDependencies().getCitizens() != null) { - return new NPCKillListPrompt(); + return new NPCKillListPrompt(context); } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoCitizens")); return new StageMainPrompt(stageNum, context); @@ -204,18 +203,103 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { } } - private class DeliveryListPrompt extends FixedSetPrompt { + public class DeliveryListPrompt extends QuestsEditorNumericPrompt { - public DeliveryListPrompt() { - super("1", "2", "3", "4", "5"); + public DeliveryListPrompt(ConversationContext context) { + super(context); + } + + private final int size = 5; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("stageEditorDeliverItems"); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + case 3: + return ChatColor.BLUE; + case 4: + return ChatColor.RED; + case 5: + return ChatColor.GREEN; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch(number) { + case 1: + return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem"); + case 2: + return ChatColor.YELLOW + Lang.get("stageEditorDeliveryNPCs"); + case 3: + return ChatColor.YELLOW + Lang.get("stageEditorDeliveryMessages"); + case 4: + return ChatColor.RED + Lang.get("clear"); + case 5: + return ChatColor.GREEN + Lang.get("done"); + default: + return null; + } + } + + @SuppressWarnings("unchecked") + public String getAdditionalText(ConversationContext context, int number) { + switch(number) { + case 1: + if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (ItemStack is : (List) context.getSessionData(pref + CK.S_DELIVERY_ITEMS)) { + text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n"; + } + return text; + } + case 2: + if (context.getSessionData(pref + CK.S_DELIVERY_NPCS) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (int i : (List) context.getSessionData(pref + CK.S_DELIVERY_NPCS)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + " (" + + plugin.getDependencies().getCitizens().getNPCRegistry().getById(i).getName() + ")\n"; + } + return text; + } + case 3: + if (context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (String s : (List) context.getSessionData(pref + CK.S_DELIVERY_MESSAGES)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + "\"" + s + "\"\n"; + } + return text; + } + case 4: + case 5: + return ""; + default: + return null; + } } + @SuppressWarnings("unchecked") @Override public String getPromptText(ConversationContext context) { // Check/add newly made item if (context.getSessionData("newItem") != null) { if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) != null) { - List itemRews = getItems(context); + List itemRews = (List) context.getSessionData(pref + CK.S_DELIVERY_ITEMS); itemRews.add((ItemStack) context.getSessionData("tempStack")); context.setSessionData(pref + CK.S_DELIVERY_ITEMS, itemRews); } else { @@ -226,79 +310,35 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { context.setSessionData("newItem", null); context.setSessionData("tempStack", null); } - String text = ChatColor.GOLD + "- " + Lang.get("stageEditorDeliverItems") + " -\n"; - if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) == null) { - text += ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorDeliveryAddItem") + "\n"; - text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + " - " - + Lang.get("stageEditorDeliveryNPCs") + " (" + Lang.get("noneSet") + ")\n"; - if (context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorDeliveryMessages") + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorDeliveryMessages") + "\n"; - for (String s : getDeliveryMessages(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + "\"" + s + "\""; - } - } - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorDeliveryAddItem") + "\n"; - for (ItemStack is : getItems(context)) { - text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n"; - } - if (context.getSessionData(pref + CK.S_DELIVERY_NPCS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorDeliveryNPCs") + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorDeliveryNPCs") + "\n"; - for (int i : getDeliveryNPCs(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + " (" - + plugin.getDependencies().getCitizens().getNPCRegistry().getById(i).getName() + ")\n"; - } - } - if (context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorDeliveryMessages") + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorDeliveryMessages") + "\n"; - for (String s : getDeliveryMessages(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA + "\"" + s + "\"\n"; - } - } + + QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; } - text += ChatColor.RED + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); return text; } - + @SuppressWarnings("unchecked") @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + switch(input.intValue()) { + case 1: return new ItemStackPrompt(DeliveryListPrompt.this); - } else if (input.equalsIgnoreCase("2")) { - if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoItems")); - return new DeliveryListPrompt(); - } else { - return new DeliveryNPCsPrompt(); - } - } else if (input.equalsIgnoreCase("3")) { - return new DeliveryMessagesPrompt(); - } else if (input.equalsIgnoreCase("4")) { + case 2: + return new DeliveryNPCsPrompt(context); + case 3: + return new DeliveryMessagesPrompt(context); + case 4: context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("Cleared")); context.setSessionData(pref + CK.S_DELIVERY_ITEMS, null); context.setSessionData(pref + CK.S_DELIVERY_NPCS, null); context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, null); - return new DeliveryListPrompt(); - } else if (input.equalsIgnoreCase("5")) { + return new DeliveryListPrompt(context); + case 5: int one; int two; if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) != null) { @@ -314,42 +354,42 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { if (one == two) { if (context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) == null && one != 0) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoDeliveryMessage")); - return new DeliveryListPrompt(); + return new DeliveryListPrompt(context); } else { return new NPCsPrompt(stageNum, context); } } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); - return new DeliveryListPrompt(); + return new DeliveryListPrompt(context); } + default: + return new NPCsPrompt(stageNum, context); } - return null; - } - - @SuppressWarnings("unchecked") - private List getItems(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_DELIVERY_ITEMS); - } - - @SuppressWarnings("unchecked") - private List getDeliveryNPCs(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_DELIVERY_NPCS); - } - - @SuppressWarnings("unchecked") - private List getDeliveryMessages(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_DELIVERY_MESSAGES); } } - private class DeliveryNPCsPrompt extends StringPrompt { + public class DeliveryNPCsPrompt extends QuestsEditorStringPrompt { + + public DeliveryNPCsPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorNPCPrompt"); + } @Override public String getPromptText(ConversationContext context) { Set temp = plugin.getQuestFactory().getSelectingNpcs(); temp.add(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); - return ChatColor.YELLOW + Lang.get("stageEditorNPCPrompt") + "\n" + ChatColor.GOLD + Lang.get("npcHint"); + return ChatColor.YELLOW + getQueryText(context) + "\n" + ChatColor.GOLD + Lang.get("npcHint"); } @Override @@ -365,12 +405,12 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { } else { context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + "" + i + ChatColor.RED + " " + Lang.get("stageEditorInvalidNPC")); - return new DeliveryNPCsPrompt(); + return new DeliveryNPCsPrompt(context); } } catch (NumberFormatException e) { context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + Lang.get("stageEditorNotListofNumbers")); - return new DeliveryNPCsPrompt(); + return new DeliveryNPCsPrompt(context); } } context.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs); @@ -378,16 +418,28 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { Set temp = plugin.getQuestFactory().getSelectingNpcs(); temp.remove(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); - return new DeliveryListPrompt(); + return new DeliveryListPrompt(context); } } - private class DeliveryMessagesPrompt extends StringPrompt { + public class DeliveryMessagesPrompt extends QuestsEditorStringPrompt { + + public DeliveryMessagesPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorDeliveryMessagesPrompt"); + } @Override public String getPromptText(ConversationContext context) { - String note = ChatColor.GOLD + Lang.get("stageEditorNPCNote"); - return ChatColor.YELLOW + Lang.get("stageEditorDeliveryMessagesPrompt") + "\n" + note; + return ChatColor.YELLOW + getQueryText(context) + "\n" + ChatColor.GOLD + Lang.get("stageEditorNPCNote"); } @Override @@ -398,18 +450,32 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { messages.addAll(Arrays.asList(args)); context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, messages); } - return new DeliveryListPrompt(); + return new DeliveryListPrompt(context); } } - private class NPCIDsToTalkToPrompt extends StringPrompt { + public class NPCIDsToTalkToPrompt extends QuestsEditorStringPrompt { + + public NPCIDsToTalkToPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorNPCToTalkToPrompt"); + } @Override public String getPromptText(ConversationContext context) { Set temp = plugin.getQuestFactory().getSelectingNpcs(); temp.add(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); - return ChatColor.YELLOW + Lang.get("stageEditorNPCToTalkToPrompt") + "\n" + ChatColor.GOLD + return ChatColor.YELLOW + getQueryText(context) + "\n" + ChatColor.GOLD + Lang.get("npcHint"); } @@ -427,12 +493,12 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { } else { context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + "" + i + ChatColor.RED + " " + Lang.get("stageEditorInvalidNPC")); - return new NPCIDsToTalkToPrompt(); + return new NPCIDsToTalkToPrompt(context); } } catch (NumberFormatException e) { context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + Lang.get("stageEditorNotListofNumbers")); - return new NPCIDsToTalkToPrompt(); + return new NPCIDsToTalkToPrompt(context); } } Set temp = plugin.getQuestFactory().getSelectingNpcs(); @@ -446,68 +512,115 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { } } - private class NPCKillListPrompt extends FixedSetPrompt { + public class NPCKillListPrompt extends QuestsEditorNumericPrompt { - public NPCKillListPrompt() { - super("1", "2", "3", "4"); + public NPCKillListPrompt(ConversationContext context) { + super(context); + } + + private final int size = 4; + + public int getSize() { + return size; + } + + public String getTitle(ConversationContext context) { + return Lang.get("stageEditorNPCs"); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + case 2: + return ChatColor.BLUE; + case 3: + return ChatColor.RED; + case 4: + return ChatColor.GREEN; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch(number) { + case 1: + return ChatColor.YELLOW + Lang.get("stageEditorSetKillIds"); + case 2: + return ChatColor.YELLOW + Lang.get("stageEditorSetKillAmounts"); + case 3: + return ChatColor.RED + Lang.get("clear"); + case 4: + return ChatColor.GREEN + Lang.get("done"); + default: + return null; + } + } + + @SuppressWarnings("unchecked") + public String getAdditionalText(ConversationContext context, int number) { + switch(number) { + case 1: + if (plugin.getDependencies().getCitizens() != null) { + if (context.getSessionData(pref + CK.S_NPCS_TO_KILL) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (Integer i : (List) context.getSessionData(pref + CK.S_NPCS_TO_KILL)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + + plugin.getDependencies().getCitizens().getNPCRegistry().getById(i).getName() + + ChatColor.DARK_AQUA + " (" + i + ")\n"; + } + return text; + } + } else { + return ChatColor.GRAY + " (" + Lang.get("questCitNotInstalled") + ")"; + } + case 2: + if (context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS) == null) { + return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; + } else { + String text = "\n"; + for (Integer i : (List) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS)) { + text += ChatColor.GRAY + " - " + ChatColor.BLUE + i + "\n"; + } + return text; + } + case 3: + case 4: + return ""; + default: + return null; + } } @Override public String getPromptText(ConversationContext context) { - String text = ChatColor.GOLD + "- " + Lang.get("stageEditorKillNPCs") + " -\n"; - if (context.getSessionData(pref + CK.S_NPCS_TO_KILL) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetKillIds") + " (" + Lang.get("noneSet") + ")\n"; - text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetKillAmounts") + " (" + Lang.get("noIdsSet") + ")\n"; - text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("cancel") + "\n"; - text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetKillIds") + "\n"; - for (Integer i : getNPCIds(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA - + plugin.getDependencies().getCitizens().getNPCRegistry().getById(i).getName() - + ChatColor.DARK_AQUA + " (" + i + ")\n"; - } - if (context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.BLUE + " - " - + Lang.get("stageEditorSetKillAmounts") + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorSetKillAmounts") + "\n"; - for (Integer i : getKillAmounts(context)) { - text += ChatColor.GRAY + " - " + ChatColor.BLUE + i + "\n"; - } - } - text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); + QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); + context.getPlugin().getServer().getPluginManager().callEvent(event); + + String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; } return text; } - + @SuppressWarnings("unchecked") @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { - return new NpcIdsToKillPrompt(); - } else if (input.equalsIgnoreCase("2")) { - if (context.getSessionData(pref + CK.S_NPCS_TO_KILL) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoNPCs")); - return new NPCKillListPrompt(); - } else { - return new NpcAmountsToKillPrompt(); - } - } else if (input.equalsIgnoreCase("3")) { + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + switch(input.intValue()) { + case 1: + return new NpcIdsToKillPrompt(context); + case 2: + return new NpcAmountsToKillPrompt(context); + case 3: context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); context.setSessionData(pref + CK.S_NPCS_TO_KILL, null); context.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, null); - return new NPCKillListPrompt(); - } else if (input.equalsIgnoreCase("4")) { + return new NPCKillListPrompt(context); + case 4: int one; int two; if (context.getSessionData(pref + CK.S_NPCS_TO_KILL) != null) { @@ -524,31 +637,36 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { return new StageMainPrompt(stageNum, context); } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); - return new NPCKillListPrompt(); + return new NPCKillListPrompt(context); } + default: + return new NPCsPrompt(stageNum, context); } - return null; - } - - @SuppressWarnings("unchecked") - private List getNPCIds(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_NPCS_TO_KILL); - } - - @SuppressWarnings("unchecked") - private List getKillAmounts(ConversationContext context) { - return (List) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS); } } - private class NpcIdsToKillPrompt extends StringPrompt { + public class NpcIdsToKillPrompt extends QuestsEditorStringPrompt { + + public NpcIdsToKillPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorNPCPrompt"); + } + @Override public String getPromptText(ConversationContext context) { Set temp = plugin.getQuestFactory().getSelectingNpcs(); temp.add(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); - return ChatColor.YELLOW + Lang.get("stageEditorNPCPrompt") + "\n" + ChatColor.GOLD + Lang.get("npcHint"); + return ChatColor.YELLOW + getQueryText(context) + "\n" + ChatColor.GOLD + Lang.get("npcHint"); } @Override @@ -564,12 +682,12 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { } else { context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + "" + i + ChatColor.RED + " " + Lang.get("stageEditorInvalidNPC")); - return new NpcIdsToKillPrompt(); + return new NpcIdsToKillPrompt(context); } } catch (NumberFormatException e) { context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + Lang.get("stageEditorNotListofNumbers")); - return new NpcIdsToKillPrompt(); + return new NpcIdsToKillPrompt(context); } } context.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs); @@ -577,15 +695,29 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { Set temp = plugin.getQuestFactory().getSelectingNpcs(); temp.remove(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); - return new NPCKillListPrompt(); + return new NPCKillListPrompt(context); } } - private class NpcAmountsToKillPrompt extends StringPrompt { + public class NpcAmountsToKillPrompt extends QuestsEditorStringPrompt { + + public NpcAmountsToKillPrompt(ConversationContext context) { + super(context); + } + + @Override + public String getTitle(ConversationContext context) { + return null; + } + + @Override + public String getQueryText(ConversationContext context) { + return Lang.get("stageEditorKillNPCsPrompt"); + } @Override public String getPromptText(ConversationContext context) { - return ChatColor.YELLOW + Lang.get("stageEditorKillNPCsPrompt"); + return ChatColor.YELLOW + getQueryText(context); } @Override @@ -600,17 +732,17 @@ public class NPCsPrompt extends QuestsEditorNumericPrompt { } else { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum") .replace("", "1")); - return new NpcAmountsToKillPrompt(); + return new NpcAmountsToKillPrompt(context); } } catch (NumberFormatException e) { context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED + Lang.get("stageEditorNotListofNumbers")); - return new NpcAmountsToKillPrompt(); + return new NpcAmountsToKillPrompt(context); } } context.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, amounts); } - return new NPCKillListPrompt(); + return new NPCKillListPrompt(context); } } } diff --git a/main/src/main/resources/strings.yml b/main/src/main/resources/strings.yml index 7b63772a0..0e3fd99af 100644 --- a/main/src/main/resources/strings.yml +++ b/main/src/main/resources/strings.yml @@ -246,11 +246,8 @@ stageEditorNotListofNumbers: "is not a list of numbers!" stageEditorNoDelaySet: "You must set a delay first!" stageEditorNoItems: "You must add items first!" stageEditorNoDeliveryMessage: "You must set at least one delivery message!" -stageEditorNoNPCs: "You must set NPC IDs first!" -stageEditorNoMobTypes: "You must set mob types first!" stageEditorNoKillLocations: "You must set kill locations first!" stageEditorNoBlockSelected: "You must select a block first." -stageEditorNoColors: "You must set colors first!" stageEditorNoLocations: "You must set locations first!" stageEditorMustSetPasswordDisplays: "You must add at least one password display first!" stageEditorDelayCleared: "Delay cleared."