From fcb1900e57233d2aab14b387e8ea99c86d35d4d6 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Wed, 25 Mar 2020 02:20:28 -0400 Subject: [PATCH] Better tracking of quests, actions, and NPCs being selected --- .../me/blackvein/quests/QuestFactory.java | 47 ++++++++++++------- .../quests/actions/ActionFactory.java | 22 ++++++--- .../convo/quests/prompts/NPCsPrompt.java | 27 ++++++----- .../quests/listeners/NpcListener.java | 4 +- .../quests/listeners/PlayerListener.java | 8 ++-- 5 files changed, 66 insertions(+), 42 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/QuestFactory.java b/main/src/main/java/me/blackvein/quests/QuestFactory.java index f701eac3e..56f77acb8 100644 --- a/main/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/main/src/main/java/me/blackvein/quests/QuestFactory.java @@ -20,6 +20,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.UUID; import org.bukkit.ChatColor; @@ -71,8 +72,8 @@ public class QuestFactory implements ConversationAbandonedListener { private Map selectedBlockStarts = new HashMap(); private Map selectedKillLocations = new HashMap(); private Map selectedReachLocations = new HashMap(); - private HashSet selectingNpcs = new HashSet(); - private List names = new LinkedList(); + private Set selectingNpcs = new HashSet(); + private List editingQuestNames = new LinkedList(); public QuestFactory(Quests plugin) { this.plugin = plugin; @@ -106,21 +107,35 @@ public class QuestFactory implements ConversationAbandonedListener { public void setSelectedReachLocations(Map selectedReachLocations) { this.selectedReachLocations = selectedReachLocations; } - - public HashSet getSelectingNpcs() { + + public Set getSelectingNpcs() { return selectingNpcs; } - public void setSelectingNpcs(HashSet selectingNpcs) { + public void setSelectingNpcs(Set selectingNpcs) { this.selectingNpcs = selectingNpcs; } + /** + * @deprecated Use {@link#getNamesOfQuestsBeingEdited} + */ public List getNames() { - return names; + return editingQuestNames; } + /** + * @deprecated Use {@link#setNamesOfQuestsBeingEdited} + */ public void setNames(List names) { - this.names = names; + this.editingQuestNames = names; + } + + public List getNamesOfQuestsBeingEdited() { + return editingQuestNames; + } + + public void setNamesOfQuestsBeingEdited(List questNames) { + this.editingQuestNames = questNames; } public ConversationFactory getConversationFactory() { @@ -130,7 +145,7 @@ public class QuestFactory implements ConversationAbandonedListener { @Override public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { if (abandonedEvent.getContext().getSessionData(CK.Q_NAME) != null) { - names.remove((String) abandonedEvent.getContext().getSessionData(CK.Q_NAME)); + editingQuestNames.remove((String) abandonedEvent.getContext().getSessionData(CK.Q_NAME)); } Player player = (Player) abandonedEvent.getContext().getForWhom(); selectedBlockStarts.remove(player.getUniqueId()); @@ -536,7 +551,7 @@ public class QuestFactory implements ConversationAbandonedListener { return new QuestSelectCreatePrompt(plugin, context); } } - if (names.contains(input)) { + if (editingQuestNames.contains(input)) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited")); return new QuestSelectCreatePrompt(plugin, context); } @@ -549,7 +564,7 @@ public class QuestFactory implements ConversationAbandonedListener { return new QuestSelectCreatePrompt(plugin, context); } context.setSessionData(CK.Q_NAME, input); - names.add(input); + editingQuestNames.add(input); return new QuestMainPrompt(context); } else { return new QuestMenuPrompt(context); @@ -1097,7 +1112,7 @@ public class QuestFactory implements ConversationAbandonedListener { } } } - if (names.contains(input)) { + if (editingQuestNames.contains(input)) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited")); return new QuestSetNamePrompt(); } @@ -1105,9 +1120,9 @@ public class QuestFactory implements ConversationAbandonedListener { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName")); return new QuestSelectCreatePrompt(plugin, context); } - names.remove((String) context.getSessionData(CK.Q_NAME)); + editingQuestNames.remove((String) context.getSessionData(CK.Q_NAME)); context.setSessionData(CK.Q_NAME, input); - names.add(input); + editingQuestNames.add(input); } return new QuestMainPrompt(context); } @@ -1163,7 +1178,7 @@ public class QuestFactory implements ConversationAbandonedListener { @Override public String getPromptText(ConversationContext context) { - selectingNpcs.add((Player) context.getForWhom()); + selectingNpcs.add(((Player) context.getForWhom()).getUniqueId()); return ChatColor.YELLOW + Lang.get("questEditorEnterNPCStart") + "\n" + ChatColor.GOLD + Lang.get("npcHint"); } @@ -1180,7 +1195,7 @@ public class QuestFactory implements ConversationAbandonedListener { return new NPCStartPrompt(); } context.setSessionData(CK.Q_START_NPC, i); - selectingNpcs.remove((Player) context.getForWhom()); + selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); return new QuestMainPrompt(context); } } catch (NumberFormatException e) { @@ -1191,7 +1206,7 @@ public class QuestFactory implements ConversationAbandonedListener { } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { context.setSessionData(CK.Q_START_NPC, null); } - selectingNpcs.remove((Player) context.getForWhom()); + selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); return new QuestMainPrompt(context); } } diff --git a/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java b/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java index 3d6c09e06..4f0072423 100644 --- a/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java +++ b/main/src/main/java/me/blackvein/quests/actions/ActionFactory.java @@ -72,7 +72,7 @@ public class ActionFactory implements ConversationAbandonedListener { private Map selectedMobLocations = new HashMap(); private Map selectedLightningLocations = new HashMap(); private Map selectedTeleportLocations = new HashMap(); - private List names = new LinkedList(); + private List editingActionNames = new LinkedList(); public ActionFactory(Quests plugin) { this.plugin = plugin; @@ -129,6 +129,14 @@ public class ActionFactory implements ConversationAbandonedListener { public ConversationFactory getConversationFactory() { return convoCreator; } + + public List getNamesOfActionsBeingEdited() { + return editingActionNames; + } + + public void setNamesOfActionsBeingEdited(List actionNames) { + this.editingActionNames = actionNames; + } @Override public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { @@ -469,7 +477,7 @@ public class ActionFactory implements ConversationAbandonedListener { return new ActionSelectCreatePrompt(context); } } - if (names.contains(input)) { + if (editingActionNames.contains(input)) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSomeone")); return new ActionSelectCreatePrompt(context); } @@ -482,7 +490,7 @@ public class ActionFactory implements ConversationAbandonedListener { return new ActionSelectCreatePrompt(context); } context.setSessionData(CK.E_NAME, input); - names.add(input); + editingActionNames.add(input); return new ActionMainPrompt(context); } else { return new ActionMenuPrompt(context); @@ -1195,7 +1203,7 @@ public class ActionFactory implements ConversationAbandonedListener { plugin.setActions(temp); } ConfigurationSection section = data.createSection(key + "." + (String) context.getSessionData(CK.E_NAME)); - names.remove((String) context.getSessionData(CK.E_NAME)); + editingActionNames.remove((String) context.getSessionData(CK.E_NAME)); if (context.getSessionData(CK.E_MESSAGE) != null) { section.set("message", getCString(context, CK.E_MESSAGE)); } @@ -1389,7 +1397,7 @@ public class ActionFactory implements ConversationAbandonedListener { return new ActionSetNamePrompt(); } } - if (names.contains(input)) { + if (editingActionNames.contains(input)) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSomeone")); return new ActionSetNamePrompt(); } @@ -1397,9 +1405,9 @@ public class ActionFactory implements ConversationAbandonedListener { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorAlpha")); return new ActionSetNamePrompt(); } - names.remove((String) context.getSessionData(CK.E_NAME)); + editingActionNames.remove((String) context.getSessionData(CK.E_NAME)); context.setSessionData(CK.E_NAME, input); - names.add(input); + editingActionNames.add(input); } return new ActionMainPrompt(context); } diff --git a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/NPCsPrompt.java b/main/src/main/java/me/blackvein/quests/convo/quests/prompts/NPCsPrompt.java index c3bc21432..d80d6517c 100644 --- a/main/src/main/java/me/blackvein/quests/convo/quests/prompts/NPCsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/convo/quests/prompts/NPCsPrompt.java @@ -13,9 +13,10 @@ package me.blackvein.quests.convo.quests.prompts; import java.util.Arrays; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; +import java.util.UUID; import org.bukkit.ChatColor; import org.bukkit.conversations.ConversationContext; @@ -291,8 +292,8 @@ public class NPCsPrompt extends FixedSetPrompt { @Override public String getPromptText(ConversationContext context) { - HashSet temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.add((Player) context.getForWhom()); + Set temp = plugin.getQuestFactory().getSelectingNpcs(); + temp.add(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); return ChatColor.YELLOW + Lang.get("stageEditorNPCPrompt") + "\n" + ChatColor.GOLD + Lang.get("npcHint"); } @@ -320,8 +321,8 @@ public class NPCsPrompt extends FixedSetPrompt { } context.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs); } - HashSet temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.remove((Player) context.getForWhom()); + Set temp = plugin.getQuestFactory().getSelectingNpcs(); + temp.remove(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); return new DeliveryListPrompt(); } @@ -351,8 +352,8 @@ public class NPCsPrompt extends FixedSetPrompt { @Override public String getPromptText(ConversationContext context) { - HashSet temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.add((Player) context.getForWhom()); + Set temp = plugin.getQuestFactory().getSelectingNpcs(); + temp.add(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); return ChatColor.YELLOW + Lang.get("stageEditorNPCToTalkToPrompt") + "\n" + ChatColor.GOLD + Lang.get("npcHint"); @@ -380,8 +381,8 @@ public class NPCsPrompt extends FixedSetPrompt { return new NPCIDsToTalkToPrompt(); } } - HashSet temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.remove((Player) context.getForWhom()); + Set temp = plugin.getQuestFactory().getSelectingNpcs(); + temp.remove(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs); } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { @@ -490,8 +491,8 @@ public class NPCsPrompt extends FixedSetPrompt { @Override public String getPromptText(ConversationContext context) { - HashSet temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.add((Player) context.getForWhom()); + Set temp = plugin.getQuestFactory().getSelectingNpcs(); + temp.add(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); return ChatColor.YELLOW + Lang.get("stageEditorNPCPrompt") + "\n" + ChatColor.GOLD + Lang.get("npcHint"); } @@ -519,8 +520,8 @@ public class NPCsPrompt extends FixedSetPrompt { } context.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs); } - HashSet temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.remove((Player) context.getForWhom()); + Set temp = plugin.getQuestFactory().getSelectingNpcs(); + temp.remove(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); return new NPCKillListPrompt(); } diff --git a/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java b/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java index 672e970b3..a5c48a860 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/NpcListener.java @@ -56,7 +56,7 @@ public class NpcListener implements Listener { @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.LOWEST) public void onNPCRightClick(NPCRightClickEvent evt) { - if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getClicker())) { + if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getClicker().getUniqueId())) { evt.getClicker().sendMessage(ChatColor.GREEN + evt.getNPC().getName() + ": " + ChatColor.DARK_GREEN + "ID " + evt.getNPC().getId()); return; @@ -300,7 +300,7 @@ public class NpcListener implements Listener { @EventHandler public void onNPCLeftClick(NPCLeftClickEvent evt) { - if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getClicker())) { + if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getClicker().getUniqueId())) { evt.getClicker().sendMessage(ChatColor.GREEN + evt.getNPC().getName() + ": " + ChatColor.DARK_GREEN + Lang.get("id") + " " + evt.getNPC().getId()); } diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index 7ad1cfce9..ab0837cc5 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -14,10 +14,10 @@ package me.blackvein.quests.listeners; import java.io.File; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; +import java.util.Set; import java.util.UUID; import org.bukkit.Bukkit; @@ -1005,9 +1005,9 @@ public class PlayerListener implements Listener { if (quester.hasData()) { quester.saveData(); } - if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getPlayer())) { - HashSet temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.remove(evt.getPlayer()); + if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getPlayer().getUniqueId())) { + Set temp = plugin.getQuestFactory().getSelectingNpcs(); + temp.remove(evt.getPlayer().getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(temp); } LinkedList temp = plugin.getQuesters();