Supply external conversation hooks, part 35

This commit is contained in:
PikaMug 2020-08-29 01:01:33 -04:00
parent da4f753cc2
commit b60edbf699
5 changed files with 291 additions and 85 deletions

View File

@ -244,7 +244,8 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
@Override
public String getPromptText(final ConversationContext context) {
final ActionsEditorPostOpenStringPromptEvent event = new ActionsEditorPostOpenStringPromptEvent(context, this);
final ActionsEditorPostOpenStringPromptEvent event
= new ActionsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
return ChatColor.YELLOW + getQueryText(context);
@ -961,10 +962,38 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
}
}
private final int size = 2;
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN;
case 2:
return ChatColor.RED;
default:
return null;
}
}
public String getSelectionText(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN + Lang.get("yesWord");
case 2:
return ChatColor.RED + Lang.get("noWord");
default:
return null;
}
}
@Override
public String getQueryText(final ConversationContext context) {
@ -976,8 +1005,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
final ActionsEditorPostOpenStringPromptEvent event = new ActionsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.YELLOW + getQueryText(context) + " \"" + ChatColor.AQUA
+ context.getSessionData(CK.E_NAME) + ChatColor.YELLOW + "\"?\n";
String text = ChatColor.YELLOW + getQueryText(context) + "\n";
if (modified.isEmpty() == false) {
text += ChatColor.RED + Lang.get("eventEditorModifiedNote") + "\n";
for (final String s : modified) {
@ -985,7 +1013,11 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
}
text += ChatColor.RED + Lang.get("eventEditorForcedToQuit") + "\n";
}
return text + ChatColor.GREEN + "1 - " + Lang.get("yesWord") + "\n" + "2 - " + Lang.get("noWord");
for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + "\n";
}
return text;
}
@Override
@ -1006,11 +1038,39 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
public ActionExitPrompt(final ConversationContext context) {
super(context);
}
private final int size = 2;
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN;
case 2:
return ChatColor.RED;
default:
return null;
}
}
public String getSelectionText(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN + Lang.get("yesWord");
case 2:
return ChatColor.RED + Lang.get("noWord");
default:
return null;
}
}
@Override
public String getQueryText(final ConversationContext context) {
@ -1019,13 +1079,16 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
@Override
public String getPromptText(final ConversationContext context) {
final ActionsEditorPostOpenStringPromptEvent event = new ActionsEditorPostOpenStringPromptEvent(context, this);
final ActionsEditorPostOpenStringPromptEvent event
= new ActionsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
final String text = ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.GREEN + " - "
+ Lang.get("yesWord") + "\n" + ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET
+ ChatColor.RED + " - " + Lang.get("noWord");
return ChatColor.YELLOW + getQueryText(context) + "\n" + text;
String text = ChatColor.YELLOW + getQueryText(context) + "\n";
for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + "\n";
}
return text;
}
@Override

View File

@ -18,16 +18,17 @@ import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quests;
import me.blackvein.quests.Stage;
import me.blackvein.quests.conditions.Condition;
import me.blackvein.quests.convo.conditions.ConditionsEditorNumericPrompt;
import me.blackvein.quests.convo.conditions.ConditionsEditorStringPrompt;
import me.blackvein.quests.convo.conditions.tasks.PlayerPrompt;
import me.blackvein.quests.convo.conditions.tasks.WorldPrompt;
import me.blackvein.quests.events.editor.conditions.ConditionsEditorPostOpenNumericPromptEvent;
import me.blackvein.quests.events.editor.conditions.ConditionsEditorPostOpenStringPromptEvent;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.Lang;
@ -127,7 +128,7 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
public Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
switch (input.intValue()) {
case 1:
return new ConditionNamePrompt();
return new ConditionNamePrompt(context);
case 2:
return new PlayerPrompt(context);
case 3:
@ -142,22 +143,40 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
return new ConditionMainPrompt(context);
case 5:
if (context.getSessionData(CK.C_OLD_CONDITION) != null) {
return new ConditionSavePrompt((String) context.getSessionData(CK.C_OLD_CONDITION));
return new ConditionSavePrompt(context, (String) context.getSessionData(CK.C_OLD_CONDITION));
} else {
return new ConditionSavePrompt(null);
return new ConditionSavePrompt(context, null);
}
case 6:
return new ConditionExitPrompt();
return new ConditionExitPrompt(context);
default:
return new ConditionMainPrompt(context);
}
}
private class ConditionNamePrompt extends StringPrompt {
public class ConditionNamePrompt extends ConditionsEditorStringPrompt {
public ConditionNamePrompt(final ConversationContext context) {
super(context);
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("conditionEditorEnterName");
}
@Override
public String getPromptText(final ConversationContext context) {
return ChatColor.YELLOW + Lang.get("conditionEditorEnterName");
final ConditionsEditorPostOpenStringPromptEvent event
= new ConditionsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
return ChatColor.YELLOW + getQueryText(context);
}
@Override
@ -166,17 +185,17 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
for (final Condition c : plugin.getConditions()) {
if (c.getName().equalsIgnoreCase(input)) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("conditionEditorExists"));
return new ConditionNamePrompt();
return new ConditionNamePrompt(context);
}
}
final List<String> actionNames = plugin.getConditionFactory().getNamesOfConditionsBeingEdited();
if (actionNames.contains(input)) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited"));
return new ConditionNamePrompt();
return new ConditionNamePrompt(context);
}
if (input.contains(",")) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName"));
return new ConditionNamePrompt();
return new ConditionNamePrompt(context);
}
actionNames.remove(context.getSessionData(CK.C_NAME));
context.setSessionData(CK.C_NAME, input);
@ -187,12 +206,13 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
}
}
private class ConditionSavePrompt extends StringPrompt {
public class ConditionSavePrompt extends ConditionsEditorStringPrompt {
String modName = null;
LinkedList<String> modified = new LinkedList<String>();
public ConditionSavePrompt(final String modifiedName) {
public ConditionSavePrompt(final ConversationContext context, final String modifiedName) {
super(context);
if (modifiedName != null) {
modName = modifiedName;
for (final Quest q : plugin.getQuests()) {
@ -207,11 +227,52 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
}
}
}
private final int size = 2;
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN;
case 2:
return ChatColor.RED;
default:
return null;
}
}
public String getSelectionText(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN + Lang.get("yesWord");
case 2:
return ChatColor.RED + Lang.get("noWord");
default:
return null;
}
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("questEditorSave");
}
@Override
public String getPromptText(final ConversationContext context) {
String text = ChatColor.YELLOW + Lang.get("questEditorSave") + " \"" + ChatColor.AQUA
+ context.getSessionData(CK.C_NAME) + ChatColor.YELLOW + "\"?\n";
final ConditionsEditorPostOpenStringPromptEvent event
= new ConditionsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
String text = ChatColor.YELLOW + getQueryText(context) + "\n";
if (modified.isEmpty() == false) {
text += ChatColor.RED + Lang.get("conditionEditorModifiedNote") + "\n";
for (final String s : modified) {
@ -219,7 +280,11 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
}
text += ChatColor.RED + Lang.get("conditionEditorForcedToQuit") + "\n";
}
return text + ChatColor.GREEN + "1 - " + Lang.get("yesWord") + "\n" + "2 - " + Lang.get("noWord");
for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + "\n";
}
return text;
}
@Override
@ -230,19 +295,67 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
} else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) {
return new ConditionMainPrompt(context);
} else {
return new ConditionSavePrompt(modName);
return new ConditionSavePrompt(context, modName);
}
}
}
private class ConditionExitPrompt extends StringPrompt {
public class ConditionExitPrompt extends ConditionsEditorStringPrompt {
public ConditionExitPrompt(final ConversationContext context) {
super(context);
}
private final int size = 2;
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN;
case 2:
return ChatColor.RED;
default:
return null;
}
}
public String getSelectionText(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN + Lang.get("yesWord");
case 2:
return ChatColor.RED + Lang.get("noWord");
default:
return null;
}
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("confirmDelete");
}
@Override
public String getPromptText(final ConversationContext context) {
final String text = ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.GREEN + " - "
+ Lang.get("yesWord") + "\n" + ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET
+ ChatColor.RED + " - " + Lang.get("noWord");
return ChatColor.YELLOW + Lang.get("confirmDelete") + "\n" + text;
final ConditionsEditorPostOpenStringPromptEvent event
= new ConditionsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.YELLOW + getQueryText(context) + "\n";
for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + "\n";
}
return text;
}
@Override
@ -254,7 +367,7 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
} else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) {
return new ConditionMainPrompt(context);
} else {
return new ConditionExitPrompt();
return new ConditionExitPrompt(context);
}
}
}

View File

@ -847,16 +847,16 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
@Override
public String getQueryText(final ConversationContext context) {
return ChatColor.YELLOW + Lang.get("questEditorSave") + " \"" + ChatColor.AQUA
+ context.getSessionData(CK.Q_NAME) + ChatColor.YELLOW + "\"?";
return Lang.get("questEditorSave");
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
final QuestsEditorPostOpenStringPromptEvent event
= new QuestsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
String text = getQueryText(context) + "\n";
String text = ChatColor.YELLOW + getQueryText(context) + "\n";
for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + "\n";
@ -965,7 +965,8 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
final QuestsEditorPostOpenStringPromptEvent event
= new QuestsEditorPostOpenStringPromptEvent(context, this);
plugin.getServer().getPluginManager().callEvent(event);
String text = ChatColor.YELLOW + getQueryText(context) + "\n";

View File

@ -526,7 +526,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
return new StageMainPrompt(stageNum, context);
}
case 16:
return new DeletePrompt(context);
return new StageDeletePrompt(context);
case 17:
return new StageMenuPrompt(context);
default:
@ -2068,53 +2068,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
}
}
}
// TODO - should be a Numeric prompt
public class DeletePrompt extends QuestsEditorStringPrompt {
public DeletePrompt(final ConversationContext context) {
super(context);
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("confirmDelete");
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.GREEN + "" + ChatColor.BOLD + "1" + ChatColor.RESET + " - " + ChatColor.GREEN
+ Lang.get("yesWord") + "\n";
text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + " - " + ChatColor.RED
+ Lang.get("noWord");
return ChatColor.RED + getQueryText(context) + " (" + ChatColor.YELLOW + Lang.get("stageEditorStage")
+ " " + stageNum + ChatColor.RED + ")\n" + ChatColor.GOLD + "("
+ Lang.get("stageEditorConfirmStageNote") + ")\n" + text;
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
final Player player = (Player) context.getForWhom();
if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase("Yes")) {
new StageMenuPrompt(context).deleteStage(context, stageNum);
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorDeleteSucces"));
return new StageMenuPrompt(context);
} else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase("No")) {
return new StageMainPrompt(stageNum, context);
} else {
player.sendMessage(ChatColor.RED + Lang.get("invalidOption"));
return new DeletePrompt(context);
}
}
}
public class StartMessagePrompt extends QuestsEditorStringPrompt {
@ -2198,6 +2152,81 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
}
}
public class StageDeletePrompt extends QuestsEditorStringPrompt {
public StageDeletePrompt(final ConversationContext context) {
super(context);
}
public final int size = 2;
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return null;
}
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN;
case 2:
return ChatColor.RED;
default:
return null;
}
}
public String getSelectionText(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.GREEN + Lang.get("yesWord");
case 2:
return ChatColor.RED + Lang.get("noWord");
default:
return null;
}
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("confirmDelete");
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.YELLOW + getQueryText(context) + " (" + ChatColor.RED + Lang.get("stageEditorStage")
+ " " + stageNum + ChatColor.YELLOW + ")\n" + ChatColor.GOLD + "("
+ Lang.get("stageEditorConfirmStageNote") + ")\n";
for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + "\n";
}
return text;
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
final Player player = (Player) context.getForWhom();
if (input.equalsIgnoreCase("1") || input.equalsIgnoreCase(Lang.get("yesWord"))) {
new StageMenuPrompt(context).deleteStage(context, stageNum);
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorDeleteSucces"));
return new StageMenuPrompt(context);
} else if (input.equalsIgnoreCase("2") || input.equalsIgnoreCase(Lang.get("noWord"))) {
return new StageMainPrompt(stageNum, context);
} else {
player.sendMessage(ChatColor.RED + Lang.get("invalidOption"));
return new StageDeletePrompt(context);
}
}
}
public class CustomObjectivesPrompt extends QuestsEditorStringPrompt {
public CustomObjectivesPrompt(final ConversationContext context) {

View File

@ -105,7 +105,7 @@ questEditorQuestAsRequirement2: "as a requirement:"
questEditorQuestAsRequirement3: "You must modify these quests so that they do not use it before deleting it."
questEditorQuestNotFound: "Quest not found!"
questEditorEventCleared: "Initial action cleared."
questEditorSave: "Finish and save"
questEditorSave: "Finish and save?"
questEditorNeedAskMessage: "You must set an ask message!"
questEditorNeedFinishMessage: "You must set a finish message!"
questEditorNeedStages: "Your quest has no stages!"