Supply external conversation hooks, part 6. Per #570

This commit is contained in:
PikaMug 2019-08-26 04:01:20 -04:00
parent 50bbee5ec3
commit d5e050412d
3 changed files with 219 additions and 60 deletions

View File

@ -0,0 +1,30 @@
package me.blackvein.quests.events.editor.quests;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.event.HandlerList;
import me.blackvein.quests.QuestFactory;
public class QuestsEditorPostOpenOptionsLevelPromptEvent extends QuestsEditorEvent {
private static final HandlerList handlers = new HandlerList();
private final QuestFactory factory;
public QuestsEditorPostOpenOptionsLevelPromptEvent(QuestFactory factory, ConversationContext context) {
super(context);
this.context = context;
this.factory = factory;
}
public QuestFactory getQuestFactory() {
return factory;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -0,0 +1,30 @@
package me.blackvein.quests.events.editor.quests;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.event.HandlerList;
import me.blackvein.quests.QuestFactory;
public class QuestsEditorPostOpenOptionsMultiplayerPromptEvent extends QuestsEditorEvent {
private static final HandlerList handlers = new HandlerList();
private final QuestFactory factory;
public QuestsEditorPostOpenOptionsMultiplayerPromptEvent(QuestFactory factory, ConversationContext context) {
super(context);
this.context = context;
this.factory = factory;
}
public QuestFactory getQuestFactory() {
return factory;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -22,6 +22,8 @@ import me.blackvein.quests.Options;
import me.blackvein.quests.QuestFactory; import me.blackvein.quests.QuestFactory;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenOptionsGeneralPromptEvent; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenOptionsGeneralPromptEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenOptionsLevelPromptEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenOptionsMultiplayerPromptEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenOptionsPromptEvent; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenOptionsPromptEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenOptionsTrueFalsePromptEvent; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenOptionsTrueFalsePromptEvent;
import me.blackvein.quests.util.CK; import me.blackvein.quests.util.CK;
@ -103,14 +105,14 @@ public class OptionsPrompt extends NumericPrompt {
public class TrueFalsePrompt extends StringPrompt { public class TrueFalsePrompt extends StringPrompt {
private final int size = 3; private final int size = 4;
public int getSize() { public int getSize() {
return size; return size;
} }
public String getQueryText() { public String getQueryText() {
String text = "Choose <true> or <false>"; String text = "Select '<true>' or '<false>'";
text = text.replace("<true>", Lang.get("true")); text = text.replace("<true>", Lang.get("true"));
text = text.replace("<false>", Lang.get("false")); text = text.replace("<false>", Lang.get("false"));
return text; return text;
@ -124,6 +126,8 @@ public class OptionsPrompt extends NumericPrompt {
return ChatColor.YELLOW + Lang.get("false"); return ChatColor.YELLOW + Lang.get("false");
case 3: case 3:
return ChatColor.RED + Lang.get("cmdClear"); return ChatColor.RED + Lang.get("cmdClear");
case 4:
return ChatColor.RED + Lang.get("cmdCancel");
default: default:
return null; return null;
} }
@ -161,15 +165,66 @@ public class OptionsPrompt extends NumericPrompt {
} }
} }
private class NumberPrompt extends StringPrompt { public class LevelPrompt extends StringPrompt {
private final int size = 6;
public int getSize() {
return size;
}
public String getQueryText() {
return "Select level of progress sharing";
}
public String getSelectionText(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.GOLD + "1";
case 2:
return ChatColor.GOLD + "2";
case 3:
return ChatColor.GOLD + "3";
case 4:
return ChatColor.GOLD + "4";
case 5:
return ChatColor.RED + Lang.get("cmdClear");
case 6:
return ChatColor.RED + Lang.get("cmdCancel");
default:
return null;
}
}
public String getAdditionalText(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.GRAY + Lang.get("everything");
case 2:
return ChatColor.GRAY + Lang.get("objectives");
case 3:
return ChatColor.GRAY + Lang.get("stageEditorStages");
case 4:
return ChatColor.GRAY + Lang.get("quests");
case 5:
return "";
case 6:
return "";
default:
return null;
}
}
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
QuestsEditorPostOpenOptionsLevelPromptEvent event = new QuestsEditorPostOpenOptionsLevelPromptEvent(factory, context);
plugin.getServer().getPluginManager().callEvent(event);
String text = Lang.get("optNumberPrompt"); String text = Lang.get("optNumberPrompt");
text += "\n" + ChatColor.GRAY + "\u2515 " + ChatColor.GOLD + "1" + ChatColor.RESET + " = " + ChatColor.GOLD + Lang.get("everything"); text += "\n" + ChatColor.GRAY + "\u2515 " + ChatColor.GOLD + "1" + ChatColor.RESET + " = " + ChatColor.GRAY + Lang.get("everything");
text += "\n" + ChatColor.GRAY + "\u2515 " + ChatColor.GOLD + "2" + ChatColor.RESET + " = " + ChatColor.GOLD + Lang.get("objectives");; text += "\n" + ChatColor.GRAY + "\u2515 " + ChatColor.GOLD + "2" + ChatColor.RESET + " = " + ChatColor.GRAY + Lang.get("objectives");;
text += "\n" + ChatColor.GRAY + "\u2515 " + ChatColor.GOLD + "3" + ChatColor.RESET + " = " + ChatColor.GOLD + Lang.get("stageEditorStages"); text += "\n" + ChatColor.GRAY + "\u2515 " + ChatColor.GOLD + "3" + ChatColor.RESET + " = " + ChatColor.GRAY + Lang.get("stageEditorStages");
text += "\n" + ChatColor.GRAY + "\u2515 " + ChatColor.GOLD + "4" + ChatColor.RESET + " = " + ChatColor.GOLD + Lang.get("quests"); text += "\n" + ChatColor.GRAY + "\u2515 " + ChatColor.GOLD + "4" + ChatColor.RESET + " = " + ChatColor.GRAY + Lang.get("quests");
return ChatColor.YELLOW + text; return ChatColor.YELLOW + text;
} }
@ -282,57 +337,100 @@ public class OptionsPrompt extends NumericPrompt {
} }
} }
private class MultiplayerPrompt extends StringPrompt { public class MultiplayerPrompt extends NumericPrompt {
private final int size = 4;
public int getSize() {
return size;
}
public String getTitle() {
return ChatColor.DARK_GREEN + Lang.get("optMultiplayer");
}
public ChatColor getNumberColor(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.BLUE;
case 3:
return ChatColor.BLUE;
case 4:
return ChatColor.GREEN;
default:
return null;
}
}
public String getSelectionText(ConversationContext context, int number) {
switch (number) {
case 1:
if (context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) == null) {
boolean defaultOpt = new Options().getUseDungeonsXLPlugin();
return ChatColor.YELLOW + Lang.get("optUseDungeonsXLPlugin") + " ("
+ (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")";
} else {
boolean dungeonsOpt = (Boolean) context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN);
return ChatColor.YELLOW + Lang.get("optUseDungeonsXLPlugin") + " ("
+ (dungeonsOpt ? ChatColor.GREEN + String.valueOf(dungeonsOpt) : ChatColor.RED + String.valueOf(dungeonsOpt)) + ChatColor.YELLOW + ")";
}
case 2:
if (context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) == null) {
boolean defaultOpt = new Options().getUsePartiesPlugin();
return ChatColor.YELLOW + Lang.get("optUsePartiesPlugin") + " ("
+ (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")";
} else {
boolean partiesOpt = (Boolean) context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN);
return ChatColor.YELLOW + Lang.get("optUsePartiesPlugin") + " ("
+ (partiesOpt ? ChatColor.GREEN + String.valueOf(partiesOpt) : ChatColor.RED + String.valueOf(partiesOpt)) + ChatColor.YELLOW + ")";
}
case 3:
if (context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL) == null) {
int defaultOpt = new Options().getShareProgressLevel();
return ChatColor.YELLOW + Lang.get("optShareProgressLevel") + " ("
+ ChatColor.AQUA + String.valueOf(defaultOpt) + ChatColor.YELLOW + ")";
} else {
int shareOpt = (Integer) context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL);
return ChatColor.YELLOW + Lang.get("optShareProgressLevel") + " ("
+ ChatColor.AQUA + String.valueOf(shareOpt) + ChatColor.YELLOW + ")";
}
case 4:
return ChatColor.YELLOW + Lang.get("done");
default:
return null;
}
}
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
String text = ChatColor.DARK_GREEN + "- " + Lang.get("optMultiplayer") + " -\n"; QuestsEditorPostOpenOptionsMultiplayerPromptEvent event = new QuestsEditorPostOpenOptionsMultiplayerPromptEvent(factory, context);
if (context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) == null) { plugin.getServer().getPluginManager().callEvent(event);
boolean defaultOpt = new Options().getUseDungeonsXLPlugin();
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optUseDungeonsXLPlugin") + " (" String text = ChatColor.DARK_GREEN + "- " + getTitle() + " -\n";
+ (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")\n"; for (int i = 1; i <= size; i++) {
} else { text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n";
boolean dungeonsOpt = (Boolean) context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optUseDungeonsXLPlugin") + " ("
+ (dungeonsOpt ? ChatColor.GREEN + String.valueOf(dungeonsOpt) : ChatColor.RED + String.valueOf(dungeonsOpt)) + ChatColor.YELLOW + ")\n";
} }
if (context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) == null) {
boolean defaultOpt = new Options().getUsePartiesPlugin();
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optUsePartiesPlugin") + " ("
+ (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")\n";
} else {
boolean partiesOpt = (Boolean) context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optUsePartiesPlugin") + " ("
+ (partiesOpt ? ChatColor.GREEN + String.valueOf(partiesOpt) : ChatColor.RED + String.valueOf(partiesOpt)) + ChatColor.YELLOW + ")\n";
}
if (context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL) == null) {
int defaultOpt = new Options().getShareProgressLevel();
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optShareProgressLevel") + " ("
+ ChatColor.AQUA + String.valueOf(defaultOpt) + ChatColor.YELLOW + ")\n";
} else {
int shareOpt = (Integer) context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optShareProgressLevel") + " ("
+ ChatColor.AQUA + String.valueOf(shareOpt) + ChatColor.YELLOW + ")\n";
}
text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("done");
return text; return text;
} }
@Override @Override
public Prompt acceptInput(ConversationContext context, String input) { public Prompt acceptValidatedInput(ConversationContext context, Number input) {
if (input.equalsIgnoreCase("1")) { switch (input.intValue()) {
case 1:
tempKey = CK.OPT_USE_DUNGEONSXL_PLUGIN; tempKey = CK.OPT_USE_DUNGEONSXL_PLUGIN;
tempPrompt = new MultiplayerPrompt(); tempPrompt = new MultiplayerPrompt();
return new TrueFalsePrompt(); return new TrueFalsePrompt();
} else if (input.equalsIgnoreCase("2")) { case 2:
tempKey = CK.OPT_USE_PARTIES_PLUGIN; tempKey = CK.OPT_USE_PARTIES_PLUGIN;
tempPrompt = new MultiplayerPrompt(); tempPrompt = new MultiplayerPrompt();
return new TrueFalsePrompt(); return new TrueFalsePrompt();
} else if (input.equalsIgnoreCase("3")) { case 3:
tempKey = CK.OPT_SHARE_PROGRESS_LEVEL; tempKey = CK.OPT_SHARE_PROGRESS_LEVEL;
tempPrompt = new MultiplayerPrompt(); tempPrompt = new MultiplayerPrompt();
return new NumberPrompt(); return new LevelPrompt();
} else if (input.equalsIgnoreCase("4")) { case 4:
tempKey = null; tempKey = null;
tempPrompt = null; tempPrompt = null;
try { try {
@ -341,8 +439,9 @@ public class OptionsPrompt extends NumericPrompt {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateCriticalError")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateCriticalError"));
return Prompt.END_OF_CONVERSATION; return Prompt.END_OF_CONVERSATION;
} }
} default:
return null; return null;
} }
} }
}
} }