Better tracking of quests, actions, and NPCs being selected

This commit is contained in:
PikaMug 2020-03-25 02:20:28 -04:00
parent 13bcb4d9ac
commit fcb1900e57
5 changed files with 66 additions and 42 deletions

View File

@ -20,6 +20,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -71,8 +72,8 @@ public class QuestFactory implements ConversationAbandonedListener {
private Map<UUID, Block> selectedBlockStarts = new HashMap<UUID, Block>(); private Map<UUID, Block> selectedBlockStarts = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedKillLocations = new HashMap<UUID, Block>(); private Map<UUID, Block> selectedKillLocations = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedReachLocations = new HashMap<UUID, Block>(); private Map<UUID, Block> selectedReachLocations = new HashMap<UUID, Block>();
private HashSet<Player> selectingNpcs = new HashSet<Player>(); private Set<UUID> selectingNpcs = new HashSet<UUID>();
private List<String> names = new LinkedList<String>(); private List<String> editingQuestNames = new LinkedList<String>();
public QuestFactory(Quests plugin) { public QuestFactory(Quests plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -106,21 +107,35 @@ public class QuestFactory implements ConversationAbandonedListener {
public void setSelectedReachLocations(Map<UUID, Block> selectedReachLocations) { public void setSelectedReachLocations(Map<UUID, Block> selectedReachLocations) {
this.selectedReachLocations = selectedReachLocations; this.selectedReachLocations = selectedReachLocations;
} }
public HashSet<Player> getSelectingNpcs() { public Set<UUID> getSelectingNpcs() {
return selectingNpcs; return selectingNpcs;
} }
public void setSelectingNpcs(HashSet<Player> selectingNpcs) { public void setSelectingNpcs(Set<UUID> selectingNpcs) {
this.selectingNpcs = selectingNpcs; this.selectingNpcs = selectingNpcs;
} }
/**
* @deprecated Use {@link#getNamesOfQuestsBeingEdited}
*/
public List<String> getNames() { public List<String> getNames() {
return names; return editingQuestNames;
} }
/**
* @deprecated Use {@link#setNamesOfQuestsBeingEdited}
*/
public void setNames(List<String> names) { public void setNames(List<String> names) {
this.names = names; this.editingQuestNames = names;
}
public List<String> getNamesOfQuestsBeingEdited() {
return editingQuestNames;
}
public void setNamesOfQuestsBeingEdited(List<String> questNames) {
this.editingQuestNames = questNames;
} }
public ConversationFactory getConversationFactory() { public ConversationFactory getConversationFactory() {
@ -130,7 +145,7 @@ public class QuestFactory implements ConversationAbandonedListener {
@Override @Override
public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) {
if (abandonedEvent.getContext().getSessionData(CK.Q_NAME) != null) { 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(); Player player = (Player) abandonedEvent.getContext().getForWhom();
selectedBlockStarts.remove(player.getUniqueId()); selectedBlockStarts.remove(player.getUniqueId());
@ -536,7 +551,7 @@ public class QuestFactory implements ConversationAbandonedListener {
return new QuestSelectCreatePrompt(plugin, context); return new QuestSelectCreatePrompt(plugin, context);
} }
} }
if (names.contains(input)) { if (editingQuestNames.contains(input)) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited"));
return new QuestSelectCreatePrompt(plugin, context); return new QuestSelectCreatePrompt(plugin, context);
} }
@ -549,7 +564,7 @@ public class QuestFactory implements ConversationAbandonedListener {
return new QuestSelectCreatePrompt(plugin, context); return new QuestSelectCreatePrompt(plugin, context);
} }
context.setSessionData(CK.Q_NAME, input); context.setSessionData(CK.Q_NAME, input);
names.add(input); editingQuestNames.add(input);
return new QuestMainPrompt(context); return new QuestMainPrompt(context);
} else { } else {
return new QuestMenuPrompt(context); 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")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorBeingEdited"));
return new QuestSetNamePrompt(); return new QuestSetNamePrompt();
} }
@ -1105,9 +1120,9 @@ public class QuestFactory implements ConversationAbandonedListener {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidQuestName"));
return new QuestSelectCreatePrompt(plugin, context); 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); context.setSessionData(CK.Q_NAME, input);
names.add(input); editingQuestNames.add(input);
} }
return new QuestMainPrompt(context); return new QuestMainPrompt(context);
} }
@ -1163,7 +1178,7 @@ public class QuestFactory implements ConversationAbandonedListener {
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
selectingNpcs.add((Player) context.getForWhom()); selectingNpcs.add(((Player) context.getForWhom()).getUniqueId());
return ChatColor.YELLOW + Lang.get("questEditorEnterNPCStart") + "\n" return ChatColor.YELLOW + Lang.get("questEditorEnterNPCStart") + "\n"
+ ChatColor.GOLD + Lang.get("npcHint"); + ChatColor.GOLD + Lang.get("npcHint");
} }
@ -1180,7 +1195,7 @@ public class QuestFactory implements ConversationAbandonedListener {
return new NPCStartPrompt(); return new NPCStartPrompt();
} }
context.setSessionData(CK.Q_START_NPC, i); context.setSessionData(CK.Q_START_NPC, i);
selectingNpcs.remove((Player) context.getForWhom()); selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId());
return new QuestMainPrompt(context); return new QuestMainPrompt(context);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
@ -1191,7 +1206,7 @@ public class QuestFactory implements ConversationAbandonedListener {
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(CK.Q_START_NPC, null); context.setSessionData(CK.Q_START_NPC, null);
} }
selectingNpcs.remove((Player) context.getForWhom()); selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId());
return new QuestMainPrompt(context); return new QuestMainPrompt(context);
} }
} }

View File

@ -72,7 +72,7 @@ public class ActionFactory implements ConversationAbandonedListener {
private Map<UUID, Block> selectedMobLocations = new HashMap<UUID, Block>(); private Map<UUID, Block> selectedMobLocations = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedLightningLocations = new HashMap<UUID, Block>(); private Map<UUID, Block> selectedLightningLocations = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedTeleportLocations = new HashMap<UUID, Block>(); private Map<UUID, Block> selectedTeleportLocations = new HashMap<UUID, Block>();
private List<String> names = new LinkedList<String>(); private List<String> editingActionNames = new LinkedList<String>();
public ActionFactory(Quests plugin) { public ActionFactory(Quests plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -129,6 +129,14 @@ public class ActionFactory implements ConversationAbandonedListener {
public ConversationFactory getConversationFactory() { public ConversationFactory getConversationFactory() {
return convoCreator; return convoCreator;
} }
public List<String> getNamesOfActionsBeingEdited() {
return editingActionNames;
}
public void setNamesOfActionsBeingEdited(List<String> actionNames) {
this.editingActionNames = actionNames;
}
@Override @Override
public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) { public void conversationAbandoned(ConversationAbandonedEvent abandonedEvent) {
@ -469,7 +477,7 @@ public class ActionFactory implements ConversationAbandonedListener {
return new ActionSelectCreatePrompt(context); return new ActionSelectCreatePrompt(context);
} }
} }
if (names.contains(input)) { if (editingActionNames.contains(input)) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSomeone")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSomeone"));
return new ActionSelectCreatePrompt(context); return new ActionSelectCreatePrompt(context);
} }
@ -482,7 +490,7 @@ public class ActionFactory implements ConversationAbandonedListener {
return new ActionSelectCreatePrompt(context); return new ActionSelectCreatePrompt(context);
} }
context.setSessionData(CK.E_NAME, input); context.setSessionData(CK.E_NAME, input);
names.add(input); editingActionNames.add(input);
return new ActionMainPrompt(context); return new ActionMainPrompt(context);
} else { } else {
return new ActionMenuPrompt(context); return new ActionMenuPrompt(context);
@ -1195,7 +1203,7 @@ public class ActionFactory implements ConversationAbandonedListener {
plugin.setActions(temp); plugin.setActions(temp);
} }
ConfigurationSection section = data.createSection(key + "." + (String) context.getSessionData(CK.E_NAME)); 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) { if (context.getSessionData(CK.E_MESSAGE) != null) {
section.set("message", getCString(context, CK.E_MESSAGE)); section.set("message", getCString(context, CK.E_MESSAGE));
} }
@ -1389,7 +1397,7 @@ public class ActionFactory implements ConversationAbandonedListener {
return new ActionSetNamePrompt(); return new ActionSetNamePrompt();
} }
} }
if (names.contains(input)) { if (editingActionNames.contains(input)) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSomeone")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorSomeone"));
return new ActionSetNamePrompt(); return new ActionSetNamePrompt();
} }
@ -1397,9 +1405,9 @@ public class ActionFactory implements ConversationAbandonedListener {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorAlpha")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorAlpha"));
return new ActionSetNamePrompt(); 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); context.setSessionData(CK.E_NAME, input);
names.add(input); editingActionNames.add(input);
} }
return new ActionMainPrompt(context); return new ActionMainPrompt(context);
} }

View File

@ -13,9 +13,10 @@
package me.blackvein.quests.convo.quests.prompts; package me.blackvein.quests.convo.quests.prompts;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.ConversationContext;
@ -291,8 +292,8 @@ public class NPCsPrompt extends FixedSetPrompt {
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
HashSet<Player> temp = plugin.getQuestFactory().getSelectingNpcs(); Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.add((Player) context.getForWhom()); temp.add(((Player) context.getForWhom()).getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp); plugin.getQuestFactory().setSelectingNpcs(temp);
return ChatColor.YELLOW + Lang.get("stageEditorNPCPrompt") + "\n" + ChatColor.GOLD + Lang.get("npcHint"); 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); context.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs);
} }
HashSet<Player> temp = plugin.getQuestFactory().getSelectingNpcs(); Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.remove((Player) context.getForWhom()); temp.remove(((Player) context.getForWhom()).getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp); plugin.getQuestFactory().setSelectingNpcs(temp);
return new DeliveryListPrompt(); return new DeliveryListPrompt();
} }
@ -351,8 +352,8 @@ public class NPCsPrompt extends FixedSetPrompt {
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
HashSet<Player> temp = plugin.getQuestFactory().getSelectingNpcs(); Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.add((Player) context.getForWhom()); temp.add(((Player) context.getForWhom()).getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp); plugin.getQuestFactory().setSelectingNpcs(temp);
return ChatColor.YELLOW + Lang.get("stageEditorNPCToTalkToPrompt") + "\n" + ChatColor.GOLD return ChatColor.YELLOW + Lang.get("stageEditorNPCToTalkToPrompt") + "\n" + ChatColor.GOLD
+ Lang.get("npcHint"); + Lang.get("npcHint");
@ -380,8 +381,8 @@ public class NPCsPrompt extends FixedSetPrompt {
return new NPCIDsToTalkToPrompt(); return new NPCIDsToTalkToPrompt();
} }
} }
HashSet<Player> temp = plugin.getQuestFactory().getSelectingNpcs(); Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.remove((Player) context.getForWhom()); temp.remove(((Player) context.getForWhom()).getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp); plugin.getQuestFactory().setSelectingNpcs(temp);
context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs); context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs);
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
@ -490,8 +491,8 @@ public class NPCsPrompt extends FixedSetPrompt {
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
HashSet<Player> temp = plugin.getQuestFactory().getSelectingNpcs(); Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.add((Player) context.getForWhom()); temp.add(((Player) context.getForWhom()).getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp); plugin.getQuestFactory().setSelectingNpcs(temp);
return ChatColor.YELLOW + Lang.get("stageEditorNPCPrompt") + "\n" + ChatColor.GOLD + Lang.get("npcHint"); 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); context.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs);
} }
HashSet<Player> temp = plugin.getQuestFactory().getSelectingNpcs(); Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.remove((Player) context.getForWhom()); temp.remove(((Player) context.getForWhom()).getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp); plugin.getQuestFactory().setSelectingNpcs(temp);
return new NPCKillListPrompt(); return new NPCKillListPrompt();
} }

View File

@ -56,7 +56,7 @@ public class NpcListener implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onNPCRightClick(NPCRightClickEvent evt) { 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.getClicker().sendMessage(ChatColor.GREEN + evt.getNPC().getName() + ": " + ChatColor.DARK_GREEN + "ID "
+ evt.getNPC().getId()); + evt.getNPC().getId());
return; return;
@ -300,7 +300,7 @@ public class NpcListener implements Listener {
@EventHandler @EventHandler
public void onNPCLeftClick(NPCLeftClickEvent evt) { 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 evt.getClicker().sendMessage(ChatColor.GREEN + evt.getNPC().getName() + ": " + ChatColor.DARK_GREEN
+ Lang.get("id") + " " + evt.getNPC().getId()); + Lang.get("id") + " " + evt.getNPC().getId());
} }

View File

@ -14,10 +14,10 @@
package me.blackvein.quests.listeners; package me.blackvein.quests.listeners;
import java.io.File; import java.io.File;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -1005,9 +1005,9 @@ public class PlayerListener implements Listener {
if (quester.hasData()) { if (quester.hasData()) {
quester.saveData(); quester.saveData();
} }
if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getPlayer())) { if (plugin.getQuestFactory().getSelectingNpcs().contains(evt.getPlayer().getUniqueId())) {
HashSet<Player> temp = plugin.getQuestFactory().getSelectingNpcs(); Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.remove(evt.getPlayer()); temp.remove(evt.getPlayer().getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp); plugin.getQuestFactory().setSelectingNpcs(temp);
} }
LinkedList<Quester> temp = plugin.getQuesters(); LinkedList<Quester> temp = plugin.getQuesters();