Supply external conversation hooks, part 5. Per #570

This commit is contained in:
PikaMug 2019-08-25 03:15:42 -04:00
parent 7cdfdc0548
commit 50bbee5ec3
7 changed files with 285 additions and 85 deletions

View File

@ -138,10 +138,10 @@ public class QuestFactory implements ConversationAbandonedListener {
} }
public class MainMenuPrompt extends NumericPrompt { public class MainMenuPrompt extends NumericPrompt {
private final int maxNumber = 4; private final int size = 4;
public int getMaxNumber() { public int getSize() {
return maxNumber; return size;
} }
public String getTitle() { public String getTitle() {
@ -181,7 +181,7 @@ public class QuestFactory implements ConversationAbandonedListener {
QuestsEditorPostOpenMainPromptEvent event = new QuestsEditorPostOpenMainPromptEvent(context); QuestsEditorPostOpenMainPromptEvent event = new QuestsEditorPostOpenMainPromptEvent(context);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
String text = ChatColor.GOLD + getTitle() + "\n"; String text = ChatColor.GOLD + getTitle() + "\n";
for (int i = 1; i <= maxNumber; i++) { for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n"; text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n";
} }
return text; return text;
@ -226,10 +226,10 @@ public class QuestFactory implements ConversationAbandonedListener {
} }
public class CreateMenuPrompt extends NumericPrompt { public class CreateMenuPrompt extends NumericPrompt {
private final int maxNumber = 15; private final int size = 15;
public int getMaxNumber() { public int getSize() {
return maxNumber; return size;
} }
public String getTitle(ConversationContext context) { public String getTitle(ConversationContext context) {
@ -416,7 +416,7 @@ public class QuestFactory implements ConversationAbandonedListener {
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
String text = ChatColor.GOLD + "- " + getTitle(context) + ChatColor.GOLD + " -\n"; String text = ChatColor.GOLD + "- " + getTitle(context) + ChatColor.GOLD + " -\n";
for (int i = 1; i <= maxNumber; i++) { for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
} }
return text; return text;
@ -785,10 +785,10 @@ public class QuestFactory implements ConversationAbandonedListener {
} }
public class SavePrompt extends StringPrompt { public class SavePrompt extends StringPrompt {
private final int maxNumber = 2; private final int size = 2;
public int getMaxNumber() { public int getSize() {
return maxNumber; return size;
} }
public ChatColor getNumberColor(ConversationContext context, int number) { public ChatColor getNumberColor(ConversationContext context, int number) {
@ -823,7 +823,7 @@ public class QuestFactory implements ConversationAbandonedListener {
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
String text = getQueryText(context); String text = getQueryText(context);
for (int i = 1; i <= maxNumber; i++) { for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n"; text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n";
} }
return text; return text;
@ -877,10 +877,10 @@ public class QuestFactory implements ConversationAbandonedListener {
} }
public class ExitPrompt extends StringPrompt { public class ExitPrompt extends StringPrompt {
private final int maxNumber = 2; private final int size = 2;
public int getMaxNumber() { public int getSize() {
return maxNumber; return size;
} }
public ChatColor getNumberColor(ConversationContext context, int number) { public ChatColor getNumberColor(ConversationContext context, int number) {
@ -915,7 +915,7 @@ public class QuestFactory implements ConversationAbandonedListener {
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
String text = getQueryText(context); String text = getQueryText(context);
for (int i = 1; i <= maxNumber; i++) { for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n"; text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n";
} }
return text; return text;

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 QuestsEditorPostOpenOptionsGeneralPromptEvent extends QuestsEditorEvent {
private static final HandlerList handlers = new HandlerList();
private final QuestFactory factory;
public QuestsEditorPostOpenOptionsGeneralPromptEvent(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 QuestsEditorPostOpenOptionsPromptEvent extends QuestsEditorEvent {
private static final HandlerList handlers = new HandlerList();
private final QuestFactory factory;
public QuestsEditorPostOpenOptionsPromptEvent(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 QuestsEditorPostOpenOptionsTrueFalsePromptEvent extends QuestsEditorEvent {
private static final HandlerList handlers = new HandlerList();
private final QuestFactory factory;
public QuestsEditorPostOpenOptionsTrueFalsePromptEvent(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

@ -23,10 +23,10 @@ public class GUIDisplayPrompt extends NumericPrompt {
this.questFactory = qf; this.questFactory = qf;
} }
private final int maxNumber = 3; private final int size = 3;
public int getMaxNumber() { public int getSize() {
return maxNumber; return size;
} }
public String getTitle() { public String getTitle() {
@ -90,7 +90,7 @@ public class GUIDisplayPrompt extends NumericPrompt {
} else { } else {
text += " " + ChatColor.GRAY + "(" + Lang.get("noneSet") + ")\n"; text += " " + ChatColor.GRAY + "(" + Lang.get("noneSet") + ")\n";
} }
for (int i = 1; i <= maxNumber; i++) { for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n"; text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n";
} }
return text; return text;

View File

@ -14,57 +14,126 @@ package me.blackvein.quests.prompts;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.FixedSetPrompt; import org.bukkit.conversations.NumericPrompt;
import org.bukkit.conversations.Prompt; import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt; import org.bukkit.conversations.StringPrompt;
import me.blackvein.quests.Options; 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.QuestsEditorPostOpenOptionsPromptEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenOptionsTrueFalsePromptEvent;
import me.blackvein.quests.util.CK; import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.Lang;
public class OptionsPrompt extends FixedSetPrompt { public class OptionsPrompt extends NumericPrompt {
private final Quests plugin; private final Quests plugin;
private final QuestFactory factory; private final QuestFactory factory;
private String tempKey; private String tempKey;
private StringPrompt tempPrompt; private Prompt tempPrompt;
public OptionsPrompt(Quests plugin, QuestFactory qf) { public OptionsPrompt(Quests plugin, QuestFactory qf) {
super("1", "2", "3");
this.plugin = plugin; this.plugin = plugin;
factory = qf; factory = qf;
} }
private final int size = 3;
public int getSize() {
return size;
}
public String getTitle(ConversationContext context) {
return ChatColor.DARK_GREEN + Lang.get("optionsTitle").replace("<quest>", ChatColor.AQUA + (String) context.getSessionData(CK.Q_NAME) + ChatColor.DARK_GREEN);
}
public ChatColor getNumberColor(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.BLUE;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
public String getSelectionText(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.GOLD + Lang.get("optGeneral");
case 2:
return ChatColor.GOLD + Lang.get("optMultiplayer");
case 3:
return ChatColor.YELLOW + Lang.get("done");
default:
return null;
}
}
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
String text; QuestsEditorPostOpenOptionsPromptEvent event = new QuestsEditorPostOpenOptionsPromptEvent(factory, context);
String lang = Lang.get("optionsTitle"); plugin.getServer().getPluginManager().callEvent(event);
lang = lang.replace("<quest>", ChatColor.AQUA + (String) context.getSessionData(CK.Q_NAME) + ChatColor.DARK_GREEN);
text = ChatColor.DARK_AQUA + lang + "\n"; String text = getTitle(context) + "\n";
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.GOLD + " - " + Lang.get("optGeneral") + "\n"; for (int i = 1; i <= size; i++) {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GOLD + " - " + Lang.get("optMultiplayer") + "\n"; text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + "\n";
text += ChatColor.GREEN + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("done"); }
return text; return text;
} }
@Override @Override
protected Prompt acceptValidatedInput(ConversationContext context, String input) { protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
if (input.equalsIgnoreCase("1")) { switch (input.intValue()) {
case 1:
return new GeneralPrompt(); return new GeneralPrompt();
} else if (input.equalsIgnoreCase("2")) { case 2:
return new MultiplayerPrompt(); return new MultiplayerPrompt();
} else if (input.equalsIgnoreCase("3")) { case 3:
return factory.returnToMenu(); return factory.returnToMenu();
} default:
return null; return null;
} }
}
private class TrueFalsePrompt extends StringPrompt { public class TrueFalsePrompt extends StringPrompt {
private final int size = 3;
public int getSize() {
return size;
}
public String getQueryText() {
String text = "Choose <true> or <false>";
text = text.replace("<true>", Lang.get("true"));
text = text.replace("<false>", Lang.get("false"));
return text;
}
public String getSelectionText(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.YELLOW + Lang.get("true");
case 2:
return ChatColor.YELLOW + Lang.get("false");
case 3:
return ChatColor.RED + Lang.get("cmdClear");
default:
return null;
}
}
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
QuestsEditorPostOpenOptionsTrueFalsePromptEvent event = new QuestsEditorPostOpenOptionsTrueFalsePromptEvent(factory, context);
plugin.getServer().getPluginManager().callEvent(event);
String text = Lang.get("optBooleanPrompt"); String text = Lang.get("optBooleanPrompt");
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"));
@ -76,7 +145,7 @@ public class OptionsPrompt extends FixedSetPrompt {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
try { try {
boolean b = Boolean.parseBoolean(input); boolean b = Boolean.parseBoolean(input);
if (input.equalsIgnoreCase("t") || input.equalsIgnoreCase(Lang.get("true"))) { if (input.equalsIgnoreCase("t") || input.equalsIgnoreCase(Lang.get("true")) || input.equalsIgnoreCase(Lang.get("yesWord"))) {
b = true; b = true;
} }
context.setSessionData(tempKey, b); context.setSessionData(tempKey, b);
@ -121,44 +190,84 @@ public class OptionsPrompt extends FixedSetPrompt {
} }
} }
private class GeneralPrompt extends StringPrompt { public class GeneralPrompt extends NumericPrompt {
private final int size = 3;
public int getSize() {
return size;
}
public String getTitle() {
return ChatColor.DARK_GREEN + Lang.get("optGeneral");
}
public ChatColor getNumberColor(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.BLUE;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
public String getSelectionText(ConversationContext context, int number) {
switch (number) {
case 1:
if (context.getSessionData(CK.OPT_ALLOW_COMMANDS) == null) {
boolean defaultOpt = new Options().getAllowCommands();
return ChatColor.YELLOW + Lang.get("optAllowCommands") + " ("
+ (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")";
} else {
boolean commandsOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_COMMANDS);
return ChatColor.YELLOW + Lang.get("optAllowCommands") + " ("
+ (commandsOpt ? ChatColor.GREEN + String.valueOf(commandsOpt) : ChatColor.RED + String.valueOf(commandsOpt)) + ChatColor.YELLOW + ")";
}
case 2:
if (context.getSessionData(CK.OPT_ALLOW_QUITTING) == null) {
boolean defaultOpt = new Options().getAllowQuitting();
return ChatColor.YELLOW + Lang.get("optAllowQuitting") + " ("
+ (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")";
} else {
boolean quittingOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_QUITTING);
return ChatColor.YELLOW + Lang.get("optAllowQuitting") + " ("
+ (quittingOpt ? ChatColor.GREEN + String.valueOf(quittingOpt) : ChatColor.RED + String.valueOf(quittingOpt)) + ChatColor.YELLOW + ")";
}
case 3:
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("optGeneral") + " -\n"; QuestsEditorPostOpenOptionsGeneralPromptEvent event = new QuestsEditorPostOpenOptionsGeneralPromptEvent(factory, context);
if (context.getSessionData(CK.OPT_ALLOW_COMMANDS) == null) { plugin.getServer().getPluginManager().callEvent(event);
boolean defaultOpt = new Options().getAllowCommands();
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optAllowCommands") + " (" 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 commandsOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_COMMANDS);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optAllowCommands") + " ("
+ (commandsOpt ? ChatColor.GREEN + String.valueOf(commandsOpt) : ChatColor.RED + String.valueOf(commandsOpt)) + ChatColor.YELLOW + ")\n";
} }
if (context.getSessionData(CK.OPT_ALLOW_QUITTING) == null) {
boolean defaultOpt = new Options().getAllowQuitting();
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optAllowQuitting") + " ("
+ (defaultOpt ? ChatColor.GREEN + String.valueOf(defaultOpt) : ChatColor.RED + String.valueOf(defaultOpt)) + ChatColor.YELLOW + ")\n";
} else {
boolean quittingOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_QUITTING);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("optAllowQuitting") + " ("
+ (quittingOpt ? ChatColor.GREEN + String.valueOf(quittingOpt) : ChatColor.RED + String.valueOf(quittingOpt)) + ChatColor.YELLOW + ")\n";
}
text += ChatColor.GREEN + "" + ChatColor.BOLD + "3" + 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_ALLOW_COMMANDS; tempKey = CK.OPT_ALLOW_COMMANDS;
tempPrompt = new GeneralPrompt(); tempPrompt = new GeneralPrompt();
return new TrueFalsePrompt(); return new TrueFalsePrompt();
} else if (input.equalsIgnoreCase("2")) { case 2:
tempKey = CK.OPT_ALLOW_QUITTING; tempKey = CK.OPT_ALLOW_QUITTING;
tempPrompt = new GeneralPrompt(); tempPrompt = new GeneralPrompt();
return new TrueFalsePrompt(); return new TrueFalsePrompt();
} else if (input.equalsIgnoreCase("3")) { case 3:
tempKey = null; tempKey = null;
tempPrompt = null; tempPrompt = null;
try { try {
@ -167,10 +276,11 @@ public class OptionsPrompt extends FixedSetPrompt {
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;
} }
} }
}
private class MultiplayerPrompt extends StringPrompt { private class MultiplayerPrompt extends StringPrompt {

View File

@ -44,15 +44,15 @@ public class RequirementsPrompt extends NumericPrompt {
private Quests plugin; private Quests plugin;
private final QuestFactory factory; private final QuestFactory factory;
private final int maxNumber = 11; private final int size = 11;
public RequirementsPrompt(Quests plugin, QuestFactory qf) { public RequirementsPrompt(Quests plugin, QuestFactory qf) {
this.plugin = plugin; this.plugin = plugin;
factory = qf; factory = qf;
} }
public int getMaxNumber() { public int getSize() {
return maxNumber; return size;
} }
public String getTitle(ConversationContext context) { public String getTitle(ConversationContext context) {
@ -269,7 +269,7 @@ public class RequirementsPrompt extends NumericPrompt {
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
String text = getTitle(context) + "\n"; String text = getTitle(context) + "\n";
for (int i = 1; i <= maxNumber; i++) { for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
} }
return text; return text;