From 5edec55ff9bd529415cfbe726127159a312c2b51 Mon Sep 17 00:00:00 2001 From: Blackvein Date: Mon, 15 Oct 2012 15:28:57 -0700 Subject: [PATCH] Unstable commit --- src/me/blackvein/quests/QuestFactory.java | 4 +- .../quests/prompts/RequirementPrompt.java | 228 +++++++++++++++++- 2 files changed, 227 insertions(+), 5 deletions(-) diff --git a/src/me/blackvein/quests/QuestFactory.java b/src/me/blackvein/quests/QuestFactory.java index 96f2c9ba3..ff6d363f4 100644 --- a/src/me/blackvein/quests/QuestFactory.java +++ b/src/me/blackvein/quests/QuestFactory.java @@ -67,7 +67,7 @@ public class QuestFactory implements ConversationAbandonedListener { public MenuPrompt(){ - super ("1", "2", "3"); + super ("1", "2", "3", "4", "5", "6", "7", "8", "9"); } @@ -274,7 +274,7 @@ public class QuestFactory implements ConversationAbandonedListener { return new SetNpcStartPrompt(); } - context.setSessionData("npcStart", input); + context.setSessionData("npcStart", input.intValue()); } diff --git a/src/me/blackvein/quests/prompts/RequirementPrompt.java b/src/me/blackvein/quests/prompts/RequirementPrompt.java index e92f335e1..add3bb582 100644 --- a/src/me/blackvein/quests/prompts/RequirementPrompt.java +++ b/src/me/blackvein/quests/prompts/RequirementPrompt.java @@ -1,14 +1,18 @@ package me.blackvein.quests.prompts; +import java.util.LinkedList; +import java.util.List; +import me.blackvein.quests.Quester; import me.blackvein.quests.Quests; import org.bukkit.ChatColor; -import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.FixedSetPrompt; -import org.bukkit.conversations.Prompt; +import org.bukkit.Material; +import org.bukkit.conversations.*; public class RequirementPrompt extends FixedSetPrompt{ + Quests quests; + static final ChatColor BOLD = ChatColor.BOLD; static final ChatColor AQUA = ChatColor.AQUA; static final ChatColor DARKAQUA = ChatColor.DARK_AQUA; @@ -19,8 +23,16 @@ public class RequirementPrompt extends FixedSetPrompt{ static final ChatColor RED = ChatColor.RED; static final ChatColor DARKRED = ChatColor.DARK_RED; static final ChatColor YELLOW = ChatColor.YELLOW; + static final ChatColor GRAY = ChatColor.GRAY; static final ChatColor RESET = ChatColor.RESET; + public RequirementPrompt(Quests plugin){ + + super("1", "2", "3"); + quests = plugin; + + } + @Override public String getPromptText(ConversationContext context){ @@ -35,6 +47,12 @@ public class RequirementPrompt extends FixedSetPrompt{ text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set money requirement (" + context.getSessionData("moneyReq") + " " + (moneyReq > 1 ? Quests.getCurrency(true) : Quests.getCurrency(false)) + " )\n"; } + if(context.getSessionData("questPointsReq") == null) + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points requirement (None set)\n"; + else{ + text += BLUE + "" + BOLD + "2" + RESET + YELLOW + " - Set Quest Points requirement (" + context.getSessionData("questPointsReq") + " Quest Points)\n"; + } + return text; @@ -43,8 +61,212 @@ public class RequirementPrompt extends FixedSetPrompt{ @Override protected Prompt acceptValidatedInput(ConversationContext context, String input){ + if(input.equalsIgnoreCase("1")){ + return new MoneyPrompt(); + }else if(input.equalsIgnoreCase("2")){ + return new QuestPointsPrompt(); + } return null; } + private class MoneyPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context){ + + return YELLOW + "Enter amount of " + (Quests.economy.currencyNamePlural().isEmpty() ? "Money" : Quests.economy.currencyNamePlural()); + + } + + @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(); + } + + context.setSessionData("moneyReq", input.intValue()); + return new RequirementPrompt(quests); + + } + + } + + private class QuestPointsPrompt extends NumericPrompt { + + @Override + public String getPromptText(ConversationContext context){ + + return YELLOW + "Enter amount of Quest Points"; + + } + + @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(); + } + + context.setSessionData("questPointsReq", input.intValue()); + return new RequirementPrompt(quests); + + } + + } + + private class ItemListPrompt extends FixedSetPrompt { + + public ItemListPrompt(){ + + super("1", "2", "3"); + + } + + @Override + public String getPromptText(ConversationContext context){ + + String text = GOLD + "- Item Requirements -\n"; + if(context.getSessionData("itemIdReqs") == null){ + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set item IDs (None set)\n"; + text += GRAY + "2 - Set item amounts (No IDs set)\n"; + text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - Done"; + }else{ + + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set item IDs\n"; + for(Integer i : getItemIds(context)){ + + text += GRAY + "\t- " + AQUA + Quester.prettyItemString(i); + + } + + if(context.getSessionData("itemAmountReqs") == null){ + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set item amounts (None set)\n"; + }else{ + + text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Set item amounts\n"; + for(Integer i : getItemAmounts(context)){ + + text += GRAY + "\t- " + AQUA + i; + + } + + } + + + } + + return text; + + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input){ + + if(input.equalsIgnoreCase("1")){ + + } + return null; + + } + + private List getItemIds(ConversationContext context){ + return (List) context.getSessionData("itemIdReqs"); + } + + private List getItemAmounts(ConversationContext context){ + return (List) context.getSessionData("itemAmountReqs"); + } + + } + + private class ItemIdsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context){ + return YELLOW + "Enter item IDs, seperating 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 ids = new LinkedList(); + for(String s : args){ + + try{ + + if(Material.getMaterial(Integer.parseInt(s)) != null) + ids.add(Integer.parseInt(s)); + else{ + context.getForWhom().sendRawMessage(PINK + s + RED + " is not a valid item ID!"); + return new ItemIdsPrompt(); + } + + }catch (Exception e){ + context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ". Input was not a list of numbers!"); + return new ItemIdsPrompt(); + } + + } + + context.setSessionData("itemIdReqs", ids); + + } + + return new RequirementPrompt(quests); + + } + + + } + + private class ItemAmountsPrompt extends StringPrompt { + + @Override + public String getPromptText(ConversationContext context){ + return YELLOW + "Enter item amounts, seperating 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 ItemAmountsPrompt(); + } + + }catch (Exception e){ + context.getForWhom().sendRawMessage(RED + "Invalid entry " + PINK + s + RED + ". Input was not a list of numbers!"); + return new ItemIdsPrompt(); + } + + } + + context.setSessionData("itemAmountReqs", amounts); + + } + + return new RequirementPrompt(quests); + + } + + + } + }