From c7ed68e99f0f9ba955112ec2ee67779112e1f377 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Thu, 23 Jan 2020 17:11:23 -0500 Subject: [PATCH] Supply external conversation hooks, part 17 --- ...stOpenRequirementsItemListPromptEvent.java | 22 ++ .../quests/prompts/ItemStackPrompt.java | 4 +- .../quests/prompts/RequirementsPrompt.java | 209 +++++++++++------- 3 files changed, 157 insertions(+), 78 deletions(-) create mode 100644 main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenRequirementsItemListPromptEvent.java diff --git a/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenRequirementsItemListPromptEvent.java b/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenRequirementsItemListPromptEvent.java new file mode 100644 index 000000000..2ab64a82f --- /dev/null +++ b/main/src/main/java/me/blackvein/quests/events/editor/quests/QuestsEditorPostOpenRequirementsItemListPromptEvent.java @@ -0,0 +1,22 @@ +package me.blackvein.quests.events.editor.quests; + +import org.bukkit.conversations.ConversationContext; +import org.bukkit.event.HandlerList; + +public class QuestsEditorPostOpenRequirementsItemListPromptEvent extends QuestsEditorEvent { + private static final HandlerList handlers = new HandlerList(); + + public QuestsEditorPostOpenRequirementsItemListPromptEvent(ConversationContext context) { + super(context); + this.context = context; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/main/src/main/java/me/blackvein/quests/prompts/ItemStackPrompt.java b/main/src/main/java/me/blackvein/quests/prompts/ItemStackPrompt.java index 94c5d3954..986fee94d 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/ItemStackPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/ItemStackPrompt.java @@ -109,9 +109,9 @@ public class ItemStackPrompt extends FixedSetPrompt { menu += ChatColor.GRAY + "" + ChatColor.BOLD + "7. " + ChatColor.RESET + "" + ChatColor.GRAY + Lang.get("itemCreateSetClearMeta") + "\n"; } - menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "8. " + ChatColor.RESET + "" + ChatColor.RED + menu += ChatColor.RED + "" + ChatColor.BOLD + "8. " + ChatColor.RESET + "" + ChatColor.RED + Lang.get("cancel") + "\n"; - menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "9. " + ChatColor.RESET + "" + ChatColor.GREEN + menu += ChatColor.GREEN + "" + ChatColor.BOLD + "9. " + ChatColor.RESET + "" + ChatColor.GREEN + Lang.get("done") + "\n"; return menu; } diff --git a/main/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java b/main/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java index d5abea46d..ff6039078 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/RequirementsPrompt.java @@ -34,6 +34,7 @@ import me.blackvein.quests.CustomRequirement; import me.blackvein.quests.Quest; import me.blackvein.quests.QuestFactory; import me.blackvein.quests.Quests; +import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenRequirementsItemListPromptEvent; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenRequirementsPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; @@ -173,7 +174,7 @@ public class RequirementsPrompt extends NumericPrompt { if (context.getSessionData(CK.REQ_ITEMS) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = ""; + String text = "\n"; LinkedList items = (LinkedList) context.getSessionData(CK.REQ_ITEMS); for (int i = 0; i < items.size(); i++) { text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getName(items.get(i)) @@ -185,7 +186,7 @@ public class RequirementsPrompt extends NumericPrompt { if (context.getSessionData(CK.REQ_PERMISSION) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = ""; + String text = "\n"; List perms = (List) context.getSessionData(CK.REQ_PERMISSION); for (String s : perms) { text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; @@ -196,7 +197,7 @@ public class RequirementsPrompt extends NumericPrompt { if (context.getSessionData(CK.REQ_QUEST) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = ""; + String text = "\n"; List qs = (List) context.getSessionData(CK.REQ_QUEST); for (String s : qs) { text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; @@ -207,7 +208,7 @@ public class RequirementsPrompt extends NumericPrompt { if (context.getSessionData(CK.REQ_QUEST_BLOCK) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = ""; + String text = "\n"; List qs = (List) context.getSessionData(CK.REQ_QUEST_BLOCK); for (String s : qs) { text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n"; @@ -219,7 +220,7 @@ public class RequirementsPrompt extends NumericPrompt { if (context.getSessionData(CK.REQ_MCMMO_SKILLS) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = ""; + String text = "\n"; List skills = (List) context.getSessionData(CK.REQ_MCMMO_SKILLS); List amounts = (List) context.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS); for (String s : skills) { @@ -238,7 +239,7 @@ public class RequirementsPrompt extends NumericPrompt { && context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")\n"; } else { - String text = ""; + String text = "\n"; if (context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) != null) { text += ChatColor.AQUA + " " + Lang.get("reqHeroesPrimaryDisplay") + " " + ChatColor.BLUE + (String) context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS); @@ -256,7 +257,7 @@ public class RequirementsPrompt extends NumericPrompt { if (context.getSessionData(CK.REQ_CUSTOM) == null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { - String text = ""; + String text = "\n"; LinkedList customReqs = (LinkedList) context.getSessionData(CK.REQ_CUSTOM); for (String s : customReqs) { text += ChatColor.RESET + "" + ChatColor.DARK_PURPLE + " - " + ChatColor.LIGHT_PURPLE + s @@ -501,14 +502,95 @@ public class RequirementsPrompt extends NumericPrompt { } } - private class ItemListPrompt extends FixedSetPrompt { + private class ItemListPrompt extends NumericPrompt { + private final int size = 4; - public ItemListPrompt() { - super("1", "2", "3", "4"); + @SuppressWarnings("unused") + public int getSize() { + return size; } - + + public String getTitle() { + return Lang.get("itemRequirementsTitle"); + } + + public ChatColor getNumberColor(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.BLUE; + case 2: + if (context.getSessionData(CK.REQ_ITEMS) == null) { + return ChatColor.GRAY; + } else { + return ChatColor.BLUE; + } + case 3: + return ChatColor.RED; + case 4: + return ChatColor.GREEN; + default: + return null; + } + } + + public String getSelectionText(ConversationContext context, int number) { + switch (number) { + case 1: + return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem"); + case 2: + if (context.getSessionData(CK.REQ_ITEMS) == null) { + return ChatColor.GRAY + Lang.get("reqSetRemoveItems"); + } else { + return ChatColor.YELLOW + Lang.get("reqSetRemoveItems"); + } + case 3: + return ChatColor.YELLOW + Lang.get("clear"); + case 4: + return ChatColor.RED + Lang.get("done"); + default: + return null; + } + } + + public String getAdditionalText(ConversationContext context, int number) { + switch (number) { + case 1: + if (context.getSessionData(CK.REQ_ITEMS) != null) { + String text = "\n"; + for (ItemStack is : getItems(context)) { + text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n"; + } + return text; + } + return ""; + case 2: + if (context.getSessionData(CK.REQ_ITEMS) == null) { + return ChatColor.GRAY + "(" + Lang.get("reqNoItemsSet") + ")"; + } else { + if (context.getSessionData(CK.REQ_ITEMS_REMOVE) == null) { + return ChatColor.YELLOW + "(" + Lang.get("reqNoValuesSet") + ")"; + } else { + String text = "\n"; + for (Boolean b : getRemoveItems(context)) { + text += ChatColor.GRAY + " - " + ChatColor.AQUA + + (b.equals(Boolean.TRUE) ? Lang.get("yesWord") : Lang.get("noWord")) + "\n"; + } + return text; + } + } + case 3: + case 4: + return ""; + default: + return null; + } + } + @Override public String getPromptText(ConversationContext context) { + QuestsEditorPostOpenRequirementsItemListPromptEvent event + = new QuestsEditorPostOpenRequirementsItemListPromptEvent(context); + plugin.getServer().getPluginManager().callEvent(event); // Check/add newly made item if (context.getSessionData("newItem") != null) { if (context.getSessionData(CK.REQ_ITEMS) != null) { @@ -523,79 +605,54 @@ public class RequirementsPrompt extends NumericPrompt { context.setSessionData("newItem", null); context.setSessionData("tempStack", null); } - String text = ChatColor.GOLD + Lang.get("itemRequirementsTitle") + "\n"; - if (context.getSessionData(CK.REQ_ITEMS) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorDeliveryAddItem") + "\n"; - text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + " - " - + Lang.get("reqSetRemoveItems") + " (" + Lang.get("reqNoItemsSet") + ")\n"; - text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); - } else { - for (ItemStack is : getItems(context)) { - text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n"; - } - text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("stageEditorDeliveryAddItem") + "\n"; - if (context.getSessionData(CK.REQ_ITEMS_REMOVE) == null) { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("reqSetRemoveItems") + " (" + Lang.get("reqNoValuesSet") + ")\n"; - } else { - text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("reqSetRemoveItems") + "\n"; - for (Boolean b : getRemoveItems(context)) { - text += ChatColor.GRAY + " - " + ChatColor.AQUA - + (b.equals(Boolean.TRUE) ? Lang.get("yesWord") : Lang.get("noWord")) + "\n"; - } - } - text += ChatColor.RED + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("clear") + "\n"; - text += ChatColor.GREEN + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " - + Lang.get("done"); + String text = ChatColor.GOLD + getTitle() + "\n"; + for (int i = 1; i <= size; i++) { + text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n"; } return text; } @SuppressWarnings("unchecked") @Override - protected Prompt acceptValidatedInput(ConversationContext context, String input) { - if (input.equalsIgnoreCase("1")) { - return new ItemStackPrompt(ItemListPrompt.this); - } else if (input.equalsIgnoreCase("2")) { - if (context.getSessionData(CK.REQ_ITEMS) == null) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqMustAddItem")); + protected Prompt acceptValidatedInput(ConversationContext context, Number input) { + switch (input.intValue()) { + case 1: + return new ItemStackPrompt(ItemListPrompt.this); + case 2: + if (context.getSessionData(CK.REQ_ITEMS) == null) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqMustAddItem")); + return new ItemListPrompt(); + } else { + return new RemoveItemsPrompt(); + } + case 3: + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqItemCleared")); + context.setSessionData(CK.REQ_ITEMS, null); + context.setSessionData(CK.REQ_ITEMS_REMOVE, null); return new ItemListPrompt(); - } else { - return new RemoveItemsPrompt(); - } - } else if (input.equalsIgnoreCase("3")) { - context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqItemCleared")); - context.setSessionData(CK.REQ_ITEMS, null); - context.setSessionData(CK.REQ_ITEMS_REMOVE, null); - return new ItemListPrompt(); - } else if (input.equalsIgnoreCase("4")) { - int one; - int two; - if (context.getSessionData(CK.REQ_ITEMS) != null) { - one = ((List) context.getSessionData(CK.REQ_ITEMS)).size(); - } else { - one = 0; - } - if (context.getSessionData(CK.REQ_ITEMS_REMOVE) != null) { - two = ((List) context.getSessionData(CK.REQ_ITEMS_REMOVE)).size(); - } else { - two = 0; - } - if (one == two) { - return new RequirementsPrompt(plugin, factory); - } else { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); - return new ItemListPrompt(); - } + case 4: + int one; + int two; + if (context.getSessionData(CK.REQ_ITEMS) != null) { + one = ((List) context.getSessionData(CK.REQ_ITEMS)).size(); + } else { + one = 0; + } + if (context.getSessionData(CK.REQ_ITEMS_REMOVE) != null) { + two = ((List) context.getSessionData(CK.REQ_ITEMS_REMOVE)).size(); + } else { + two = 0; + } + if (one == two) { + return new RequirementsPrompt(plugin, factory); + } else { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); + return new ItemListPrompt(); + } + default: + return null; } - return null; } @SuppressWarnings("unchecked")