Added multiple password phrase functionality

Fixed redo delay bug
This commit is contained in:
Blackvein 2014-03-08 12:59:58 -08:00
parent 7722ccead4
commit fe19fd4fe6
4 changed files with 165 additions and 122 deletions

View File

@ -820,9 +820,10 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
} }
if(done) if (done) {
break; break;
} }
}
if (found == null) { if (found == null) {
player.sendMessage(RED + input + YELLOW + " is not a valid WorldGuard region!"); player.sendMessage(RED + input + YELLOW + " is not a valid WorldGuard region!");
@ -854,6 +855,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
@Override @Override
public Prompt acceptInput(ConversationContext context, String input) { public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new CreateMenuPrompt(); return new CreateMenuPrompt();
} }
@ -864,11 +866,13 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
try { try {
delay = Long.parseLong(input); delay = Long.parseLong(input);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
delay = MiscUtil.getTimeFromString(input); context.getForWhom().sendRawMessage(ITALIC + "" + RED + input + RESET + RED + " " + Lang.get("stageEditorInvalidNumber"));
//delay = MiscUtil.getTimeFromString(input);
return new RedoDelayPrompt();
} }
if (delay < -1) { if (delay < -1) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorPositiveAmount")); context.getForWhom().sendRawMessage(RED + Lang.get("questEditorPositiveAmount"));
} else if (delay == 0) { } else if (delay == 0) {
context.setSessionData(CK.Q_REDO_DELAY, null); context.setSessionData(CK.Q_REDO_DELAY, null);
} else if (delay != -1) { } else if (delay != -1) {
@ -1263,7 +1267,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
LinkedList<Integer> shearAmounts; LinkedList<Integer> shearAmounts;
LinkedList<String> passDisplays; LinkedList<String> passDisplays;
LinkedList<String> passPhrases; LinkedList<LinkedList<String>> passPhrases;
LinkedList<String> customObjs; LinkedList<String> customObjs;
LinkedList<Integer> customObjCounts; LinkedList<Integer> customObjCounts;
@ -1436,7 +1440,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
if (cc.getSessionData(pref + CK.S_PASSWORD_DISPLAYS) != null) { if (cc.getSessionData(pref + CK.S_PASSWORD_DISPLAYS) != null) {
passDisplays = (LinkedList<String>) cc.getSessionData(pref + CK.S_PASSWORD_DISPLAYS); passDisplays = (LinkedList<String>) cc.getSessionData(pref + CK.S_PASSWORD_DISPLAYS);
passPhrases = (LinkedList<String>) cc.getSessionData(pref + CK.S_PASSWORD_PHRASES); passPhrases = (LinkedList<LinkedList<String>>) cc.getSessionData(pref + CK.S_PASSWORD_PHRASES);
} }
if (cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) != null) { if (cc.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) != null) {
@ -1544,7 +1548,25 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
stage.set("sheep-to-shear", shearColors); stage.set("sheep-to-shear", shearColors);
stage.set("sheep-amounts", shearAmounts); stage.set("sheep-amounts", shearAmounts);
stage.set("password-displays", passDisplays); stage.set("password-displays", passDisplays);
stage.set("password-phrases", passPhrases); if (passPhrases != null) {
LinkedList<String> toPut = new LinkedList<String>();
for (LinkedList<String> list : passPhrases) {
String combine = "";
for (String s : list) {
if (list.getLast().equals(s) == false) {
combine += s + "|";
} else {
combine += s;
}
}
toPut.add(combine);
}
stage.set("password-phrases", toPut);
}
if (customObjs != null && customObjs.isEmpty() == false) { if (customObjs != null && customObjs.isEmpty() == false) {
ConfigurationSection sec = stage.createSection("custom-objectives"); ConfigurationSection sec = stage.createSection("custom-objectives");
@ -1553,8 +1575,9 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
ConfigurationSection sec2 = sec.createSection("custom" + (index + 1)); ConfigurationSection sec2 = sec.createSection("custom" + (index + 1));
sec2.set("name", customObjs.get(index)); sec2.set("name", customObjs.get(index));
sec2.set("count", customObjCounts.get(index)); sec2.set("count", customObjCounts.get(index));
if(customObjsData.get(index).isEmpty() == false) if (customObjsData.get(index).isEmpty() == false) {
sec2.set("data", customObjsData.get(index)); sec2.set("data", customObjsData.get(index));
}
} }

View File

@ -518,15 +518,15 @@ public class Quester {
} }
for (String s : currentStage.passwordPhrases) { for (String s : currentStage.passwordDisplays) {
if (passwordsSaid.get(s) == false) { if (passwordsSaid.get(s) == false) {
unfinishedObjectives.add(ChatColor.GREEN + currentStage.passwordDisplays.get(currentStage.passwordPhrases.indexOf(s))); unfinishedObjectives.add(ChatColor.GREEN + s);
} else { } else {
finishedObjectives.add(ChatColor.GRAY + currentStage.passwordDisplays.get(currentStage.passwordPhrases.indexOf(s))); finishedObjectives.add(ChatColor.GRAY + s);
} }
@ -1017,19 +1017,31 @@ public class Quester {
public void sayPass(AsyncPlayerChatEvent evt) { public void sayPass(AsyncPlayerChatEvent evt) {
for (String pass : currentStage.passwordPhrases) { boolean done;
for (LinkedList<String> passes : currentStage.passwordPhrases) {
done = false;
for(String pass : passes){
if (pass.equalsIgnoreCase(evt.getMessage())) { if (pass.equalsIgnoreCase(evt.getMessage())) {
evt.setCancelled(true); evt.setCancelled(true);
String display = currentStage.passwordDisplays.get(currentStage.passwordPhrases.indexOf(pass)); String display = currentStage.passwordDisplays.get(currentStage.passwordPhrases.indexOf(passes));
passwordsSaid.put(pass, true); passwordsSaid.put(display, true);
done = true;
finishObjective("password", null, null, null, null, null, null, null, null, display, null); finishObjective("password", null, null, null, null, null, null, null, null, display, null);
break;
} }
} }
if(done)
break;
}
} }
public void finishObjective(String objective, Material material, ItemStack itemstack, Enchantment enchantment, EntityType mob, String player, NPC npc, Location location, DyeColor color, String pass, CustomObjective co) { public void finishObjective(String objective, Material material, ItemStack itemstack, Enchantment enchantment, EntityType mob, String player, NPC npc, Location location, DyeColor color, String pass, CustomObjective co) {
@ -1368,9 +1380,9 @@ public class Quester {
} }
} }
if (currentStage.passwordPhrases.isEmpty() == false) { if (currentStage.passwordDisplays.isEmpty() == false) {
for (String pass : currentStage.passwordPhrases) { for (String display : currentStage.passwordDisplays) {
passwordsSaid.put(pass, false); passwordsSaid.put(display, false);
} }
} }

View File

@ -3280,15 +3280,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
List<String> phrases = config.getStringList("quests." + s + ".stages.ordered." + s2 + ".password-phrases"); List<String> phrases = config.getStringList("quests." + s + ".stages.ordered." + s2 + ".password-phrases");
if(displays.size() == phrases.size()) { if(displays.size() == phrases.size()) {
for(int index = 0; index < displays.size(); index++){ for(int passIndex = 0; passIndex < displays.size(); passIndex++){
oStage.passwordDisplays.add(displays.get(index)); oStage.passwordDisplays.add(displays.get(passIndex));
LinkedList<String> answers = new LinkedList<String>(); LinkedList<String> answers = new LinkedList<String>();
answers.addAll(Arrays.asList(phrases.get(index).split(""))); answers.addAll(Arrays.asList(phrases.get(passIndex).split("\\|")));
oStage.passwordPhrases.add(answers);
} }
oStage.passwordDisplays.addAll(displays);
oStage.passwordPhrases.addAll(phrases);
} else { } else {
printSevere("[Quests] password-displays and password-phrases in Stage " + s2 + " of Quest " + quest.name + " are not the same size!"); printSevere("[Quests] password-displays and password-phrases in Stage " + s2 + " of Quest " + quest.name + " are not the same size!");
@ -4284,17 +4283,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
String message = ""; String message = "";
Calendar calendar = Calendar.getInstance(); long days = milliseconds / 86400000;
calendar.setTimeInMillis(milliseconds); long hours = (milliseconds % 86400000) / 3600000;
long minutes = ((milliseconds % 86400000) % 3600000) / 60000;
long seconds = (((milliseconds % 86400000) % 3600000) % 60000) / 1000;
long milliSeconds2 = (((milliseconds % 86400000) % 3600000) % 60000) % 1000;
Calendar epoch = Calendar.getInstance();
epoch.setTimeInMillis(0);
long days = calendar.get(Calendar.DAY_OF_YEAR) - epoch.get(Calendar.DAY_OF_YEAR);
long hours = calendar.get(Calendar.HOUR_OF_DAY) - epoch.get(Calendar.HOUR_OF_DAY);
long minutes = calendar.get(Calendar.MINUTE);
long seconds = calendar.get(Calendar.SECOND);
long milliSeconds2 = calendar.get(Calendar.MILLISECOND);
if (days > 0) { if (days > 0) {
if (days == 1) { if (days == 1) {

View File

@ -316,13 +316,16 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
} }
if (context.getSessionData(pref + CK.S_PASSWORD_PHRASES) == null) { if (context.getSessionData(pref + CK.S_PASSWORD_PHRASES) == null) {
text += PURPLE + "" + BOLD + "20 " + RESET + PURPLE + "- Password Objectives" + GRAY + " (" + Lang.get("noneSet") + ")\n"; text += PINK + "" + BOLD + "20 " + RESET + PURPLE + "- Password Objectives" + GRAY + " (" + Lang.get("noneSet") + ")\n";
} else { } else {
LinkedList<String> passPhrases = (LinkedList<String>) context.getSessionData(pref + CK.S_PASSWORD_PHRASES); LinkedList<LinkedList<String>> passPhrases = (LinkedList<LinkedList<String>>) context.getSessionData(pref + CK.S_PASSWORD_PHRASES);
LinkedList<String> passDisplays = (LinkedList<String>) context.getSessionData(pref + CK.S_PASSWORD_DISPLAYS); LinkedList<String> passDisplays = (LinkedList<String>) context.getSessionData(pref + CK.S_PASSWORD_DISPLAYS);
text += PURPLE + "" + BOLD + "20 " + RESET + PURPLE + "- Password Objectives\n"; text += PINK + "" + BOLD + "20 " + RESET + PURPLE + "- Password Objectives\n";
for(int i = 0; i < passPhrases.size(); i++){ for(int i = 0; i < passPhrases.size(); i++){
text += AQUA + " - \"" + passDisplays.get(i) + "\"" + RESET + DARKAQUA + " (" + passPhrases.get(i) + ")" + "\n"; text += AQUA + " - \"" + passDisplays.get(i) + "\"\n";
LinkedList<String> phrases = passPhrases.get(i);
for(String phrase : phrases)
text += DARKAQUA + " - " + phrase + "\n";
} }
} }
@ -461,7 +464,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
String text = GOLD + "- Password Objectives -\n"; String text = GOLD + "- Password Objectives -\n";
if (context.getSessionData(pref + CK.S_PASSWORD_DISPLAYS) == null) { if (context.getSessionData(pref + CK.S_PASSWORD_DISPLAYS) == null) {
text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add password display (" + Lang.get("noneSet") + ")\n"; text += BLUE + "" + BOLD + "1" + RESET + YELLOW + " - Add password display (" + Lang.get("noneSet") + ")\n";
text += GRAY + "2 - " + "Add password phrase (No password displays set)\n"; text += GRAY + "2 - " + "Add password phrase(s) (No password displays set)\n";
text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - " + Lang.get("clear") + "\n"; text += BLUE + "" + BOLD + "3" + RESET + YELLOW + " - " + Lang.get("clear") + "\n";
text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - " + Lang.get("done"); text += BLUE + "" + BOLD + "4" + RESET + YELLOW + " - " + Lang.get("done");
} else { } else {
@ -474,13 +477,19 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
} }
if (context.getSessionData(pref + CK.S_PASSWORD_PHRASES) == null) { if (context.getSessionData(pref + CK.S_PASSWORD_PHRASES) == null) {
text += YELLOW + "2 - " + "Add password phrase (" + Lang.get("noneSet") + ")\n"; text += YELLOW + "2 - " + "Add password phrase(s) (" + Lang.get("noneSet") + ")\n";
} else { } else {
text += YELLOW + "2 - " + "Add password phrase\n"; text += YELLOW + "2 - " + "Add password phrase(s)\n";
for (String phrase : getPasswordPhrases(context)) { for (LinkedList<String> phraseList : getPasswordPhrases(context)) {
text += GRAY + " - " + DARKAQUA + phrase + "\n"; text += GRAY + " - ";
for(String s : phraseList){
if(phraseList.getLast().equals(s) == false)
text += DARKAQUA + s + GRAY + "|";
else
text += DARKAQUA + s + "\n";
}
} }
@ -524,7 +533,7 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
} }
if (context.getSessionData(pref + CK.S_PASSWORD_PHRASES) != null) { if (context.getSessionData(pref + CK.S_PASSWORD_PHRASES) != null) {
two = ((List<String>) context.getSessionData(pref + CK.S_PASSWORD_PHRASES)).size(); two = ((LinkedList<LinkedList<String>>) context.getSessionData(pref + CK.S_PASSWORD_PHRASES)).size();
} else { } else {
two = 0; two = 0;
} }
@ -544,8 +553,8 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
return (List<String>) context.getSessionData(pref + CK.S_PASSWORD_DISPLAYS); return (List<String>) context.getSessionData(pref + CK.S_PASSWORD_DISPLAYS);
} }
private List<String> getPasswordPhrases(ConversationContext context) { private LinkedList<LinkedList<String>> getPasswordPhrases(ConversationContext context) {
return (List<String>) context.getSessionData(pref + CK.S_PASSWORD_PHRASES); return (LinkedList<LinkedList<String>>) context.getSessionData(pref + CK.S_PASSWORD_PHRASES);
} }
} }
@ -595,7 +604,8 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
String text = YELLOW + "Enter a password phrase, or 'cancel' to return\n"; String text = YELLOW + "Enter a password phrase, or 'cancel' to return\n";
text += ITALIC + "" + GOLD + "(This is the text that a player has to say to complete the objective)"; text += ITALIC + "" + GOLD + "(This is the text that a player has to say to complete the objective)\n";
text += RESET + "" + YELLOW + "If you want multiple password phrases, seperate them by a | (pipe)";
return text; return text;
@ -608,14 +618,18 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
if(context.getSessionData(pref + CK.S_PASSWORD_PHRASES) != null) { if(context.getSessionData(pref + CK.S_PASSWORD_PHRASES) != null) {
List<String> phrases = (List<String>) context.getSessionData(pref + CK.S_PASSWORD_PHRASES); LinkedList<LinkedList<String>> phrases = (LinkedList<LinkedList<String>>) context.getSessionData(pref + CK.S_PASSWORD_PHRASES);
phrases.add(input); LinkedList<String> newPhrases = new LinkedList<String>();
newPhrases.addAll(Arrays.asList(input.split("\\|")));
phrases.add(newPhrases);
context.setSessionData(pref + CK.S_PASSWORD_PHRASES, phrases); context.setSessionData(pref + CK.S_PASSWORD_PHRASES, phrases);
} else { } else {
List<String> phrases = new LinkedList<String>(); LinkedList<LinkedList<String>> phrases = new LinkedList<LinkedList<String>>();
phrases.add(input); LinkedList<String> newPhrases = new LinkedList<String>();
newPhrases.addAll(Arrays.asList(input.split("\\|")));
phrases.add(newPhrases);
context.setSessionData(pref + CK.S_PASSWORD_PHRASES, phrases); context.setSessionData(pref + CK.S_PASSWORD_PHRASES, phrases);
} }