diff --git a/lib/Heroes.jar b/lib/Heroes.jar index 5bace9f73..6139c5e7e 100644 Binary files a/lib/Heroes.jar and b/lib/Heroes.jar differ diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java index e3013d161..19e8cae0d 100644 --- a/src/main/java/me/blackvein/quests/Quester.java +++ b/src/main/java/me/blackvein/quests/Quester.java @@ -38,6 +38,7 @@ public class Quester { Quests plugin; public LinkedList completedQuests = new LinkedList(); Map completedTimes = new HashMap(); + Map amountsCompleted = new HashMap(); Map blocksDamaged = new EnumMap(Material.class); Map blocksBroken = new EnumMap(Material.class); Map blocksPlaced = new EnumMap(Material.class); @@ -78,27 +79,34 @@ public class Quester { } - public void takeQuest(Quest q) { + public void takeQuest(Quest q, boolean override) { Player player = plugin.getServer().getPlayer(name); - if (q.testRequirements(player) == true) { + if (q.testRequirements(player) == true || override) { currentQuest = q; currentStage = q.orderedStages.getFirst(); addEmpties(); - if (q.moneyReq > 0) { - Quests.economy.withdrawPlayer(name, q.moneyReq); - } - - for (ItemStack is : q.items) { - if (q.removeItems.get(q.items.indexOf(is)) == true) { - Quests.removeItem(player.getInventory(), is); + + if(!override){ + + if (q.moneyReq > 0) { + Quests.economy.withdrawPlayer(name, q.moneyReq); } + + for (ItemStack is : q.items) { + if (q.removeItems.get(q.items.indexOf(is)) == true) { + Quests.removeItem(player.getInventory(), is); + } + } + + player.sendMessage(ChatColor.GREEN + "Quest accepted: " + q.name); + player.sendMessage(""); + } - player.sendMessage(ChatColor.GREEN + "Quest accepted: " + q.name); - player.sendMessage(""); + player.sendMessage(ChatColor.GOLD + "---(Objectives)---"); for (String s : getObjectives()) { player.sendMessage(s); @@ -124,6 +132,8 @@ public class Quester { if(currentStage.startEvent != null) currentStage.startEvent.fire(this); + saveData(); + } else { player.sendMessage(q.failRequirements); @@ -992,7 +1002,7 @@ public class Quester { } else if (objective.equalsIgnoreCase("deliverItem")) { - String message = ChatColor.GREEN + "(Completed) Deliver " + ItemUtil.getString(currentStage.itemsToDeliver.get(currentStage.itemsToDeliver.indexOf(itemstack))) + " " + ItemUtil.getName(itemstack) + " to " + plugin.getNPCName(currentStage.itemDeliveryTargets.get(currentStage.itemsToDeliver.indexOf(itemstack))); + String message = ChatColor.GREEN + "(Completed) Deliver " + ItemUtil.getString(currentStage.itemsToDeliver.get(currentStage.itemsToDeliver.indexOf(itemstack))) + " to " + plugin.getNPCName(currentStage.itemDeliveryTargets.get(currentStage.itemsToDeliver.indexOf(itemstack))); p.sendMessage(message); if (testComplete()) { currentQuest.nextStage(this); @@ -1529,23 +1539,6 @@ public class Quester { FileConfiguration data = new YamlConfiguration(); - if (completedTimes.isEmpty() == false) { - - List questTimeNames = new LinkedList(); - List questTimes = new LinkedList(); - - for (String s : completedTimes.keySet()) { - - questTimeNames.add(s); - questTimes.add(completedTimes.get(s)); - - } - - data.set("completedRedoableQuests", questTimeNames); - data.set("completedQuestTimes", questTimes); - - } - if (currentQuest != null) { data.set("currentQuest", currentQuest.name); @@ -1870,6 +1863,40 @@ public class Quester { data.set("completed-Quests", completed); } + + if (completedTimes.isEmpty() == false) { + + List questTimeNames = new LinkedList(); + List questTimes = new LinkedList(); + + for (String s : completedTimes.keySet()) { + + questTimeNames.add(s); + questTimes.add(completedTimes.get(s)); + + } + + data.set("completedRedoableQuests", questTimeNames); + data.set("completedQuestTimes", questTimes); + + } + + if (amountsCompleted.isEmpty() == false) { + + List list1 = new LinkedList(); + List list2 = new LinkedList(); + + for(Entry entry : amountsCompleted.entrySet()){ + + list1.add(entry.getKey()); + list2.add(entry.getValue()); + + } + + data.set("amountsCompletedQuests", list1); + data.set("amountsCompleted", list2); + + } return data; @@ -1906,6 +1933,21 @@ public class Quester { } } + + amountsCompleted.clear(); + + if (data.contains("amountsCompletedQuests")) { + + List list1 = data.getStringList("amountsCompletedQuests"); + List list2 = data.getIntegerList("amountsCompleted"); + + for(int i = 0; i < list1.size(); i++){ + + amountsCompleted.put(list1.get(i), list2.get(i)); + + } + + } questPoints = data.getInt("quest-points"); diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index 5c8f147d7..f0c43853c 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -335,7 +335,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, if (s.equalsIgnoreCase("Yes")) { - getQuester(player.getName()).takeQuest(getQuest(getQuester(player.getName()).questToTake)); + getQuester(player.getName()).takeQuest(getQuest(getQuester(player.getName()).questToTake), false); return Prompt.END_OF_CONVERSATION; } else if (s.equalsIgnoreCase("No")) { @@ -983,10 +983,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, completed = PURPLE + ""; for (String s : quester.completedQuests) { + completed += s; + + if (quester.amountsCompleted.containsKey(s) && quester.amountsCompleted.get(s) > 1){ + completed += PINK + " (x" + quester.amountsCompleted.get(s) + ")"; + } + if (quester.completedQuests.indexOf(s) < (quester.completedQuests.size() - 1)) { - completed = completed + s + ", "; - } else { - completed = completed + s; + completed += ", "; } } @@ -1387,16 +1391,18 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } catch (IOException e) { - if (failCount < 4) { + if (failCount < 10) { cs.sendMessage(RED + "Error reading " + DARKAQUA + f.getName() + RED + ", skipping.."); + failCount++; } else if (suppressed == false) { cs.sendMessage(RED + "Error reading " + DARKAQUA + f.getName() + RED + ", suppressing further errors."); suppressed = true; } } catch (InvalidConfigurationException e) { - if (failCount < 4) { + if (failCount < 10) { cs.sendMessage(RED + "Error reading " + DARKAQUA + f.getName() + RED + ", skipping.."); + failCount++; } else if (suppressed == false) { cs.sendMessage(RED + "Error reading " + DARKAQUA + f.getName() + RED + ", suppressing further errors."); suppressed = true; @@ -1506,20 +1512,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener, } else { Quester quester = getQuester(target.getName()); - quester.resetObjectives(); - quester.currentQuest = questToGive; - quester.currentStage = questToGive.orderedStages.getFirst(); - quester.addEmpties(); cs.sendMessage(GREEN + target.getName() + GOLD + " has forcibly started the Quest " + PURPLE + questToGive.name + GOLD + "."); - target.sendMessage(GREEN + cs.getName() + GOLD + " has forced you to take the Quest " + PURPLE + questToGive.name + GOLD + "."); - target.sendMessage(GOLD + "---(Objectives)---"); - for (String s : quester.getObjectives()) { - target.sendMessage(s); - } - - quester.saveData(); + target.sendMessage(GREEN + "You have been forced to take the Quest " + PURPLE + questToGive.name + GOLD + "."); + quester.takeQuest(questToGive, true); } diff --git a/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java b/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java index 72a6f5466..3ed8a64ff 100644 --- a/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java +++ b/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java @@ -1,893 +1,893 @@ -package me.blackvein.quests.prompts; - -import com.herocraftonline.heroes.characters.classes.HeroClass; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; - -import me.blackvein.quests.util.ColorUtil; -import me.blackvein.quests.Quest; -import me.blackvein.quests.QuestFactory; -import me.blackvein.quests.Quests; -import me.blackvein.quests.util.CK; -import me.blackvein.quests.util.ItemUtil; -import me.blackvein.quests.util.Lang; -import me.blackvein.quests.util.MiscUtil; - -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.FixedSetPrompt; -import org.bukkit.conversations.NumericPrompt; -import org.bukkit.conversations.Prompt; -import org.bukkit.conversations.StringPrompt; -import org.bukkit.inventory.ItemStack; - -public class RequirementsPrompt extends FixedSetPrompt implements ColorUtil { - - Quests quests; - final QuestFactory factory; - - public RequirementsPrompt(Quests plugin, QuestFactory qf) { - - super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); - quests = plugin; - factory = qf; - - } - - @Override - public String getPromptText(ConversationContext context) { - - String text; - - text = DARKAQUA + "- " + AQUA + context.getSessionData(CK.Q_NAME) + AQUA + " | Requirements -\n"; - - if (context.getSessionData(CK.REQ_MONEY) == null) { - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set money requirement " + GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - int moneyReq = (Integer) context.getSessionData(CK.REQ_MONEY); - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set money requirement (" + moneyReq + " " + (moneyReq > 1 ? Quests.getCurrency(true) : Quests.getCurrency(false)) + ")\n"; - } - - if (context.getSessionData(CK.REQ_QUEST_POINTS) == null) { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points requirement " + GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points requirement " + GRAY + "(" + AQUA + context.getSessionData(CK.REQ_QUEST_POINTS) + " Quest Points" + GRAY + ")\n"; - } - - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Set item requirements\n"; - - if (context.getSessionData(CK.REQ_PERMISSION) == null) { - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set permission requirements " + GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set permission requirements\n"; - List perms = (List) context.getSessionData(CK.REQ_PERMISSION); - - for (String s : perms) { - - text += GRAY + " - " + AQUA + s + "\n"; - - } - } - - if (context.getSessionData(CK.REQ_QUEST) == null) { - text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Quest requirements " + GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Quest requirements\n"; - List qs = (List) context.getSessionData(CK.REQ_QUEST); - - for (String s : qs) { - - text += GRAY + " - " + AQUA + s + "\n"; - - } - } - - if (context.getSessionData(CK.REQ_QUEST_BLOCK) == null) { - text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Quest blocks " + GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Quest blocks\n"; - List qs = (List) context.getSessionData(CK.REQ_QUEST_BLOCK); - - for (String s : qs) { - - text += GRAY + " - " + AQUA + s + "\n"; - - } - } - - if (Quests.mcmmo != null) { - - if (context.getSessionData(CK.REQ_MCMMO_SKILLS) == null) { - text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set mcMMO requirements " + GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set mcMMO requirements\n"; - List skills = (List) context.getSessionData(CK.REQ_MCMMO_SKILLS); - List amounts = (List) context.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS); - - for (String s : skills) { - text += GRAY + " - " + DARKGREEN + s + RESET + YELLOW + " level " + GREEN + amounts.get(skills.indexOf(s)) + "\n"; - } - } - - } else { - text += GRAY + "6 - Set mcMMO requirements (mcMMO not installed)\n"; - } - - if (Quests.heroes != null) { - - if (context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) == null && context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) == null) { - text += BLUE + "" + BOLD + "8" + RESET + YELLOW + " - Set Heroes requirements " + GRAY + " (" + Lang.get("noneSet") + ")\n"; - } else { - text += BLUE + "" + BOLD + "8" + RESET + YELLOW + " - Set Heroes requirements\n"; - - if (context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) != null) { - text += AQUA + " Primary Class: " + BLUE + (String) context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) + "\n"; - } - - if (context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) != null) { - text += AQUA + " Secondary Class: " + BLUE + (String) context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) + "\n"; - } - } - - } else { - text += GRAY + "8 - Set Heroes requirements (Heroes not installed)\n"; - } - - if (context.getSessionData(CK.REQ_MONEY) == null && context.getSessionData(CK.REQ_QUEST_POINTS) == null && context.getSessionData(CK.REQ_QUEST_BLOCK) == null && context.getSessionData(CK.REQ_ITEMS) == null && context.getSessionData(CK.REQ_PERMISSION) == null && context.getSessionData(CK.REQ_QUEST) == null && context.getSessionData(CK.REQ_QUEST_BLOCK) == null && context.getSessionData(CK.REQ_MCMMO_SKILLS) == null && context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) == null && context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) == null) { - text += GRAY + "" + BOLD + "9 - " + RESET + GRAY + "Set fail requirements message (No requirements set)\n"; - } else if (context.getSessionData(CK.Q_FAIL_MESSAGE) == null) { - text += RED + "" + BOLD + "9 - " + RESET + RED + "Set fail requirements message (Required)\n"; - } else { - text += BLUE + "" + BOLD + "9 - " + RESET + YELLOW + "Set fail requirements message" + GRAY + "(" + AQUA + "\"" + context.getSessionData(CK.Q_FAIL_MESSAGE) + "\"" + GRAY + ")\n"; - } - - text += GREEN + "" + BOLD + "10" + RESET + YELLOW + " - Done"; - - return text; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1")) { - return new MoneyPrompt(); - } else if (input.equalsIgnoreCase("2")) { - return new QuestPointsPrompt(); - } else if (input.equalsIgnoreCase("3")) { - return new ItemListPrompt(); - } else if (input.equalsIgnoreCase("4")) { - return new PermissionsPrompt(); - } else if (input.equalsIgnoreCase("5")) { - return new QuestListPrompt(true); - } else if (input.equalsIgnoreCase("6")) { - return new QuestListPrompt(false); - } else if (input.equalsIgnoreCase("7")) { - if (Quests.mcmmo != null) { - return new mcMMOPrompt(); - } else { - return new RequirementsPrompt(quests, factory); - } - } else if (input.equalsIgnoreCase("8")) { - if (Quests.heroes != null) { - return new HeroesPrompt(); - } else { - return new RequirementsPrompt(quests, factory); - } - } else if (input.equalsIgnoreCase("9")) { - return new FailMessagePrompt(); - } else if (input.equalsIgnoreCase("10")) { - if (context.getSessionData(CK.REQ_MONEY) != null || context.getSessionData(CK.REQ_QUEST_POINTS) != null || context.getSessionData(CK.REQ_ITEMS) != null || context.getSessionData(CK.REQ_PERMISSION) != null || context.getSessionData(CK.REQ_QUEST) != null || context.getSessionData(CK.REQ_QUEST_BLOCK) != null || context.getSessionData(CK.REQ_MCMMO_SKILLS) != null || context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) != null || context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) != null) { - - if (context.getSessionData(CK.Q_FAIL_MESSAGE) == null) { - context.getForWhom().sendRawMessage(RED + "You must set a fail requirements message!"); - return new RequirementsPrompt(quests, factory); - } - - } - - return factory.returnToMenu(); - } - return null; - - } - - private class MoneyPrompt extends NumericPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return YELLOW + "Enter amount of " + PURPLE + ((Quests.economy.currencyNamePlural().isEmpty() ? "Money" : Quests.economy.currencyNamePlural())) + YELLOW + ", or 0 to clear the money requirement, or -1 to cancel"; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - - if (input.intValue() < -1) { - context.getForWhom().sendRawMessage(RED + "Amount must be greater than 0!"); - return new MoneyPrompt(); - } else if (input.intValue() == -1) { - return new RequirementsPrompt(quests, factory); - } else if (input.intValue() == 0) { - context.setSessionData(CK.REQ_MONEY, null); - return new RequirementsPrompt(quests, factory); - } - - context.setSessionData(CK.REQ_MONEY, input.intValue()); - return new RequirementsPrompt(quests, factory); - - } - } - - private class QuestPointsPrompt extends NumericPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return YELLOW + "Enter amount of Quest Points, or 0 to clear the Quest Point requirement,\nor -1 to cancel"; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - - if (input.intValue() < -1) { - context.getForWhom().sendRawMessage(RED + "Amount must be greater than 0!"); - return new QuestPointsPrompt(); - } else if (input.intValue() == -1) { - return new RequirementsPrompt(quests, factory); - } else if (input.intValue() == 0) { - context.setSessionData(CK.REQ_QUEST_POINTS, null); - return new RequirementsPrompt(quests, factory); - } - - context.setSessionData(CK.REQ_QUEST_POINTS, input.intValue()); - return new RequirementsPrompt(quests, factory); - - } - } - - private class QuestListPrompt extends StringPrompt { - - private final boolean isRequiredQuest; - - /*public QuestListPrompt() { - this.isRequiredQuest = true; - }*/ - public QuestListPrompt(boolean isRequired) { - this.isRequiredQuest = isRequired; - } - - @Override - public String getPromptText(ConversationContext context) { - - String text = PINK + "- Quests -\n" + PURPLE; - - boolean none = true; - for (Quest q : quests.getQuests()) { - - text += q.getName() + ", "; - none = false; - - } - - if (none) { - text += "(None)\n"; - } else { - text = text.substring(0, (text.length() - 2)); - text += "\n"; - } - - text += YELLOW + "Enter a list of Quest names separating each one by a " + RED + BOLD + "comma" + RESET + YELLOW + ", or enter \'clear\' to clear the list, or \'cancel\' to return."; - - return text; - - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - String[] args = input.split(","); - LinkedList questNames = new LinkedList(); - - for (String s : args) { - - if (quests.getQuest(s) == null) { - - context.getForWhom().sendRawMessage(PINK + s + " " + RED + "is not a Quest name!"); - return new QuestListPrompt(isRequiredQuest); - - } - - if (questNames.contains(s)) { - - context.getForWhom().sendRawMessage(RED + "List contains duplicates!"); - return new QuestListPrompt(isRequiredQuest); - - } - - questNames.add(s); - - } - - Collections.sort(questNames, new Comparator() { - @Override - public int compare(String one, String two) { - - return one.compareTo(two); - - } - }); - - if (isRequiredQuest) { - context.setSessionData(CK.REQ_QUEST, questNames); - } else { - context.setSessionData(CK.REQ_QUEST_BLOCK, questNames); - } - - } else if (input.equalsIgnoreCase("clear")) { - - if (isRequiredQuest) { - context.setSessionData(CK.REQ_QUEST, null); - } else { - context.setSessionData(CK.REQ_QUEST_BLOCK, null); - } - - } - - return new RequirementsPrompt(quests, factory); - - } - } - - private class ItemListPrompt extends FixedSetPrompt { - - public ItemListPrompt() { - - super("1", "2", "3", "4"); - - } - - @Override - public String getPromptText(ConversationContext context) { - - // Check/add newly made item - if (context.getSessionData("newItem") != null) { - if (context.getSessionData(CK.REQ_ITEMS) != null) { - List itemRews = getItems(context); - itemRews.add((ItemStack) context.getSessionData("tempStack")); - context.setSessionData(CK.REQ_ITEMS, itemRews); - } else { - LinkedList itemRews = new LinkedList(); - itemRews.add((ItemStack) context.getSessionData("tempStack")); - context.setSessionData(CK.REQ_ITEMS, itemRews); - } - - context.setSessionData("newItem", null); - context.setSessionData("tempStack", null); - - } - - String text = GOLD + "- Item Requirements -\n"; - if (context.getSessionData(CK.REQ_ITEMS) == null) { - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add item\n"; - text += GRAY + "2 - Set remove items (No items set)\n"; - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; - } else { - - for (ItemStack is : getItems(context)) { - - text += GRAY + " - " + ItemUtil.getDisplayString(is) + "\n"; - - } - - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add item\n"; - - if (context.getSessionData(CK.REQ_ITEMS_REMOVE) == null) { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set remove items (No values set)\n"; - } else { - - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set remove items\n"; - for (Boolean b : getRemoveItems(context)) { - - text += GRAY + " - " + AQUA + b.toString().toLowerCase() + "\n"; - - } - - } - - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; - - } - - return text; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1")) { - return new ItemStackPrompt(ItemListPrompt.this); - } else if (input.equalsIgnoreCase("2")) { - if (context.getSessionData(CK.REQ_ITEMS) == null) { - context.getForWhom().sendRawMessage(RED + "You must add at least one item first!"); - return new ItemListPrompt(); - } else { - return new RemoveItemsPrompt(); - } - } else if (input.equalsIgnoreCase("3")) { - context.getForWhom().sendRawMessage(YELLOW + "Item requirements cleared."); - context.setSessionData(CK.REQ_ITEMS, null); - context.setSessionData(CK.REQ_ITEMS_REMOVE, null); - return new ItemListPrompt(); - } else if (input.equalsIgnoreCase("4")) { - - int one; - int two; - - if (context.getSessionData(CK.REQ_ITEMS) != null) { - one = ((List) context.getSessionData(CK.REQ_ITEMS)).size(); - } else { - one = 0; - } - - if (context.getSessionData(CK.REQ_ITEMS_REMOVE) != null) { - two = ((List) context.getSessionData(CK.REQ_ITEMS_REMOVE)).size(); - } else { - two = 0; - } - - if (one == two) { - return new RequirementsPrompt(quests, factory); - } else { - context.getForWhom().sendRawMessage(RED + "The " + GOLD + "items list " + RED + "and " + GOLD + "remove items list " + RED + "are not the same size!"); - return new ItemListPrompt(); - } - } - return null; - - } - - private List getItems(ConversationContext context) { - return (List) context.getSessionData(CK.REQ_ITEMS); - } - - private List getRemoveItems(ConversationContext context) { - return (List) context.getSessionData(CK.REQ_ITEMS_REMOVE); - } - } - - private class RemoveItemsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return YELLOW + "Enter a list of true/false values, separating each one by a space, or enter \'cancel\' to return."; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - - String[] args = input.split(" "); - LinkedList booleans = new LinkedList(); - - for (String s : args) { - - if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("yes")) { - booleans.add(true); - } else if (s.equalsIgnoreCase("false") || s.equalsIgnoreCase("no")) { - booleans.add(false); - } else { - context.getForWhom().sendRawMessage(PINK + s + RED + " is not a true or false value!\n " + GOLD + "Example: true false true true"); - return new RemoveItemsPrompt(); - } - - } - - context.setSessionData(CK.REQ_ITEMS_REMOVE, booleans); - - } - - return new ItemListPrompt(); - - } - } - - private class PermissionsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return YELLOW + "Enter permission requirements separating each one by a space, or enter \'clear\' to clear the list, or enter \'cancel\' to return."; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - String[] args = input.split(" "); - LinkedList permissions = new LinkedList(); - permissions.addAll(Arrays.asList(args)); - - context.setSessionData(CK.REQ_PERMISSION, permissions); - - } else if (input.equalsIgnoreCase("clear")) { - context.setSessionData(CK.REQ_PERMISSION, null); - } - - return new RequirementsPrompt(quests, factory); - - } - } - - private class mcMMOPrompt extends FixedSetPrompt { - - public mcMMOPrompt() { - super("1", "2", "3"); - } - - @Override - public String getPromptText(ConversationContext cc) { - - String text = DARKGREEN + "- mcMMO Requirements -\n"; - if (cc.getSessionData(CK.REQ_MCMMO_SKILLS) == null) { - text += BOLD + "" + GREEN + "1" + RESET + GREEN + " - Set skills (None set)\n"; - } else { - text += BOLD + "" + GREEN + "1" + RESET + GREEN + " - Set skills\n"; - LinkedList skills = (LinkedList) cc.getSessionData(CK.REQ_MCMMO_SKILLS); - for (String skill : skills) { - text += GRAY + " - " + AQUA + skill + "\n"; - } - } - - if (cc.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS) == null) { - text += BOLD + "" + GREEN + "2" + RESET + GREEN + " - Set skill amounts (None set)\n"; - } else { - text += BOLD + "" + GREEN + "2" + RESET + GREEN + " - Set skill amounts\n"; - LinkedList amounts = (LinkedList) cc.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS); - for (int i : amounts) { - text += GRAY + " - " + AQUA + i + "\n"; - } - } - - text += BOLD + "" + GREEN + "3" + RESET + GREEN + " - Done"; - - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext cc, String input) { - - if (input.equalsIgnoreCase("1")) { - return new mcMMOSkillsPrompt(); - } else if (input.equalsIgnoreCase("2")) { - return new mcMMOAmountsPrompt(); - } else if (input.equalsIgnoreCase("3")) { - return new RequirementsPrompt(quests, factory); - } - - return null; - - } - } - - private class mcMMOSkillsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - String skillList - = DARKGREEN + "-Skill List-\n" - + GREEN + "Acrobatics\n" - + GREEN + "All\n" - + GREEN + "Archery\n" - + GREEN + "Axes\n" - + GREEN + "Excavation\n" - + GREEN + "Fishing\n" - + GREEN + "Herbalism\n" - + GREEN + "Mining\n" - + GREEN + "Repair\n" - + GREEN + "Smelting\n" - + GREEN + "Swords\n" - + GREEN + "Taming\n" - + GREEN + "Unarmed\n" - + GREEN + "Woodcutting\n\n"; - - return skillList + YELLOW + "Enter mcMMO skills, separating each one by a space, or enter \'clear\' to clear the list, " - + "or \'cancel\' to return.\n"; - } - - @Override - public Prompt acceptInput(ConversationContext cc, String input) { - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - LinkedList skills = new LinkedList(); - - for (String s : input.split(" ")) { - - String formatted = MiscUtil.getCapitalized(s); - - if (Quests.getMcMMOSkill(formatted) != null) { - skills.add(formatted); - } else if (skills.contains(formatted)) { - cc.getForWhom().sendRawMessage(YELLOW + "Error: List contains duplicates!"); - return new mcMMOSkillsPrompt(); - } else { - cc.getForWhom().sendRawMessage(YELLOW + "Error: " + RED + s + YELLOW + " is not an mcMMO skill name!"); - return new mcMMOSkillsPrompt(); - } - - } - - cc.setSessionData(CK.REQ_MCMMO_SKILLS, skills); - return new mcMMOPrompt(); - - } else if (input.equalsIgnoreCase("clear")) { - cc.getForWhom().sendRawMessage(YELLOW + "mcMMO skill requirements cleared."); - cc.setSessionData(CK.REQ_MCMMO_SKILLS, null); - return new mcMMOPrompt(); - } else if (input.equalsIgnoreCase("cancel")) { - return new mcMMOPrompt(); - } - - return new mcMMOSkillsPrompt(); - - } - - } - - private class mcMMOAmountsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return YELLOW + "Enter mcMMO skill amounts, separating each one by a space, or enter \'clear\' to clear the list, " - + "or \'cancel\' to return.\n"; - } - - @Override - public Prompt acceptInput(ConversationContext cc, String input) { - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - LinkedList amounts = new LinkedList(); - - for (String s : input.split(" ")) { - - try { - - int i = Integer.parseInt(s); - amounts.add(i); - - } catch (NumberFormatException nfe) { - cc.getForWhom().sendRawMessage(YELLOW + "Error: " + RED + s + YELLOW + " is not a number!"); - return new mcMMOAmountsPrompt(); - } - - } - - cc.setSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS, amounts); - return new mcMMOPrompt(); - - } else if (input.equalsIgnoreCase("clear")) { - cc.getForWhom().sendRawMessage(YELLOW + "mcMMO skill amount requirements cleared."); - cc.setSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS, null); - return new mcMMOPrompt(); - } else if (input.equalsIgnoreCase("cancel")) { - return new mcMMOPrompt(); - } - - return new mcMMOAmountsPrompt(); - - } - - } - - private class HeroesPrompt extends FixedSetPrompt { - - public HeroesPrompt() { - super("1", "2", "3"); - } - - @Override - public String getPromptText(ConversationContext cc) { - - String text = DARKGREEN + "- Heroes Requirements -\n"; - if (cc.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) == null) { - text += BOLD + "" + GREEN + "1" + RESET + GREEN + " - Set Primary Class (None set)\n"; - } else { - text += BOLD + "" + GREEN + "1" + RESET + GREEN + " - Set Primary Class (" + AQUA + (String) cc.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) + GREEN + ")\n"; - } - - if (cc.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) == null) { - text += BOLD + "" + GREEN + "2" + RESET + GREEN + " - Set Secondary Class (None set)\n"; - } else { - text += BOLD + "" + GREEN + "2" + RESET + GREEN + " - Set Secondary Class (" + AQUA + (String) cc.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) + GREEN + ")\n"; - } - - text += BOLD + "" + GREEN + "3" + RESET + GREEN + " - Done"; - - return text; - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext cc, String input) { - - if (input.equalsIgnoreCase("1")) { - return new HeroesPrimaryPrompt(); - } else if (input.equalsIgnoreCase("2")) { - return new HeroesSecondaryPrompt(); - } else if (input.equalsIgnoreCase("3")) { - return new RequirementsPrompt(quests, factory); - } - - return null; - - } - } - - private class HeroesPrimaryPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext cc) { - - String text = PURPLE + "- " + PINK + "Primary Classes" + PURPLE + " -\n"; - LinkedList list = new LinkedList(); - for (HeroClass hc : Quests.heroes.getClassManager().getClasses()) { - if (hc.isPrimary()) { - list.add(hc.getName()); - } - } - - if (list.isEmpty()) { - text += GRAY + "(None)"; - } else { - - Collections.sort(list); - - for (String s : list) { - text += PURPLE + "- " + PINK + s + "\n"; - } - - } - - text += YELLOW + "Enter a Heroes Primary Class name, or enter \"clear\" to clear the requirement, or \"cancel\" to return."; - - return text; - } - - @Override - public Prompt acceptInput(ConversationContext cc, String input) { - - if (input.equalsIgnoreCase("clear") == false && input.equalsIgnoreCase("cancel") == false) { - - HeroClass hc = Quests.heroes.getClassManager().getClass(input); - if (hc != null) { - - if (hc.isPrimary()) { - - cc.setSessionData(CK.REQ_HEROES_PRIMARY_CLASS, hc.getName()); - return new HeroesPrompt(); - - } else { - cc.getForWhom().sendRawMessage(RED + "The " + PINK + hc.getName() + RED + " class is not primary!"); - return new HeroesPrimaryPrompt(); - } - - } else { - cc.getForWhom().sendRawMessage(RED + "Class not found!"); - return new HeroesPrimaryPrompt(); - } - - } else if (input.equalsIgnoreCase("clear")) { - - cc.setSessionData(CK.REQ_HEROES_PRIMARY_CLASS, null); - cc.getForWhom().sendRawMessage(YELLOW + "Heroes Primary Class requirement cleared."); - return new HeroesPrompt(); - - } else { - - return new HeroesPrompt(); - - } - - } - } - - private class HeroesSecondaryPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext cc) { - - String text = PURPLE + "- " + PINK + "Secondary Classes" + PURPLE + " -\n"; - LinkedList list = new LinkedList(); - for (HeroClass hc : Quests.heroes.getClassManager().getClasses()) { - if (hc.isSecondary()) { - list.add(hc.getName()); - } - } - - if (list.isEmpty()) { - text += GRAY + "(None)"; - } else { - - Collections.sort(list); - - for (String s : list) { - text += PURPLE + "- " + PINK + s + "\n"; - } - - } - - text += YELLOW + "Enter a Heroes Secondary Class name, or enter \"clear\" to clear the requirement, or \"cancel\" to return."; - - return text; - } - - @Override - public Prompt acceptInput(ConversationContext cc, String input) { - - if (input.equalsIgnoreCase("clear") == false && input.equalsIgnoreCase("cancel") == false) { - - HeroClass hc = Quests.heroes.getClassManager().getClass(input); - if (hc != null) { - - if (hc.isSecondary()) { - - cc.setSessionData(CK.REQ_HEROES_SECONDARY_CLASS, hc.getName()); - return new HeroesPrompt(); - - } else { - cc.getForWhom().sendRawMessage(RED + "The " + PINK + hc.getName() + RED + " class is not secondary!"); - return new HeroesSecondaryPrompt(); - } - - } else { - cc.getForWhom().sendRawMessage(RED + "Class not found!"); - return new HeroesSecondaryPrompt(); - } - - } else if (input.equalsIgnoreCase("clear")) { - - cc.setSessionData(CK.REQ_HEROES_SECONDARY_CLASS, null); - cc.getForWhom().sendRawMessage(YELLOW + "Heroes Secondary Class requirement cleared."); - return new HeroesPrompt(); - - } else { - - return new HeroesPrompt(); - - } - - } - } - - private class FailMessagePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return YELLOW + "Enter fail requirements message, or enter \'cancel\' to return."; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - context.setSessionData(CK.Q_FAIL_MESSAGE, input); - } - - return new RequirementsPrompt(quests, factory); - - } - } -} +package me.blackvein.quests.prompts; + +import com.herocraftonline.heroes.characters.classes.HeroClass; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; + +import me.blackvein.quests.util.ColorUtil; +import me.blackvein.quests.Quest; +import me.blackvein.quests.QuestFactory; +import me.blackvein.quests.Quests; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.ItemUtil; +import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.MiscUtil; + +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.FixedSetPrompt; +import org.bukkit.conversations.NumericPrompt; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.inventory.ItemStack; + +public class RequirementsPrompt extends FixedSetPrompt implements ColorUtil { + + Quests quests; + final QuestFactory factory; + + public RequirementsPrompt(Quests plugin, QuestFactory qf) { + + super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); + quests = plugin; + factory = qf; + + } + + @Override + public String getPromptText(ConversationContext context) { + + String text; + + text = DARKAQUA + "- " + AQUA + context.getSessionData(CK.Q_NAME) + AQUA + " | Requirements -\n"; + + if (context.getSessionData(CK.REQ_MONEY) == null) { + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set money requirement " + GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + int moneyReq = (Integer) context.getSessionData(CK.REQ_MONEY); + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set money requirement (" + moneyReq + " " + (moneyReq > 1 ? Quests.getCurrency(true) : Quests.getCurrency(false)) + ")\n"; + } + + if (context.getSessionData(CK.REQ_QUEST_POINTS) == null) { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points requirement " + GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points requirement " + GRAY + "(" + AQUA + context.getSessionData(CK.REQ_QUEST_POINTS) + " Quest Points" + GRAY + ")\n"; + } + + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Set item requirements\n"; + + if (context.getSessionData(CK.REQ_PERMISSION) == null) { + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set permission requirements " + GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set permission requirements\n"; + List perms = (List) context.getSessionData(CK.REQ_PERMISSION); + + for (String s : perms) { + + text += GRAY + " - " + AQUA + s + "\n"; + + } + } + + if (context.getSessionData(CK.REQ_QUEST) == null) { + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Quest requirements " + GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set Quest requirements\n"; + List qs = (List) context.getSessionData(CK.REQ_QUEST); + + for (String s : qs) { + + text += GRAY + " - " + AQUA + s + "\n"; + + } + } + + if (context.getSessionData(CK.REQ_QUEST_BLOCK) == null) { + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Quest blocks " + GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set Quest blocks\n"; + List qs = (List) context.getSessionData(CK.REQ_QUEST_BLOCK); + + for (String s : qs) { + + text += GRAY + " - " + AQUA + s + "\n"; + + } + } + + if (Quests.mcmmo != null) { + + if (context.getSessionData(CK.REQ_MCMMO_SKILLS) == null) { + text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set mcMMO requirements " + GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set mcMMO requirements\n"; + List skills = (List) context.getSessionData(CK.REQ_MCMMO_SKILLS); + List amounts = (List) context.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS); + + for (String s : skills) { + text += GRAY + " - " + DARKGREEN + s + RESET + YELLOW + " level " + GREEN + amounts.get(skills.indexOf(s)) + "\n"; + } + } + + } else { + text += GRAY + "6 - Set mcMMO requirements (mcMMO not installed)\n"; + } + + if (Quests.heroes != null) { + + if (context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) == null && context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) == null) { + text += BLUE + "" + BOLD + "8" + RESET + YELLOW + " - Set Heroes requirements " + GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += BLUE + "" + BOLD + "8" + RESET + YELLOW + " - Set Heroes requirements\n"; + + if (context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) != null) { + text += AQUA + " Primary Class: " + BLUE + (String) context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) + "\n"; + } + + if (context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) != null) { + text += AQUA + " Secondary Class: " + BLUE + (String) context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) + "\n"; + } + } + + } else { + text += GRAY + "8 - Set Heroes requirements (Heroes not installed)\n"; + } + + if (context.getSessionData(CK.REQ_MONEY) == null && context.getSessionData(CK.REQ_QUEST_POINTS) == null && context.getSessionData(CK.REQ_QUEST_BLOCK) == null && context.getSessionData(CK.REQ_ITEMS) == null && context.getSessionData(CK.REQ_PERMISSION) == null && context.getSessionData(CK.REQ_QUEST) == null && context.getSessionData(CK.REQ_QUEST_BLOCK) == null && context.getSessionData(CK.REQ_MCMMO_SKILLS) == null && context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) == null && context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) == null) { + text += GRAY + "" + BOLD + "9 - " + RESET + GRAY + "Set fail requirements message (No requirements set)\n"; + } else if (context.getSessionData(CK.Q_FAIL_MESSAGE) == null) { + text += RED + "" + BOLD + "9 - " + RESET + RED + "Set fail requirements message (Required)\n"; + } else { + text += BLUE + "" + BOLD + "9 - " + RESET + YELLOW + "Set fail requirements message" + GRAY + "(" + AQUA + "\"" + context.getSessionData(CK.Q_FAIL_MESSAGE) + "\"" + GRAY + ")\n"; + } + + text += GREEN + "" + BOLD + "10" + RESET + YELLOW + " - Done"; + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1")) { + return new MoneyPrompt(); + } else if (input.equalsIgnoreCase("2")) { + return new QuestPointsPrompt(); + } else if (input.equalsIgnoreCase("3")) { + return new ItemListPrompt(); + } else if (input.equalsIgnoreCase("4")) { + return new PermissionsPrompt(); + } else if (input.equalsIgnoreCase("5")) { + return new QuestListPrompt(true); + } else if (input.equalsIgnoreCase("6")) { + return new QuestListPrompt(false); + } else if (input.equalsIgnoreCase("7")) { + if (Quests.mcmmo != null) { + return new mcMMOPrompt(); + } else { + return new RequirementsPrompt(quests, factory); + } + } else if (input.equalsIgnoreCase("8")) { + if (Quests.heroes != null) { + return new HeroesPrompt(); + } else { + return new RequirementsPrompt(quests, factory); + } + } else if (input.equalsIgnoreCase("9")) { + return new FailMessagePrompt(); + } else if (input.equalsIgnoreCase("10")) { + if (context.getSessionData(CK.REQ_MONEY) != null || context.getSessionData(CK.REQ_QUEST_POINTS) != null || context.getSessionData(CK.REQ_ITEMS) != null || context.getSessionData(CK.REQ_PERMISSION) != null || context.getSessionData(CK.REQ_QUEST) != null || context.getSessionData(CK.REQ_QUEST_BLOCK) != null || context.getSessionData(CK.REQ_MCMMO_SKILLS) != null || context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) != null || context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) != null) { + + if (context.getSessionData(CK.Q_FAIL_MESSAGE) == null) { + context.getForWhom().sendRawMessage(RED + "You must set a fail requirements message!"); + return new RequirementsPrompt(quests, factory); + } + + } + + return factory.returnToMenu(); + } + return null; + + } + + private class MoneyPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return YELLOW + "Enter amount of " + PURPLE + ((Quests.economy.currencyNamePlural().isEmpty() ? "Money" : Quests.economy.currencyNamePlural())) + YELLOW + ", or 0 to clear the money requirement, or -1 to cancel"; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + + if (input.intValue() < -1) { + context.getForWhom().sendRawMessage(RED + "Amount must be greater than 0!"); + return new MoneyPrompt(); + } else if (input.intValue() == -1) { + return new RequirementsPrompt(quests, factory); + } else if (input.intValue() == 0) { + context.setSessionData(CK.REQ_MONEY, null); + return new RequirementsPrompt(quests, factory); + } + + context.setSessionData(CK.REQ_MONEY, input.intValue()); + return new RequirementsPrompt(quests, factory); + + } + } + + private class QuestPointsPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return YELLOW + "Enter amount of Quest Points, or 0 to clear the Quest Point requirement,\nor -1 to cancel"; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + + if (input.intValue() < -1) { + context.getForWhom().sendRawMessage(RED + "Amount must be greater than 0!"); + return new QuestPointsPrompt(); + } else if (input.intValue() == -1) { + return new RequirementsPrompt(quests, factory); + } else if (input.intValue() == 0) { + context.setSessionData(CK.REQ_QUEST_POINTS, null); + return new RequirementsPrompt(quests, factory); + } + + context.setSessionData(CK.REQ_QUEST_POINTS, input.intValue()); + return new RequirementsPrompt(quests, factory); + + } + } + + private class QuestListPrompt extends StringPrompt { + + private final boolean isRequiredQuest; + + /*public QuestListPrompt() { + this.isRequiredQuest = true; + }*/ + public QuestListPrompt(boolean isRequired) { + this.isRequiredQuest = isRequired; + } + + @Override + public String getPromptText(ConversationContext context) { + + String text = PINK + "- Quests -\n" + PURPLE; + + boolean none = true; + for (Quest q : quests.getQuests()) { + + text += q.getName() + ", "; + none = false; + + } + + if (none) { + text += "(None)\n"; + } else { + text = text.substring(0, (text.length() - 2)); + text += "\n"; + } + + text += YELLOW + "Enter a list of Quest names separating each one by a " + RED + BOLD + "comma" + RESET + YELLOW + ", or enter \'clear\' to clear the list, or \'cancel\' to return."; + + return text; + + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + String[] args = input.split(","); + LinkedList questNames = new LinkedList(); + + for (String s : args) { + + if (quests.getQuest(s) == null) { + + context.getForWhom().sendRawMessage(PINK + s + " " + RED + "is not a Quest name!"); + return new QuestListPrompt(isRequiredQuest); + + } + + if (questNames.contains(s)) { + + context.getForWhom().sendRawMessage(RED + "List contains duplicates!"); + return new QuestListPrompt(isRequiredQuest); + + } + + questNames.add(s); + + } + + Collections.sort(questNames, new Comparator() { + @Override + public int compare(String one, String two) { + + return one.compareTo(two); + + } + }); + + if (isRequiredQuest) { + context.setSessionData(CK.REQ_QUEST, questNames); + } else { + context.setSessionData(CK.REQ_QUEST_BLOCK, questNames); + } + + } else if (input.equalsIgnoreCase("clear")) { + + if (isRequiredQuest) { + context.setSessionData(CK.REQ_QUEST, null); + } else { + context.setSessionData(CK.REQ_QUEST_BLOCK, null); + } + + } + + return new RequirementsPrompt(quests, factory); + + } + } + + private class ItemListPrompt extends FixedSetPrompt { + + public ItemListPrompt() { + + super("1", "2", "3", "4"); + + } + + @Override + public String getPromptText(ConversationContext context) { + + // Check/add newly made item + if (context.getSessionData("newItem") != null) { + if (context.getSessionData(CK.REQ_ITEMS) != null) { + List itemRews = getItems(context); + itemRews.add((ItemStack) context.getSessionData("tempStack")); + context.setSessionData(CK.REQ_ITEMS, itemRews); + } else { + LinkedList itemRews = new LinkedList(); + itemRews.add((ItemStack) context.getSessionData("tempStack")); + context.setSessionData(CK.REQ_ITEMS, itemRews); + } + + context.setSessionData("newItem", null); + context.setSessionData("tempStack", null); + + } + + String text = GOLD + "- Item Requirements -\n"; + if (context.getSessionData(CK.REQ_ITEMS) == null) { + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add item\n"; + text += GRAY + "2 - Set remove items (No items set)\n"; + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; + } else { + + for (ItemStack is : getItems(context)) { + + text += GRAY + " - " + ItemUtil.getDisplayString(is) + "\n"; + + } + + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add item\n"; + + if (context.getSessionData(CK.REQ_ITEMS_REMOVE) == null) { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set remove items (No values set)\n"; + } else { + + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set remove items\n"; + for (Boolean b : getRemoveItems(context)) { + + text += GRAY + " - " + AQUA + b.toString().toLowerCase() + "\n"; + + } + + } + + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; + + } + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1")) { + return new ItemStackPrompt(ItemListPrompt.this); + } else if (input.equalsIgnoreCase("2")) { + if (context.getSessionData(CK.REQ_ITEMS) == null) { + context.getForWhom().sendRawMessage(RED + "You must add at least one item first!"); + return new ItemListPrompt(); + } else { + return new RemoveItemsPrompt(); + } + } else if (input.equalsIgnoreCase("3")) { + context.getForWhom().sendRawMessage(YELLOW + "Item requirements cleared."); + context.setSessionData(CK.REQ_ITEMS, null); + context.setSessionData(CK.REQ_ITEMS_REMOVE, null); + return new ItemListPrompt(); + } else if (input.equalsIgnoreCase("4")) { + + int one; + int two; + + if (context.getSessionData(CK.REQ_ITEMS) != null) { + one = ((List) context.getSessionData(CK.REQ_ITEMS)).size(); + } else { + one = 0; + } + + if (context.getSessionData(CK.REQ_ITEMS_REMOVE) != null) { + two = ((List) context.getSessionData(CK.REQ_ITEMS_REMOVE)).size(); + } else { + two = 0; + } + + if (one == two) { + return new RequirementsPrompt(quests, factory); + } else { + context.getForWhom().sendRawMessage(RED + "The " + GOLD + "items list " + RED + "and " + GOLD + "remove items list " + RED + "are not the same size!"); + return new ItemListPrompt(); + } + } + return null; + + } + + private List getItems(ConversationContext context) { + return (List) context.getSessionData(CK.REQ_ITEMS); + } + + private List getRemoveItems(ConversationContext context) { + return (List) context.getSessionData(CK.REQ_ITEMS_REMOVE); + } + } + + private class RemoveItemsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return YELLOW + "Enter a list of true/false values, separating each one by a space, or enter \'cancel\' to return."; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + + String[] args = input.split(" "); + LinkedList booleans = new LinkedList(); + + for (String s : args) { + + if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("yes")) { + booleans.add(true); + } else if (s.equalsIgnoreCase("false") || s.equalsIgnoreCase("no")) { + booleans.add(false); + } else { + context.getForWhom().sendRawMessage(PINK + s + RED + " is not a true or false value!\n " + GOLD + "Example: true false true true"); + return new RemoveItemsPrompt(); + } + + } + + context.setSessionData(CK.REQ_ITEMS_REMOVE, booleans); + + } + + return new ItemListPrompt(); + + } + } + + private class PermissionsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return YELLOW + "Enter permission requirements separating each one by a space, or enter \'clear\' to clear the list, or enter \'cancel\' to return."; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + String[] args = input.split(" "); + LinkedList permissions = new LinkedList(); + permissions.addAll(Arrays.asList(args)); + + context.setSessionData(CK.REQ_PERMISSION, permissions); + + } else if (input.equalsIgnoreCase("clear")) { + context.setSessionData(CK.REQ_PERMISSION, null); + } + + return new RequirementsPrompt(quests, factory); + + } + } + + private class mcMMOPrompt extends FixedSetPrompt { + + public mcMMOPrompt() { + super("1", "2", "3"); + } + + @Override + public String getPromptText(ConversationContext cc) { + + String text = DARKGREEN + "- mcMMO Requirements -\n"; + if (cc.getSessionData(CK.REQ_MCMMO_SKILLS) == null) { + text += BOLD + "" + GREEN + "1" + RESET + GREEN + " - Set skills (None set)\n"; + } else { + text += BOLD + "" + GREEN + "1" + RESET + GREEN + " - Set skills\n"; + LinkedList skills = (LinkedList) cc.getSessionData(CK.REQ_MCMMO_SKILLS); + for (String skill : skills) { + text += GRAY + " - " + AQUA + skill + "\n"; + } + } + + if (cc.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS) == null) { + text += BOLD + "" + GREEN + "2" + RESET + GREEN + " - Set skill amounts (None set)\n"; + } else { + text += BOLD + "" + GREEN + "2" + RESET + GREEN + " - Set skill amounts\n"; + LinkedList amounts = (LinkedList) cc.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS); + for (int i : amounts) { + text += GRAY + " - " + AQUA + i + "\n"; + } + } + + text += BOLD + "" + GREEN + "3" + RESET + GREEN + " - Done"; + + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext cc, String input) { + + if (input.equalsIgnoreCase("1")) { + return new mcMMOSkillsPrompt(); + } else if (input.equalsIgnoreCase("2")) { + return new mcMMOAmountsPrompt(); + } else if (input.equalsIgnoreCase("3")) { + return new RequirementsPrompt(quests, factory); + } + + return null; + + } + } + + private class mcMMOSkillsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + String skillList + = DARKGREEN + "-Skill List-\n" + + GREEN + "Acrobatics\n" + + GREEN + "All\n" + + GREEN + "Archery\n" + + GREEN + "Axes\n" + + GREEN + "Excavation\n" + + GREEN + "Fishing\n" + + GREEN + "Herbalism\n" + + GREEN + "Mining\n" + + GREEN + "Repair\n" + + GREEN + "Smelting\n" + + GREEN + "Swords\n" + + GREEN + "Taming\n" + + GREEN + "Unarmed\n" + + GREEN + "Woodcutting\n\n"; + + return skillList + YELLOW + "Enter mcMMO skills, separating each one by a space, or enter \'clear\' to clear the list, " + + "or \'cancel\' to return.\n"; + } + + @Override + public Prompt acceptInput(ConversationContext cc, String input) { + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + LinkedList skills = new LinkedList(); + + for (String s : input.split(" ")) { + + String formatted = MiscUtil.getCapitalized(s); + + if (Quests.getMcMMOSkill(formatted) != null) { + skills.add(formatted); + } else if (skills.contains(formatted)) { + cc.getForWhom().sendRawMessage(YELLOW + "Error: List contains duplicates!"); + return new mcMMOSkillsPrompt(); + } else { + cc.getForWhom().sendRawMessage(YELLOW + "Error: " + RED + s + YELLOW + " is not an mcMMO skill name!"); + return new mcMMOSkillsPrompt(); + } + + } + + cc.setSessionData(CK.REQ_MCMMO_SKILLS, skills); + return new mcMMOPrompt(); + + } else if (input.equalsIgnoreCase("clear")) { + cc.getForWhom().sendRawMessage(YELLOW + "mcMMO skill requirements cleared."); + cc.setSessionData(CK.REQ_MCMMO_SKILLS, null); + return new mcMMOPrompt(); + } else if (input.equalsIgnoreCase("cancel")) { + return new mcMMOPrompt(); + } + + return new mcMMOSkillsPrompt(); + + } + + } + + private class mcMMOAmountsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return YELLOW + "Enter mcMMO skill amounts, separating each one by a space, or enter \'clear\' to clear the list, " + + "or \'cancel\' to return.\n"; + } + + @Override + public Prompt acceptInput(ConversationContext cc, String input) { + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + LinkedList amounts = new LinkedList(); + + for (String s : input.split(" ")) { + + try { + + int i = Integer.parseInt(s); + amounts.add(i); + + } catch (NumberFormatException nfe) { + cc.getForWhom().sendRawMessage(YELLOW + "Error: " + RED + s + YELLOW + " is not a number!"); + return new mcMMOAmountsPrompt(); + } + + } + + cc.setSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS, amounts); + return new mcMMOPrompt(); + + } else if (input.equalsIgnoreCase("clear")) { + cc.getForWhom().sendRawMessage(YELLOW + "mcMMO skill amount requirements cleared."); + cc.setSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS, null); + return new mcMMOPrompt(); + } else if (input.equalsIgnoreCase("cancel")) { + return new mcMMOPrompt(); + } + + return new mcMMOAmountsPrompt(); + + } + + } + + private class HeroesPrompt extends FixedSetPrompt { + + public HeroesPrompt() { + super("1", "2", "3"); + } + + @Override + public String getPromptText(ConversationContext cc) { + + String text = DARKGREEN + "- Heroes Requirements -\n"; + if (cc.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) == null) { + text += BOLD + "" + GREEN + "1" + RESET + GREEN + " - Set Primary Class (None set)\n"; + } else { + text += BOLD + "" + GREEN + "1" + RESET + GREEN + " - Set Primary Class (" + AQUA + (String) cc.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) + GREEN + ")\n"; + } + + if (cc.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) == null) { + text += BOLD + "" + GREEN + "2" + RESET + GREEN + " - Set Secondary Class (None set)\n"; + } else { + text += BOLD + "" + GREEN + "2" + RESET + GREEN + " - Set Secondary Class (" + AQUA + (String) cc.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) + GREEN + ")\n"; + } + + text += BOLD + "" + GREEN + "3" + RESET + GREEN + " - Done"; + + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext cc, String input) { + + if (input.equalsIgnoreCase("1")) { + return new HeroesPrimaryPrompt(); + } else if (input.equalsIgnoreCase("2")) { + return new HeroesSecondaryPrompt(); + } else if (input.equalsIgnoreCase("3")) { + return new RequirementsPrompt(quests, factory); + } + + return null; + + } + } + + private class HeroesPrimaryPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext cc) { + + String text = PURPLE + "- " + PINK + "Primary Classes" + PURPLE + " -\n"; + LinkedList list = new LinkedList(); + for (HeroClass hc : Quests.heroes.getClassManager().getClasses()) { + if (hc.isPrimary()) { + list.add(hc.getName()); + } + } + + if (list.isEmpty()) { + text += GRAY + "(None)\n"; + } else { + + Collections.sort(list); + + for (String s : list) { + text += PURPLE + "- " + PINK + s + "\n"; + } + + } + + text += YELLOW + "Enter a Heroes Primary Class name, or enter \"clear\" to clear the requirement, or \"cancel\" to return."; + + return text; + } + + @Override + public Prompt acceptInput(ConversationContext cc, String input) { + + if (input.equalsIgnoreCase("clear") == false && input.equalsIgnoreCase("cancel") == false) { + + HeroClass hc = Quests.heroes.getClassManager().getClass(input); + if (hc != null) { + + if (hc.isPrimary()) { + + cc.setSessionData(CK.REQ_HEROES_PRIMARY_CLASS, hc.getName()); + return new HeroesPrompt(); + + } else { + cc.getForWhom().sendRawMessage(RED + "The " + PINK + hc.getName() + RED + " class is not primary!"); + return new HeroesPrimaryPrompt(); + } + + } else { + cc.getForWhom().sendRawMessage(RED + "Class not found!"); + return new HeroesPrimaryPrompt(); + } + + } else if (input.equalsIgnoreCase("clear")) { + + cc.setSessionData(CK.REQ_HEROES_PRIMARY_CLASS, null); + cc.getForWhom().sendRawMessage(YELLOW + "Heroes Primary Class requirement cleared."); + return new HeroesPrompt(); + + } else { + + return new HeroesPrompt(); + + } + + } + } + + private class HeroesSecondaryPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext cc) { + + String text = PURPLE + "- " + PINK + "Secondary Classes" + PURPLE + " -\n"; + LinkedList list = new LinkedList(); + for (HeroClass hc : Quests.heroes.getClassManager().getClasses()) { + if (hc.isSecondary()) { + list.add(hc.getName()); + } + } + + if (list.isEmpty()) { + text += GRAY + "(None)\n"; + } else { + + Collections.sort(list); + + for (String s : list) { + text += PURPLE + "- " + PINK + s + "\n"; + } + + } + + text += YELLOW + "Enter a Heroes Secondary Class name, or enter \"clear\" to clear the requirement, or \"cancel\" to return."; + + return text; + } + + @Override + public Prompt acceptInput(ConversationContext cc, String input) { + + if (input.equalsIgnoreCase("clear") == false && input.equalsIgnoreCase("cancel") == false) { + + HeroClass hc = Quests.heroes.getClassManager().getClass(input); + if (hc != null) { + + if (hc.isSecondary()) { + + cc.setSessionData(CK.REQ_HEROES_SECONDARY_CLASS, hc.getName()); + return new HeroesPrompt(); + + } else { + cc.getForWhom().sendRawMessage(RED + "The " + PINK + hc.getName() + RED + " class is not secondary!"); + return new HeroesSecondaryPrompt(); + } + + } else { + cc.getForWhom().sendRawMessage(RED + "Class not found!"); + return new HeroesSecondaryPrompt(); + } + + } else if (input.equalsIgnoreCase("clear")) { + + cc.setSessionData(CK.REQ_HEROES_SECONDARY_CLASS, null); + cc.getForWhom().sendRawMessage(YELLOW + "Heroes Secondary Class requirement cleared."); + return new HeroesPrompt(); + + } else { + + return new HeroesPrompt(); + + } + + } + } + + private class FailMessagePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return YELLOW + "Enter fail requirements message, or enter \'cancel\' to return."; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + context.setSessionData(CK.Q_FAIL_MESSAGE, input); + } + + return new RequirementsPrompt(quests, factory); + + } + } +} diff --git a/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java b/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java index a75dc422e..d846e89e9 100644 --- a/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java +++ b/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java @@ -1,1110 +1,1110 @@ -package me.blackvein.quests.prompts; - -import com.codisimus.plugins.phatloots.PhatLoot; -import com.codisimus.plugins.phatloots.PhatLootsAPI; -import com.herocraftonline.heroes.characters.classes.HeroClass; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import me.blackvein.quests.util.ColorUtil; -import me.blackvein.quests.QuestFactory; -import me.blackvein.quests.Quester; -import me.blackvein.quests.Quests; -import me.blackvein.quests.util.CK; -import me.blackvein.quests.util.ItemUtil; -import me.blackvein.quests.util.Lang; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.FixedSetPrompt; -import org.bukkit.conversations.NumericPrompt; -import org.bukkit.conversations.Prompt; -import org.bukkit.conversations.StringPrompt; -import org.bukkit.inventory.ItemStack; -import think.rpgitems.item.ItemManager; -import think.rpgitems.item.RPGItem; - -public class RewardsPrompt extends FixedSetPrompt implements ColorUtil { - - final Quests quests; - - final QuestFactory factory; - - public RewardsPrompt(Quests plugin, QuestFactory qf) { - - super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"); - quests = plugin; - factory = qf; - - } - - @Override - public String getPromptText(ConversationContext context) { - - String text; - - text = DARKAQUA + "- " + AQUA + context.getSessionData(CK.Q_NAME) + AQUA + " | Rewards -\n"; - - if (context.getSessionData(CK.REW_MONEY) == null) { - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set money reward (None set)\n"; - } else { - int moneyRew = (Integer) context.getSessionData(CK.REW_MONEY); - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set money reward (" + moneyRew + " " + (moneyRew > 1 ? Quests.getCurrency(true) : Quests.getCurrency(false)) + ")\n"; - } - - if (context.getSessionData(CK.REW_QUEST_POINTS) == null) { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points reward (None set)\n"; - } else { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points reward (" + context.getSessionData(CK.REW_QUEST_POINTS) + " Quest Points)\n"; - } - - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Set item rewards\n"; - - //RPGItems - if (Quests.rpgItems != null) { - - if (context.getSessionData(CK.REW_RPG_ITEM_IDS) == null) { - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set RPGItem rewards (None set)\n"; - } else { - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set RPGItem rewards\n"; - List rpgItems = (List) context.getSessionData(CK.REW_RPG_ITEM_IDS); - List rpgItemAmounts = (List) context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS); - - for (Integer i : rpgItems) { - - RPGItem item = ItemManager.getItemById(i); - text += GRAY + " - " + PINK + ITALIC + item.getName() + RESET + GRAY + " x " + PURPLE + rpgItemAmounts.get(rpgItems.indexOf(i)) + "\n"; - - } - } - - } else { - - text += GRAY + "4 - Set RPGItem rewards (RPGItems not installed)\n"; - - } - - // - if (context.getSessionData(CK.REW_EXP) == null) { - text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set experience reward (None set)\n"; - } else { - text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set experience reward (" + context.getSessionData(CK.REW_EXP) + " points)\n"; - } - - if (context.getSessionData(CK.REW_COMMAND) == null) { - text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set command rewards (None set)\n"; - } else { - text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set command rewards\n"; - List commands = (List) context.getSessionData(CK.REW_COMMAND); - - for (String cmd : commands) { - - text += GRAY + " - " + AQUA + cmd + "\n"; - - } - } - - if (context.getSessionData(CK.REW_PERMISSION) == null) { - text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set permission rewards (None set)\n"; - } else { - text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set permission rewards\n"; - List permissions = (List) context.getSessionData(CK.REW_PERMISSION); - - for (String perm : permissions) { - - text += GRAY + " - " + AQUA + perm + "\n"; - - } - } - - if (Quests.mcmmo != null) { - - if (context.getSessionData(CK.REW_MCMMO_SKILLS) == null) { - text += BLUE + "" + BOLD + "8" + RESET + YELLOW + " - Set mcMMO skill rewards (None set)\n"; - } else { - text += BLUE + "" + BOLD + "8" + RESET + YELLOW + " - Set mcMMO skill rewards\n"; - List skills = (List) context.getSessionData(CK.REW_MCMMO_SKILLS); - List amounts = (List) context.getSessionData(CK.REW_MCMMO_AMOUNTS); - - for (String skill : skills) { - - text += GRAY + " - " + AQUA + skill + GRAY + " x " + DARKAQUA + amounts.get(skills.indexOf(skill)) + "\n"; - - } - } - - } else { - - text += GRAY + "8 - Set mcMMO skill rewards (mcMMO not installed)\n"; - - } - - if (Quests.heroes != null) { - - if (context.getSessionData(CK.REW_HEROES_CLASSES) == null) { - text += BLUE + "" + BOLD + "9" + RESET + YELLOW + " - Set Heroes experience rewards (None set)\n"; - } else { - text += BLUE + "" + BOLD + "9" + RESET + YELLOW + " - Set Heroes experience rewards\n"; - List heroClasses = (List) context.getSessionData(CK.REW_HEROES_CLASSES); - List amounts = (List) context.getSessionData(CK.REW_HEROES_AMOUNTS); - - for (String heroClass : heroClasses) { - - text += GRAY + " - " + AQUA + amounts.get(heroClasses.indexOf(heroClass)) + " " + DARKAQUA + heroClass + " Experience\n"; - - } - } - - } else { - - text += GRAY + "9 - Set Heroes experience rewards (Heroes not installed)\n"; - - } - - if (Quests.phatLoots != null) { - - if (context.getSessionData(CK.REW_PHAT_LOOTS) == null) { - text += BLUE + "" + BOLD + "10" + RESET + YELLOW + " - Set PhatLoot rewards (None set)\n"; - } else { - text += BLUE + "" + BOLD + "10" + RESET + YELLOW + " - Set PhatLoot rewards\n"; - List phatLoots = (List) context.getSessionData(CK.REW_PHAT_LOOTS); - - for (String phatLoot : phatLoots) { - - text += GRAY + " - " + AQUA + phatLoot + "\n"; - - } - } - - } else { - - text += GRAY + "10 - Set PhatLoot rewards (PhatLoots not installed)\n"; - - } - - text += GREEN + "" + BOLD + "11" + RESET + YELLOW + " - Done"; - - return text; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1")) { - return new MoneyPrompt(); - } else if (input.equalsIgnoreCase("2")) { - return new QuestPointsPrompt(); - } else if (input.equalsIgnoreCase("3")) { - return new ItemListPrompt(); - } else if (input.equalsIgnoreCase("4")) { - if (Quests.rpgItems != null) { - return new RPGItemsPrompt(); - } else { - return new RewardsPrompt(quests, factory); - } - } else if (input.equalsIgnoreCase("5")) { - return new ExperiencePrompt(); - } else if (input.equalsIgnoreCase("6")) { - return new CommandsPrompt(); - } else if (input.equalsIgnoreCase("7")) { - return new PermissionsPrompt(); - } else if (input.equalsIgnoreCase("8")) { - if (Quests.mcmmo != null) { - return new mcMMOListPrompt(); - } else { - return new RewardsPrompt(quests, factory); - } - } else if (input.equalsIgnoreCase("9")) { - if (Quests.heroes != null) { - return new HeroesListPrompt(); - } else { - return new RewardsPrompt(quests, factory); - } - } else if (input.equalsIgnoreCase("10")) { - if (Quests.phatLoots != null) { - return new PhatLootsPrompt(); - } else { - return new RewardsPrompt(quests, factory); - } - } else if (input.equalsIgnoreCase("11")) { - return factory.returnToMenu(); - } - return null; - - } - - private class MoneyPrompt extends NumericPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return YELLOW + "Enter amount of " + AQUA + (Quests.economy.currencyNamePlural().isEmpty() ? "Money" : Quests.economy.currencyNamePlural()) + YELLOW + ", or 0 to clear the money reward, or -1 to cancel"; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - - if (input.intValue() < -1) { - context.getForWhom().sendRawMessage(RED + "Amount must be positive!"); - return new MoneyPrompt(); - } else if (input.intValue() == 0) { - context.setSessionData(CK.REW_MONEY, null); - } else if (input.intValue() != -1) { - context.setSessionData(CK.REW_MONEY, input.intValue()); - } - - return new RewardsPrompt(quests, factory); - - } - - } - - private class ExperiencePrompt extends NumericPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return YELLOW + "Enter amount of experience, or 0 to clear the experience reward, or -1 to cancel"; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - - if (input.intValue() < -1) { - context.getForWhom().sendRawMessage(RED + "Amount must be positive!"); - return new ExperiencePrompt(); - } else if (input.intValue() == -1) { - context.setSessionData(CK.REW_EXP, null); - } else if (input.intValue() != 0) { - context.setSessionData(CK.REW_EXP, input.intValue()); - } - - return new RewardsPrompt(quests, factory); - - } - - } - - private class QuestPointsPrompt extends NumericPrompt { - - @Override - public String getPromptText(ConversationContext context) { - - return YELLOW + "Enter amount of Quest Points, or 0 to clear the Quest Points reward, or -1 to cancel"; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, Number input) { - - if (input.intValue() < -1) { - context.getForWhom().sendRawMessage(RED + "Amount must be positive!"); - return new QuestPointsPrompt(); - } else if (input.intValue() == -1) { - context.setSessionData(CK.REW_QUEST_POINTS, null); - } else if (input.intValue() != 0) { - context.setSessionData(CK.REW_QUEST_POINTS, input.intValue()); - } - - return new RewardsPrompt(quests, factory); - - } - - } - - private class ItemListPrompt extends FixedSetPrompt { - - public ItemListPrompt() { - - super("1", "2", "3"); - - } - - @Override - public String getPromptText(ConversationContext context) { - - // Check/add newly made item - if (context.getSessionData("newItem") != null) { - if (context.getSessionData(CK.REW_ITEMS) != null) { - List itemRews = getItems(context); - itemRews.add((ItemStack) context.getSessionData("tempStack")); - context.setSessionData(CK.REW_ITEMS, itemRews); - } else { - LinkedList itemRews = new LinkedList(); - itemRews.add((ItemStack) context.getSessionData("tempStack")); - context.setSessionData(CK.REW_ITEMS, itemRews); - } - - context.setSessionData("newItem", null); - context.setSessionData("tempStack", null); - - } - - String text = GOLD + "- Item Rewards -\n"; - if (context.getSessionData(CK.REW_ITEMS) == null) { - text += GRAY + " (" + Lang.get("noneSet") + ")\n"; - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add item\n"; - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Clear\n"; - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Done"; - } else { - - for (ItemStack is : getItems(context)) { - - text += GRAY + "- " + ItemUtil.getDisplayString(is) + "\n"; - - } - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add item\n"; - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Clear\n"; - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Done"; - - } - - return text; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1")) { - return new ItemStackPrompt(ItemListPrompt.this); - } else if (input.equalsIgnoreCase("2")) { - context.getForWhom().sendRawMessage(YELLOW + "Item rewards cleared."); - context.setSessionData(CK.REW_ITEMS, null); - return new ItemListPrompt(); - } else if (input.equalsIgnoreCase("3")) { - return new RewardsPrompt(quests, factory); - } - return null; - - } - - private List getItems(ConversationContext context) { - return (List) context.getSessionData(CK.REW_ITEMS); - } - - } - - private class RPGItemsPrompt extends FixedSetPrompt { - - public RPGItemsPrompt() { - - super("1", "2", "3"); - - } - - @Override - public String getPromptText(ConversationContext context) { - - String text = GOLD + "- RPGItem Rewards -\n"; - if (context.getSessionData(CK.REW_RPG_ITEM_IDS) == null) { - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set IDs\n"; - } else { - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set IDs\n"; - for (Integer i : (List) context.getSessionData(CK.REW_RPG_ITEM_IDS)) { - text += AQUA + " - " + i + "\n"; - } - } - - if (context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS) == null) { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set amounts\n"; - } else { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set amounts\n"; - for (Integer i : (List) context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS)) { - text += AQUA + " - " + i + "\n"; - } - } - - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Done"; - - return text; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1")) { - return new RPGItemIdsPrompt(); - } else if (input.equalsIgnoreCase("2")) { - return new RPGItemAmountsPrompt(); - } else if (input.equalsIgnoreCase("3")) { - - int one; - int two; - - if (context.getSessionData(CK.REW_RPG_ITEM_IDS) != null) { - one = ((List) context.getSessionData(CK.REW_RPG_ITEM_IDS)).size(); - } else { - one = 0; - } - - if (context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS) != null) { - two = ((List) context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS)).size(); - } else { - two = 0; - } - - if (one == two) { - return new RewardsPrompt(quests, factory); - } else { - context.getForWhom().sendRawMessage(RED + "The " + GOLD + "IDs list " + RED + "and " + GOLD + "amounts list " + RED + "are not the same size!"); - return new RPGItemsPrompt(); - } - - } - return null; - - } - - } - - private class RPGItemIdsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return YELLOW + "Enter RPGItem IDs (or names) separating each one by a space, or enter \'clear\' to clear the list, or \'cancel\' to return."; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - String[] args = input.split(" "); - LinkedList ids = new LinkedList(); - for (String s : args) { - - try { - - int id = Integer.parseInt(s); - - if (ids.contains(id)) { - context.getForWhom().sendRawMessage(RED + "Error: List contains duplicates!"); - return new RPGItemIdsPrompt(); - } - - RPGItem item = ItemManager.getItemById(id); - - if (item != null) { - ids.add(id); - } else { - context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ", not an RPGItem ID or name!"); - return new RPGItemIdsPrompt(); - } - - } catch (NumberFormatException e) { - - RPGItem item = ItemManager.getItemByName(s); - - if (item == null) { - context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ", not an RPGItem ID or name!"); - return new RPGItemIdsPrompt(); - } else { - ids.add(item.getID()); - } - } - - } - - context.setSessionData(CK.REW_RPG_ITEM_IDS, ids); - - } else if (input.equalsIgnoreCase("clear")) { - - context.setSessionData(CK.REW_RPG_ITEM_IDS, null); - context.getForWhom().sendRawMessage(YELLOW + "RPGItem IDs cleared."); - - } - - return new RPGItemsPrompt(); - - } - - } - - private class RPGItemAmountsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return YELLOW + "Enter RPGItem amounts (numbers) separating each one by a space, or enter \'clear\' to clear the list, or \'cancel\' to return."; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - String[] args = input.split(" "); - LinkedList amounts = new LinkedList(); - for (String s : args) { - - try { - - if (Integer.parseInt(s) > 0) { - amounts.add(Integer.parseInt(s)); - } else { - context.getForWhom().sendRawMessage(PINK + s + RED + " is not greater than 0!"); - return new RPGItemAmountsPrompt(); - } - - } catch (NumberFormatException e) { - context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ". Input was not a list of numbers!"); - return new RPGItemAmountsPrompt(); - } - - } - - context.setSessionData(CK.REW_RPG_ITEM_AMOUNTS, amounts); - - } else if (input.equalsIgnoreCase("clear")) { - - context.setSessionData(CK.REW_RPG_ITEM_AMOUNTS, null); - context.getForWhom().sendRawMessage(YELLOW + "RPGItem amounts cleared."); - - } - - return new RPGItemsPrompt(); - - } - - } - - private class CommandsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String note = GOLD + "\nNote: You may put to specify the player who completed the Quest. e.g. " + AQUA + BOLD + ITALIC + "smite " + RESET; - return YELLOW + "Enter command rewards separating each one by a " + BOLD + "comma" + RESET + YELLOW + ", or enter \'clear\' to clear the list, or enter \'cancel\' to return." + note; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - String[] args = input.split(","); - LinkedList commands = new LinkedList(); - for (String s : args) { - - if (s.startsWith("/")) { - s = s.substring(1); - } - - commands.add(s); - - } - - context.setSessionData(CK.REW_COMMAND, commands); - - } else if (input.equalsIgnoreCase("clear")) { - context.setSessionData(CK.REW_COMMAND, null); - } - - return new RewardsPrompt(quests, factory); - - } - - } - - private class PermissionsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return YELLOW + "Enter permission rewards separating each one by a space, or enter \'clear\' to clear the list, or enter \'cancel\' to return."; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - String[] args = input.split(" "); - LinkedList permissions = new LinkedList(); - permissions.addAll(Arrays.asList(args)); - - context.setSessionData(CK.REW_PERMISSION, permissions); - - } else if (input.equalsIgnoreCase("clear")) { - context.setSessionData(CK.REW_PERMISSION, null); - } - - return new RewardsPrompt(quests, factory); - - } - - } - - //mcMMO - private class mcMMOListPrompt extends FixedSetPrompt { - - public mcMMOListPrompt() { - - super("1", "2", "3", "4"); - - } - - @Override - public String getPromptText(ConversationContext context) { - - String text = GOLD + "- mcMMO Rewards -\n"; - if (context.getSessionData(CK.REW_MCMMO_SKILLS) == null) { - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set skills (None set)\n"; - text += GRAY + "2 - Set skill amounts (No skills set)\n"; - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; - } else { - - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set skills\n"; - for (String s : getSkills(context)) { - - text += GRAY + " - " + AQUA + s + "\n"; - - } - - if (context.getSessionData(CK.REW_MCMMO_AMOUNTS) == null) { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set skill amounts (None set)\n"; - } else { - - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set skill amounts\n"; - for (Integer i : getSkillAmounts(context)) { - - text += GRAY + " - " + AQUA + i + "\n"; - - } - - } - - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; - - } - - return text; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1")) { - return new mcMMOSkillsPrompt(); - } else if (input.equalsIgnoreCase("2")) { - if (context.getSessionData(CK.REW_MCMMO_SKILLS) == null) { - context.getForWhom().sendRawMessage(RED + "You must set skills first!"); - return new mcMMOListPrompt(); - } else { - return new mcMMOAmountsPrompt(); - } - } else if (input.equalsIgnoreCase("3")) { - context.getForWhom().sendRawMessage(YELLOW + "mcMMO rewards cleared."); - context.setSessionData(CK.REW_MCMMO_SKILLS, null); - context.setSessionData(CK.REW_MCMMO_AMOUNTS, null); - return new mcMMOListPrompt(); - } else if (input.equalsIgnoreCase("4")) { - - int one; - int two; - - if (context.getSessionData(CK.REW_MCMMO_SKILLS) != null) { - one = ((List) context.getSessionData(CK.REW_MCMMO_SKILLS)).size(); - } else { - one = 0; - } - - if (context.getSessionData(CK.REW_MCMMO_AMOUNTS) != null) { - two = ((List) context.getSessionData(CK.REW_MCMMO_AMOUNTS)).size(); - } else { - two = 0; - } - - if (one == two) { - return new RewardsPrompt(quests, factory); - } else { - context.getForWhom().sendRawMessage(RED + "The " + GOLD + "skills list " + RED + "and " + GOLD + "skill amounts list " + RED + "are not the same size!"); - return new mcMMOListPrompt(); - } - } - return null; - - } - - private List getSkills(ConversationContext context) { - return (List) context.getSessionData(CK.REW_MCMMO_SKILLS); - } - - private List getSkillAmounts(ConversationContext context) { - return (List) context.getSessionData(CK.REW_MCMMO_AMOUNTS); - } - - } - - private class mcMMOSkillsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - String skillList - = GOLD + "-Skill List-\n" - + AQUA + "Acrobatics\n" - + GRAY + "All\n" - + AQUA + "Archery\n" - + AQUA + "Axes\n" - + AQUA + "Excavation\n" - + AQUA + "Fishing\n" - + AQUA + "Herbalism\n" - + AQUA + "Mining\n" - + AQUA + "Repair\n" - + AQUA + "Smelting\n" - + AQUA + "Swords\n" - + AQUA + "Taming\n" - + AQUA + "Unarmed\n" - + AQUA + "Woodcutting\n\n"; - - return skillList + YELLOW + "Enter mcMMO skills, separating each one by a space, or enter \'cancel\' to return." - + "\n" + GOLD + "Note: The \'All\' option will give levels to all skills."; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - - String[] args = input.split(" "); - LinkedList skills = new LinkedList(); - for (String s : args) { - - if (Quests.getMcMMOSkill(s) != null) { - - if (skills.contains(s) == false) { - skills.add(Quester.getCapitalized(s)); - } else { - context.getForWhom().sendRawMessage(RED + "List contains duplicates!"); - return new mcMMOSkillsPrompt(); - } - - } else { - context.getForWhom().sendRawMessage(PINK + s + RED + " is not a valid mcMMO skill!"); - return new mcMMOSkillsPrompt(); - } - - } - - context.setSessionData(CK.REW_MCMMO_SKILLS, skills); - - } - - return new mcMMOListPrompt(); - - } - - } - - private class mcMMOAmountsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext context) { - return YELLOW + "Enter skill amounts (numbers), separating each one by a space, or enter \'cancel\' to return."; - } - - @Override - public Prompt acceptInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - - String[] args = input.split(" "); - LinkedList amounts = new LinkedList(); - for (String s : args) { - - try { - - if (Integer.parseInt(s) > 0) { - amounts.add(Integer.parseInt(s)); - } else { - context.getForWhom().sendRawMessage(PINK + s + RED + " is not greater than 0!"); - return new mcMMOAmountsPrompt(); - } - - } catch (NumberFormatException e) { - context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ". Input was not a list of numbers!"); - return new mcMMOAmountsPrompt(); - } - - } - - context.setSessionData(CK.REW_MCMMO_AMOUNTS, amounts); - - } - - return new mcMMOListPrompt(); - - } - - } - - private class HeroesListPrompt extends FixedSetPrompt { - - public HeroesListPrompt() { - - super("1", "2", "3", "4"); - - } - - @Override - public String getPromptText(ConversationContext context) { - - String text = GOLD + "- Heroes Rewards -\n"; - if (context.getSessionData(CK.REW_HEROES_CLASSES) == null) { - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set classes (None set)\n"; - text += GRAY + "2 - Set experience amounts (No classes set)\n"; - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; - } else { - - text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set classes\n"; - for (String s : getClasses(context)) { - - text += GRAY + " - " + AQUA + s + "\n"; - - } - - if (context.getSessionData(CK.REW_HEROES_AMOUNTS) == null) { - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set experience amounts (None set)\n"; - } else { - - text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set experience amounts\n"; - for (Double d : getClassAmounts(context)) { - - text += GRAY + " - " + AQUA + d + "\n"; - - } - - } - - text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; - text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; - - } - - return text; - - } - - @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - - if (input.equalsIgnoreCase("1")) { - return new HeroesClassesPrompt(); - } else if (input.equalsIgnoreCase("2")) { - if (context.getSessionData(CK.REW_HEROES_CLASSES) == null) { - context.getForWhom().sendRawMessage(RED + "You must set classes first!"); - return new HeroesListPrompt(); - } else { - return new HeroesExperiencePrompt(); - } - } else if (input.equalsIgnoreCase("3")) { - context.getForWhom().sendRawMessage(YELLOW + "Heroes rewards cleared."); - context.setSessionData(CK.REW_HEROES_CLASSES, null); - context.setSessionData(CK.REW_HEROES_AMOUNTS, null); - return new HeroesListPrompt(); - } else if (input.equalsIgnoreCase("4")) { - - int one; - int two; - - if (context.getSessionData(CK.REW_HEROES_CLASSES) != null) { - one = ((List) context.getSessionData(CK.REW_HEROES_CLASSES)).size(); - } else { - one = 0; - } - - if (context.getSessionData(CK.REW_HEROES_AMOUNTS) != null) { - two = ((List) context.getSessionData(CK.REW_HEROES_AMOUNTS)).size(); - } else { - two = 0; - } - - if (one == two) { - return new RewardsPrompt(quests, factory); - } else { - context.getForWhom().sendRawMessage(RED + "The " + GOLD + "classes list " + RED + "and " + GOLD + "experience amounts list " + RED + "are not the same size!"); - return new HeroesListPrompt(); - } - } - return null; - - } - - private List getClasses(ConversationContext context) { - return (List) context.getSessionData(CK.REW_HEROES_CLASSES); - } - - private List getClassAmounts(ConversationContext context) { - return (List) context.getSessionData(CK.REW_HEROES_AMOUNTS); - } - - } - - private class HeroesClassesPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext cc) { - - String text = PURPLE + "- " + PINK + "Heroes Classes" + PURPLE + " -\n"; - LinkedList list = new LinkedList(); - for (HeroClass hc : Quests.heroes.getClassManager().getClasses()) { - list.add(hc.getName()); - } - - if (list.isEmpty()) { - text += GRAY + "(None)"; - } else { - - Collections.sort(list); - - for (String s : list) { - text += PINK + s + ", "; - } - - text = text.substring(0, text.length() - 2) + "\n"; - - } - - text += YELLOW + "Enter Heroes classes separating each one by a space, or enter \"cancel\" to return."; - - return text; - } - - @Override - public Prompt acceptInput(ConversationContext cc, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - - String[] arr = input.split(" "); - LinkedList classes = new LinkedList(); - - for (String s : arr) { - - HeroClass hc = Quests.heroes.getClassManager().getClass(s); - if (hc == null) { - cc.getForWhom().sendRawMessage(RED + "Error: " + PINK + s + RED + " is not a valid Heroes class name!"); - return new HeroesClassesPrompt(); - } else { - classes.add(hc.getName()); - } - - } - - cc.setSessionData(CK.REW_HEROES_CLASSES, classes); - - return new HeroesListPrompt(); - - } else { - return new HeroesListPrompt(); - } - - } - } - - private class HeroesExperiencePrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext cc) { - - String text = PURPLE + "- " + PINK + "Heroes Experience" + PURPLE + " -\n"; - - text += YELLOW + "Enter experience amounts (numbers, decimals are allowed) separating each one by a space, or enter \"cancel\" to return."; - - return text; - } - - @Override - public Prompt acceptInput(ConversationContext cc, String input) { - - if (input.equalsIgnoreCase("cancel") == false) { - - String[] arr = input.split(" "); - LinkedList amounts = new LinkedList(); - - for (String s : arr) { - - try { - - double d = Double.parseDouble(s); - if (d > 0) { - amounts.add(d); - } else { - cc.getForWhom().sendRawMessage(RED + "Error: " + PINK + s + RED + " is not greater than zero!"); - return new HeroesExperiencePrompt(); - } - - } catch (NumberFormatException nfe) { - cc.getForWhom().sendRawMessage(RED + "Error: " + PINK + s + RED + " is not a number!"); - return new HeroesExperiencePrompt(); - } - - } - - cc.setSessionData(CK.REW_HEROES_AMOUNTS, amounts); - return new HeroesListPrompt(); - - } else { - return new HeroesListPrompt(); - } - - } - } - - private class PhatLootsPrompt extends StringPrompt { - - @Override - public String getPromptText(ConversationContext cc) { - - String text = DARKAQUA + "- " + AQUA + "PhatLoots" + DARKAQUA + " -\n"; - - for (PhatLoot pl : PhatLootsAPI.getAllPhatLoots()) { - - text += GRAY + "- " + BLUE + pl.name + "\n"; - - } - - text += YELLOW + "Enter PhatLoots separating each one by a space, or enter \"clear\" to clear the list, or \"cancel\" to return."; - - return text; - } - - @Override - public Prompt acceptInput(ConversationContext cc, String input) { - - if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { - - String[] arr = input.split(" "); - LinkedList loots = new LinkedList(); - - for (String s : arr) { - - if (PhatLootsAPI.getPhatLoot(s) == null) { - cc.getForWhom().sendRawMessage(DARKRED + s + RED + " is not a valid PhatLoot name!"); - return new PhatLootsPrompt(); - } - - } - - loots.addAll(Arrays.asList(arr)); - cc.setSessionData(CK.REW_PHAT_LOOTS, loots); - return new RewardsPrompt(quests, factory); - - } else if (input.equalsIgnoreCase("clear")) { - - cc.setSessionData(CK.REW_PHAT_LOOTS, null); - cc.getForWhom().sendRawMessage(YELLOW + "PhatLoots reward cleared."); - return new RewardsPrompt(quests, factory); - - } else { - return new RewardsPrompt(quests, factory); - } - - } - } - -} +package me.blackvein.quests.prompts; + +import com.codisimus.plugins.phatloots.PhatLoot; +import com.codisimus.plugins.phatloots.PhatLootsAPI; +import com.herocraftonline.heroes.characters.classes.HeroClass; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import me.blackvein.quests.util.ColorUtil; +import me.blackvein.quests.QuestFactory; +import me.blackvein.quests.Quester; +import me.blackvein.quests.Quests; +import me.blackvein.quests.util.CK; +import me.blackvein.quests.util.ItemUtil; +import me.blackvein.quests.util.Lang; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.FixedSetPrompt; +import org.bukkit.conversations.NumericPrompt; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.bukkit.inventory.ItemStack; +import think.rpgitems.item.ItemManager; +import think.rpgitems.item.RPGItem; + +public class RewardsPrompt extends FixedSetPrompt implements ColorUtil { + + final Quests quests; + + final QuestFactory factory; + + public RewardsPrompt(Quests plugin, QuestFactory qf) { + + super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"); + quests = plugin; + factory = qf; + + } + + @Override + public String getPromptText(ConversationContext context) { + + String text; + + text = DARKAQUA + "- " + AQUA + context.getSessionData(CK.Q_NAME) + AQUA + " | Rewards -\n"; + + if (context.getSessionData(CK.REW_MONEY) == null) { + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set money reward (None set)\n"; + } else { + int moneyRew = (Integer) context.getSessionData(CK.REW_MONEY); + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set money reward (" + moneyRew + " " + (moneyRew > 1 ? Quests.getCurrency(true) : Quests.getCurrency(false)) + ")\n"; + } + + if (context.getSessionData(CK.REW_QUEST_POINTS) == null) { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points reward (None set)\n"; + } else { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points reward (" + context.getSessionData(CK.REW_QUEST_POINTS) + " Quest Points)\n"; + } + + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Set item rewards\n"; + + //RPGItems + if (Quests.rpgItems != null) { + + if (context.getSessionData(CK.REW_RPG_ITEM_IDS) == null) { + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set RPGItem rewards (None set)\n"; + } else { + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Set RPGItem rewards\n"; + List rpgItems = (List) context.getSessionData(CK.REW_RPG_ITEM_IDS); + List rpgItemAmounts = (List) context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS); + + for (Integer i : rpgItems) { + + RPGItem item = ItemManager.getItemById(i); + text += GRAY + " - " + PINK + ITALIC + item.getName() + RESET + GRAY + " x " + PURPLE + rpgItemAmounts.get(rpgItems.indexOf(i)) + "\n"; + + } + } + + } else { + + text += GRAY + "4 - Set RPGItem rewards (RPGItems not installed)\n"; + + } + + // + if (context.getSessionData(CK.REW_EXP) == null) { + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set experience reward (None set)\n"; + } else { + text += BLUE + "" + BOLD + "5" + RESET + YELLOW + " - Set experience reward (" + context.getSessionData(CK.REW_EXP) + " points)\n"; + } + + if (context.getSessionData(CK.REW_COMMAND) == null) { + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set command rewards (None set)\n"; + } else { + text += BLUE + "" + BOLD + "6" + RESET + YELLOW + " - Set command rewards\n"; + List commands = (List) context.getSessionData(CK.REW_COMMAND); + + for (String cmd : commands) { + + text += GRAY + " - " + AQUA + cmd + "\n"; + + } + } + + if (context.getSessionData(CK.REW_PERMISSION) == null) { + text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set permission rewards (None set)\n"; + } else { + text += BLUE + "" + BOLD + "7" + RESET + YELLOW + " - Set permission rewards\n"; + List permissions = (List) context.getSessionData(CK.REW_PERMISSION); + + for (String perm : permissions) { + + text += GRAY + " - " + AQUA + perm + "\n"; + + } + } + + if (Quests.mcmmo != null) { + + if (context.getSessionData(CK.REW_MCMMO_SKILLS) == null) { + text += BLUE + "" + BOLD + "8" + RESET + YELLOW + " - Set mcMMO skill rewards (None set)\n"; + } else { + text += BLUE + "" + BOLD + "8" + RESET + YELLOW + " - Set mcMMO skill rewards\n"; + List skills = (List) context.getSessionData(CK.REW_MCMMO_SKILLS); + List amounts = (List) context.getSessionData(CK.REW_MCMMO_AMOUNTS); + + for (String skill : skills) { + + text += GRAY + " - " + AQUA + skill + GRAY + " x " + DARKAQUA + amounts.get(skills.indexOf(skill)) + "\n"; + + } + } + + } else { + + text += GRAY + "8 - Set mcMMO skill rewards (mcMMO not installed)\n"; + + } + + if (Quests.heroes != null) { + + if (context.getSessionData(CK.REW_HEROES_CLASSES) == null) { + text += BLUE + "" + BOLD + "9" + RESET + YELLOW + " - Set Heroes experience rewards (None set)\n"; + } else { + text += BLUE + "" + BOLD + "9" + RESET + YELLOW + " - Set Heroes experience rewards\n"; + List heroClasses = (List) context.getSessionData(CK.REW_HEROES_CLASSES); + List amounts = (List) context.getSessionData(CK.REW_HEROES_AMOUNTS); + + for (String heroClass : heroClasses) { + + text += GRAY + " - " + AQUA + amounts.get(heroClasses.indexOf(heroClass)) + " " + DARKAQUA + heroClass + " Experience\n"; + + } + } + + } else { + + text += GRAY + "9 - Set Heroes experience rewards (Heroes not installed)\n"; + + } + + if (Quests.phatLoots != null) { + + if (context.getSessionData(CK.REW_PHAT_LOOTS) == null) { + text += BLUE + "" + BOLD + "10" + RESET + YELLOW + " - Set PhatLoot rewards (None set)\n"; + } else { + text += BLUE + "" + BOLD + "10" + RESET + YELLOW + " - Set PhatLoot rewards\n"; + List phatLoots = (List) context.getSessionData(CK.REW_PHAT_LOOTS); + + for (String phatLoot : phatLoots) { + + text += GRAY + " - " + AQUA + phatLoot + "\n"; + + } + } + + } else { + + text += GRAY + "10 - Set PhatLoot rewards (PhatLoots not installed)\n"; + + } + + text += GREEN + "" + BOLD + "11" + RESET + YELLOW + " - Done"; + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1")) { + return new MoneyPrompt(); + } else if (input.equalsIgnoreCase("2")) { + return new QuestPointsPrompt(); + } else if (input.equalsIgnoreCase("3")) { + return new ItemListPrompt(); + } else if (input.equalsIgnoreCase("4")) { + if (Quests.rpgItems != null) { + return new RPGItemsPrompt(); + } else { + return new RewardsPrompt(quests, factory); + } + } else if (input.equalsIgnoreCase("5")) { + return new ExperiencePrompt(); + } else if (input.equalsIgnoreCase("6")) { + return new CommandsPrompt(); + } else if (input.equalsIgnoreCase("7")) { + return new PermissionsPrompt(); + } else if (input.equalsIgnoreCase("8")) { + if (Quests.mcmmo != null) { + return new mcMMOListPrompt(); + } else { + return new RewardsPrompt(quests, factory); + } + } else if (input.equalsIgnoreCase("9")) { + if (Quests.heroes != null) { + return new HeroesListPrompt(); + } else { + return new RewardsPrompt(quests, factory); + } + } else if (input.equalsIgnoreCase("10")) { + if (Quests.phatLoots != null) { + return new PhatLootsPrompt(); + } else { + return new RewardsPrompt(quests, factory); + } + } else if (input.equalsIgnoreCase("11")) { + return factory.returnToMenu(); + } + return null; + + } + + private class MoneyPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return YELLOW + "Enter amount of " + AQUA + (Quests.economy.currencyNamePlural().isEmpty() ? "Money" : Quests.economy.currencyNamePlural()) + YELLOW + ", or 0 to clear the money reward, or -1 to cancel"; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + + if (input.intValue() < -1) { + context.getForWhom().sendRawMessage(RED + "Amount must be positive!"); + return new MoneyPrompt(); + } else if (input.intValue() == 0) { + context.setSessionData(CK.REW_MONEY, null); + } else if (input.intValue() != -1) { + context.setSessionData(CK.REW_MONEY, input.intValue()); + } + + return new RewardsPrompt(quests, factory); + + } + + } + + private class ExperiencePrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return YELLOW + "Enter amount of experience, or 0 to clear the experience reward, or -1 to cancel"; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + + if (input.intValue() < -1) { + context.getForWhom().sendRawMessage(RED + "Amount must be positive!"); + return new ExperiencePrompt(); + } else if (input.intValue() == -1) { + context.setSessionData(CK.REW_EXP, null); + } else if (input.intValue() != 0) { + context.setSessionData(CK.REW_EXP, input.intValue()); + } + + return new RewardsPrompt(quests, factory); + + } + + } + + private class QuestPointsPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context) { + + return YELLOW + "Enter amount of Quest Points, or 0 to clear the Quest Points reward, or -1 to cancel"; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + + if (input.intValue() < -1) { + context.getForWhom().sendRawMessage(RED + "Amount must be positive!"); + return new QuestPointsPrompt(); + } else if (input.intValue() == -1) { + context.setSessionData(CK.REW_QUEST_POINTS, null); + } else if (input.intValue() != 0) { + context.setSessionData(CK.REW_QUEST_POINTS, input.intValue()); + } + + return new RewardsPrompt(quests, factory); + + } + + } + + private class ItemListPrompt extends FixedSetPrompt { + + public ItemListPrompt() { + + super("1", "2", "3"); + + } + + @Override + public String getPromptText(ConversationContext context) { + + // Check/add newly made item + if (context.getSessionData("newItem") != null) { + if (context.getSessionData(CK.REW_ITEMS) != null) { + List itemRews = getItems(context); + itemRews.add((ItemStack) context.getSessionData("tempStack")); + context.setSessionData(CK.REW_ITEMS, itemRews); + } else { + LinkedList itemRews = new LinkedList(); + itemRews.add((ItemStack) context.getSessionData("tempStack")); + context.setSessionData(CK.REW_ITEMS, itemRews); + } + + context.setSessionData("newItem", null); + context.setSessionData("tempStack", null); + + } + + String text = GOLD + "- Item Rewards -\n"; + if (context.getSessionData(CK.REW_ITEMS) == null) { + text += GRAY + " (" + Lang.get("noneSet") + ")\n"; + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add item\n"; + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Clear\n"; + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Done"; + } else { + + for (ItemStack is : getItems(context)) { + + text += GRAY + "- " + ItemUtil.getDisplayString(is) + "\n"; + + } + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add item\n"; + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Clear\n"; + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Done"; + + } + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1")) { + return new ItemStackPrompt(ItemListPrompt.this); + } else if (input.equalsIgnoreCase("2")) { + context.getForWhom().sendRawMessage(YELLOW + "Item rewards cleared."); + context.setSessionData(CK.REW_ITEMS, null); + return new ItemListPrompt(); + } else if (input.equalsIgnoreCase("3")) { + return new RewardsPrompt(quests, factory); + } + return null; + + } + + private List getItems(ConversationContext context) { + return (List) context.getSessionData(CK.REW_ITEMS); + } + + } + + private class RPGItemsPrompt extends FixedSetPrompt { + + public RPGItemsPrompt() { + + super("1", "2", "3"); + + } + + @Override + public String getPromptText(ConversationContext context) { + + String text = GOLD + "- RPGItem Rewards -\n"; + if (context.getSessionData(CK.REW_RPG_ITEM_IDS) == null) { + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set IDs\n"; + } else { + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set IDs\n"; + for (Integer i : (List) context.getSessionData(CK.REW_RPG_ITEM_IDS)) { + text += AQUA + " - " + i + "\n"; + } + } + + if (context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS) == null) { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set amounts\n"; + } else { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set amounts\n"; + for (Integer i : (List) context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS)) { + text += AQUA + " - " + i + "\n"; + } + } + + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Done"; + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1")) { + return new RPGItemIdsPrompt(); + } else if (input.equalsIgnoreCase("2")) { + return new RPGItemAmountsPrompt(); + } else if (input.equalsIgnoreCase("3")) { + + int one; + int two; + + if (context.getSessionData(CK.REW_RPG_ITEM_IDS) != null) { + one = ((List) context.getSessionData(CK.REW_RPG_ITEM_IDS)).size(); + } else { + one = 0; + } + + if (context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS) != null) { + two = ((List) context.getSessionData(CK.REW_RPG_ITEM_AMOUNTS)).size(); + } else { + two = 0; + } + + if (one == two) { + return new RewardsPrompt(quests, factory); + } else { + context.getForWhom().sendRawMessage(RED + "The " + GOLD + "IDs list " + RED + "and " + GOLD + "amounts list " + RED + "are not the same size!"); + return new RPGItemsPrompt(); + } + + } + return null; + + } + + } + + private class RPGItemIdsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return YELLOW + "Enter RPGItem IDs (or names) separating each one by a space, or enter \'clear\' to clear the list, or \'cancel\' to return."; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + String[] args = input.split(" "); + LinkedList ids = new LinkedList(); + for (String s : args) { + + try { + + int id = Integer.parseInt(s); + + if (ids.contains(id)) { + context.getForWhom().sendRawMessage(RED + "Error: List contains duplicates!"); + return new RPGItemIdsPrompt(); + } + + RPGItem item = ItemManager.getItemById(id); + + if (item != null) { + ids.add(id); + } else { + context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ", not an RPGItem ID or name!"); + return new RPGItemIdsPrompt(); + } + + } catch (NumberFormatException e) { + + RPGItem item = ItemManager.getItemByName(s); + + if (item == null) { + context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ", not an RPGItem ID or name!"); + return new RPGItemIdsPrompt(); + } else { + ids.add(item.getID()); + } + } + + } + + context.setSessionData(CK.REW_RPG_ITEM_IDS, ids); + + } else if (input.equalsIgnoreCase("clear")) { + + context.setSessionData(CK.REW_RPG_ITEM_IDS, null); + context.getForWhom().sendRawMessage(YELLOW + "RPGItem IDs cleared."); + + } + + return new RPGItemsPrompt(); + + } + + } + + private class RPGItemAmountsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return YELLOW + "Enter RPGItem amounts (numbers) separating each one by a space, or enter \'clear\' to clear the list, or \'cancel\' to return."; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + String[] args = input.split(" "); + LinkedList amounts = new LinkedList(); + for (String s : args) { + + try { + + if (Integer.parseInt(s) > 0) { + amounts.add(Integer.parseInt(s)); + } else { + context.getForWhom().sendRawMessage(PINK + s + RED + " is not greater than 0!"); + return new RPGItemAmountsPrompt(); + } + + } catch (NumberFormatException e) { + context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ". Input was not a list of numbers!"); + return new RPGItemAmountsPrompt(); + } + + } + + context.setSessionData(CK.REW_RPG_ITEM_AMOUNTS, amounts); + + } else if (input.equalsIgnoreCase("clear")) { + + context.setSessionData(CK.REW_RPG_ITEM_AMOUNTS, null); + context.getForWhom().sendRawMessage(YELLOW + "RPGItem amounts cleared."); + + } + + return new RPGItemsPrompt(); + + } + + } + + private class CommandsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String note = GOLD + "\nNote: You may put to specify the player who completed the Quest. e.g. " + AQUA + BOLD + ITALIC + "smite " + RESET; + return YELLOW + "Enter command rewards separating each one by a " + BOLD + "comma" + RESET + YELLOW + ", or enter \'clear\' to clear the list, or enter \'cancel\' to return." + note; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + String[] args = input.split(","); + LinkedList commands = new LinkedList(); + for (String s : args) { + + if (s.startsWith("/")) { + s = s.substring(1); + } + + commands.add(s); + + } + + context.setSessionData(CK.REW_COMMAND, commands); + + } else if (input.equalsIgnoreCase("clear")) { + context.setSessionData(CK.REW_COMMAND, null); + } + + return new RewardsPrompt(quests, factory); + + } + + } + + private class PermissionsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return YELLOW + "Enter permission rewards separating each one by a space, or enter \'clear\' to clear the list, or enter \'cancel\' to return."; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + String[] args = input.split(" "); + LinkedList permissions = new LinkedList(); + permissions.addAll(Arrays.asList(args)); + + context.setSessionData(CK.REW_PERMISSION, permissions); + + } else if (input.equalsIgnoreCase("clear")) { + context.setSessionData(CK.REW_PERMISSION, null); + } + + return new RewardsPrompt(quests, factory); + + } + + } + + //mcMMO + private class mcMMOListPrompt extends FixedSetPrompt { + + public mcMMOListPrompt() { + + super("1", "2", "3", "4"); + + } + + @Override + public String getPromptText(ConversationContext context) { + + String text = GOLD + "- mcMMO Rewards -\n"; + if (context.getSessionData(CK.REW_MCMMO_SKILLS) == null) { + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set skills (None set)\n"; + text += GRAY + "2 - Set skill amounts (No skills set)\n"; + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; + } else { + + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set skills\n"; + for (String s : getSkills(context)) { + + text += GRAY + " - " + AQUA + s + "\n"; + + } + + if (context.getSessionData(CK.REW_MCMMO_AMOUNTS) == null) { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set skill amounts (None set)\n"; + } else { + + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set skill amounts\n"; + for (Integer i : getSkillAmounts(context)) { + + text += GRAY + " - " + AQUA + i + "\n"; + + } + + } + + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; + + } + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1")) { + return new mcMMOSkillsPrompt(); + } else if (input.equalsIgnoreCase("2")) { + if (context.getSessionData(CK.REW_MCMMO_SKILLS) == null) { + context.getForWhom().sendRawMessage(RED + "You must set skills first!"); + return new mcMMOListPrompt(); + } else { + return new mcMMOAmountsPrompt(); + } + } else if (input.equalsIgnoreCase("3")) { + context.getForWhom().sendRawMessage(YELLOW + "mcMMO rewards cleared."); + context.setSessionData(CK.REW_MCMMO_SKILLS, null); + context.setSessionData(CK.REW_MCMMO_AMOUNTS, null); + return new mcMMOListPrompt(); + } else if (input.equalsIgnoreCase("4")) { + + int one; + int two; + + if (context.getSessionData(CK.REW_MCMMO_SKILLS) != null) { + one = ((List) context.getSessionData(CK.REW_MCMMO_SKILLS)).size(); + } else { + one = 0; + } + + if (context.getSessionData(CK.REW_MCMMO_AMOUNTS) != null) { + two = ((List) context.getSessionData(CK.REW_MCMMO_AMOUNTS)).size(); + } else { + two = 0; + } + + if (one == two) { + return new RewardsPrompt(quests, factory); + } else { + context.getForWhom().sendRawMessage(RED + "The " + GOLD + "skills list " + RED + "and " + GOLD + "skill amounts list " + RED + "are not the same size!"); + return new mcMMOListPrompt(); + } + } + return null; + + } + + private List getSkills(ConversationContext context) { + return (List) context.getSessionData(CK.REW_MCMMO_SKILLS); + } + + private List getSkillAmounts(ConversationContext context) { + return (List) context.getSessionData(CK.REW_MCMMO_AMOUNTS); + } + + } + + private class mcMMOSkillsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + String skillList + = GOLD + "-Skill List-\n" + + AQUA + "Acrobatics\n" + + GRAY + "All\n" + + AQUA + "Archery\n" + + AQUA + "Axes\n" + + AQUA + "Excavation\n" + + AQUA + "Fishing\n" + + AQUA + "Herbalism\n" + + AQUA + "Mining\n" + + AQUA + "Repair\n" + + AQUA + "Smelting\n" + + AQUA + "Swords\n" + + AQUA + "Taming\n" + + AQUA + "Unarmed\n" + + AQUA + "Woodcutting\n\n"; + + return skillList + YELLOW + "Enter mcMMO skills, separating each one by a space, or enter \'cancel\' to return." + + "\n" + GOLD + "Note: The \'All\' option will give levels to all skills."; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + + String[] args = input.split(" "); + LinkedList skills = new LinkedList(); + for (String s : args) { + + if (Quests.getMcMMOSkill(s) != null) { + + if (skills.contains(s) == false) { + skills.add(Quester.getCapitalized(s)); + } else { + context.getForWhom().sendRawMessage(RED + "List contains duplicates!"); + return new mcMMOSkillsPrompt(); + } + + } else { + context.getForWhom().sendRawMessage(PINK + s + RED + " is not a valid mcMMO skill!"); + return new mcMMOSkillsPrompt(); + } + + } + + context.setSessionData(CK.REW_MCMMO_SKILLS, skills); + + } + + return new mcMMOListPrompt(); + + } + + } + + private class mcMMOAmountsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context) { + return YELLOW + "Enter skill amounts (numbers), separating each one by a space, or enter \'cancel\' to return."; + } + + @Override + public Prompt acceptInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + + String[] args = input.split(" "); + LinkedList amounts = new LinkedList(); + for (String s : args) { + + try { + + if (Integer.parseInt(s) > 0) { + amounts.add(Integer.parseInt(s)); + } else { + context.getForWhom().sendRawMessage(PINK + s + RED + " is not greater than 0!"); + return new mcMMOAmountsPrompt(); + } + + } catch (NumberFormatException e) { + context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ". Input was not a list of numbers!"); + return new mcMMOAmountsPrompt(); + } + + } + + context.setSessionData(CK.REW_MCMMO_AMOUNTS, amounts); + + } + + return new mcMMOListPrompt(); + + } + + } + + private class HeroesListPrompt extends FixedSetPrompt { + + public HeroesListPrompt() { + + super("1", "2", "3", "4"); + + } + + @Override + public String getPromptText(ConversationContext context) { + + String text = GOLD + "- Heroes Rewards -\n"; + if (context.getSessionData(CK.REW_HEROES_CLASSES) == null) { + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set classes (None set)\n"; + text += GRAY + "2 - Set experience amounts (No classes set)\n"; + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; + } else { + + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set classes\n"; + for (String s : getClasses(context)) { + + text += GRAY + " - " + AQUA + s + "\n"; + + } + + if (context.getSessionData(CK.REW_HEROES_AMOUNTS) == null) { + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set experience amounts (None set)\n"; + } else { + + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set experience amounts\n"; + for (Double d : getClassAmounts(context)) { + + text += GRAY + " - " + AQUA + d + "\n"; + + } + + } + + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Clear\n"; + text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - Done"; + + } + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + + if (input.equalsIgnoreCase("1")) { + return new HeroesClassesPrompt(); + } else if (input.equalsIgnoreCase("2")) { + if (context.getSessionData(CK.REW_HEROES_CLASSES) == null) { + context.getForWhom().sendRawMessage(RED + "You must set classes first!"); + return new HeroesListPrompt(); + } else { + return new HeroesExperiencePrompt(); + } + } else if (input.equalsIgnoreCase("3")) { + context.getForWhom().sendRawMessage(YELLOW + "Heroes rewards cleared."); + context.setSessionData(CK.REW_HEROES_CLASSES, null); + context.setSessionData(CK.REW_HEROES_AMOUNTS, null); + return new HeroesListPrompt(); + } else if (input.equalsIgnoreCase("4")) { + + int one; + int two; + + if (context.getSessionData(CK.REW_HEROES_CLASSES) != null) { + one = ((List) context.getSessionData(CK.REW_HEROES_CLASSES)).size(); + } else { + one = 0; + } + + if (context.getSessionData(CK.REW_HEROES_AMOUNTS) != null) { + two = ((List) context.getSessionData(CK.REW_HEROES_AMOUNTS)).size(); + } else { + two = 0; + } + + if (one == two) { + return new RewardsPrompt(quests, factory); + } else { + context.getForWhom().sendRawMessage(RED + "The " + GOLD + "classes list " + RED + "and " + GOLD + "experience amounts list " + RED + "are not the same size!"); + return new HeroesListPrompt(); + } + } + return null; + + } + + private List getClasses(ConversationContext context) { + return (List) context.getSessionData(CK.REW_HEROES_CLASSES); + } + + private List getClassAmounts(ConversationContext context) { + return (List) context.getSessionData(CK.REW_HEROES_AMOUNTS); + } + + } + + private class HeroesClassesPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext cc) { + + String text = PURPLE + "- " + PINK + "Heroes Classes" + PURPLE + " -\n"; + LinkedList list = new LinkedList(); + for (HeroClass hc : Quests.heroes.getClassManager().getClasses()) { + list.add(hc.getName()); + } + + if (list.isEmpty()) { + text += GRAY + "(None)\n"; + } else { + + Collections.sort(list); + + for (String s : list) { + text += PINK + s + ", "; + } + + text = text.substring(0, text.length() - 2) + "\n"; + + } + + text += YELLOW + "Enter Heroes classes separating each one by a space, or enter \"cancel\" to return."; + + return text; + } + + @Override + public Prompt acceptInput(ConversationContext cc, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + + String[] arr = input.split(" "); + LinkedList classes = new LinkedList(); + + for (String s : arr) { + + HeroClass hc = Quests.heroes.getClassManager().getClass(s); + if (hc == null) { + cc.getForWhom().sendRawMessage(RED + "Error: " + PINK + s + RED + " is not a valid Heroes class name!"); + return new HeroesClassesPrompt(); + } else { + classes.add(hc.getName()); + } + + } + + cc.setSessionData(CK.REW_HEROES_CLASSES, classes); + + return new HeroesListPrompt(); + + } else { + return new HeroesListPrompt(); + } + + } + } + + private class HeroesExperiencePrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext cc) { + + String text = PURPLE + "- " + PINK + "Heroes Experience" + PURPLE + " -\n"; + + text += YELLOW + "Enter experience amounts (numbers, decimals are allowed) separating each one by a space, or enter \"cancel\" to return."; + + return text; + } + + @Override + public Prompt acceptInput(ConversationContext cc, String input) { + + if (input.equalsIgnoreCase("cancel") == false) { + + String[] arr = input.split(" "); + LinkedList amounts = new LinkedList(); + + for (String s : arr) { + + try { + + double d = Double.parseDouble(s); + if (d > 0) { + amounts.add(d); + } else { + cc.getForWhom().sendRawMessage(RED + "Error: " + PINK + s + RED + " is not greater than zero!"); + return new HeroesExperiencePrompt(); + } + + } catch (NumberFormatException nfe) { + cc.getForWhom().sendRawMessage(RED + "Error: " + PINK + s + RED + " is not a number!"); + return new HeroesExperiencePrompt(); + } + + } + + cc.setSessionData(CK.REW_HEROES_AMOUNTS, amounts); + return new HeroesListPrompt(); + + } else { + return new HeroesListPrompt(); + } + + } + } + + private class PhatLootsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext cc) { + + String text = DARKAQUA + "- " + AQUA + "PhatLoots" + DARKAQUA + " -\n"; + + for (PhatLoot pl : PhatLootsAPI.getAllPhatLoots()) { + + text += GRAY + "- " + BLUE + pl.name + "\n"; + + } + + text += YELLOW + "Enter PhatLoots separating each one by a space, or enter \"clear\" to clear the list, or \"cancel\" to return."; + + return text; + } + + @Override + public Prompt acceptInput(ConversationContext cc, String input) { + + if (input.equalsIgnoreCase("cancel") == false && input.equalsIgnoreCase("clear") == false) { + + String[] arr = input.split(" "); + LinkedList loots = new LinkedList(); + + for (String s : arr) { + + if (PhatLootsAPI.getPhatLoot(s) == null) { + cc.getForWhom().sendRawMessage(DARKRED + s + RED + " is not a valid PhatLoot name!"); + return new PhatLootsPrompt(); + } + + } + + loots.addAll(Arrays.asList(arr)); + cc.setSessionData(CK.REW_PHAT_LOOTS, loots); + return new RewardsPrompt(quests, factory); + + } else if (input.equalsIgnoreCase("clear")) { + + cc.setSessionData(CK.REW_PHAT_LOOTS, null); + cc.getForWhom().sendRawMessage(YELLOW + "PhatLoots reward cleared."); + return new RewardsPrompt(quests, factory); + + } else { + return new RewardsPrompt(quests, factory); + } + + } + } + +}