From c593c210a37f0657640abade3ce3968822022d5d Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Sun, 17 Apr 2022 19:28:23 -0400 Subject: [PATCH] Track NPCs by UUID instead. Bump version --- api/pom.xml | 2 +- .../java/me/blackvein/quests/QuestData.java | 20 +- .../quests/dependencies/IDependencies.java | 2 + .../me/blackvein/quests/quests/IStage.java | 25 +- core/pom.xml | 2 +- .../me/blackvein/quests/Dependencies.java | 16 +- .../main/java/me/blackvein/quests/Quest.java | 10 +- .../java/me/blackvein/quests/Quester.java | 82 +- .../main/java/me/blackvein/quests/Quests.java | 277 ++++--- .../main/java/me/blackvein/quests/Stage.java | 91 ++- .../convo/conditions/tasks/EntityPrompt.java | 2 +- .../convo/quests/main/QuestMainPrompt.java | 59 +- .../convo/quests/objectives/BlocksPrompt.java | 48 +- .../convo/quests/objectives/NpcsPrompt.java | 245 +++--- .../quests/listeners/NpcListener.java | 34 +- .../quests/quests/BukkitQuestFactory.java | 725 +++++++++--------- .../file/SeparatedYamlStorage.java | 22 +- .../implementation/sql/SqlStorage.java | 8 +- core/src/main/resources/strings.yml | 18 +- dist/pom.xml | 2 +- pom.xml | 4 +- v1_8_R1/pom.xml | 2 +- v1_8_R2/pom.xml | 2 +- v1_8_R3/pom.xml | 2 +- 24 files changed, 950 insertions(+), 750 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 83b56d1c3..daaa24f78 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 4.3.1 + 4.4.0 quests-api diff --git a/api/src/main/java/me/blackvein/quests/QuestData.java b/api/src/main/java/me/blackvein/quests/QuestData.java index 5a4b5463f..2c0972158 100644 --- a/api/src/main/java/me/blackvein/quests/QuestData.java +++ b/api/src/main/java/me/blackvein/quests/QuestData.java @@ -513,7 +513,7 @@ public class QuestData { } }; - public LinkedList citizensInteracted = new LinkedList() { + public LinkedList npcsInteracted = new LinkedList() { private static final long serialVersionUID = 2447610341508300847L; @@ -580,7 +580,7 @@ public class QuestData { } }; - public LinkedList citizensNumKilled = new LinkedList() { + public LinkedList npcsNumKilled = new LinkedList() { private static final long serialVersionUID = 1849192351499071688L; @@ -1180,23 +1180,23 @@ public class QuestData { } } - public LinkedList getCitizensInteracted() { - return citizensInteracted; + public LinkedList getNpcsInteracted() { + return npcsInteracted; } - public void setCitizensInteracted(final LinkedList citizensInteracted) { - this.citizensInteracted = citizensInteracted; + public void setNpcsInteracted(final LinkedList npcsInteracted) { + this.npcsInteracted = npcsInteracted; if (doJournalUpdate) { quester.updateJournal(); } } - public LinkedList getCitizensNumKilled() { - return citizensNumKilled; + public LinkedList getNpcsNumKilled() { + return npcsNumKilled; } - public void setCitizensNumKilled(final LinkedList citizensNumKilled) { - this.citizensNumKilled = citizensNumKilled; + public void setNpcsNumKilled(final LinkedList npcsNumKilled) { + this.npcsNumKilled = npcsNumKilled; if (doJournalUpdate) { quester.updateJournal(); } diff --git a/api/src/main/java/me/blackvein/quests/dependencies/IDependencies.java b/api/src/main/java/me/blackvein/quests/dependencies/IDependencies.java index 61f2d7794..387aa6686 100644 --- a/api/src/main/java/me/blackvein/quests/dependencies/IDependencies.java +++ b/api/src/main/java/me/blackvein/quests/dependencies/IDependencies.java @@ -71,6 +71,8 @@ public interface IDependencies { String getNPCName(final int id); + String getNPCName(final UUID uuid); + int getMcmmoSkillLevel(final SkillType st, final String player); Hero getHero(final UUID uuid); diff --git a/api/src/main/java/me/blackvein/quests/quests/IStage.java b/api/src/main/java/me/blackvein/quests/quests/IStage.java index 6718665f1..f17e858a9 100644 --- a/api/src/main/java/me/blackvein/quests/quests/IStage.java +++ b/api/src/main/java/me/blackvein/quests/quests/IStage.java @@ -24,6 +24,7 @@ import org.bukkit.inventory.ItemStack; import java.util.LinkedList; import java.util.Map; +import java.util.UUID; public interface IStage { LinkedList getBlocksToBreak(); @@ -92,11 +93,11 @@ public interface IStage { void setItemsToDeliver(final LinkedList itemsToDeliver); - LinkedList getItemDeliveryTargets(); + LinkedList getItemDeliveryTargets(); - boolean addItemDeliveryTarget(Integer itemDeliveryTarget); + boolean addItemDeliveryTarget(UUID itemDeliveryTarget); - void setItemDeliveryTargets(final LinkedList itemDeliveryTargets); + void setItemDeliveryTargets(final LinkedList itemDeliveryTargets); LinkedList getDeliverMessages(); @@ -104,23 +105,23 @@ public interface IStage { void setDeliverMessages(final LinkedList deliverMessages); - LinkedList getCitizensToInteract(); + LinkedList getNpcsToInteract(); - boolean addCitizenToInteract(Integer citizenToInteract); + boolean addNpcToInteract(UUID npcToInteract); - void setCitizensToInteract(final LinkedList citizensToInteract); + void setNpcsToInteract(final LinkedList npcsToInteract); - LinkedList getCitizensToKill(); + LinkedList getNpcsToKill(); - boolean addCitizenToKill(Integer citizenToKill); + boolean addNpcToKill(UUID citizenToKill); - void setCitizensToKill(final LinkedList citizensToKill); + void setNpcsToKill(final LinkedList npcsToKill); - LinkedList getCitizenNumToKill(); + LinkedList getNpcNumToKill(); - boolean addCitizenNumToKill(Integer citizenNumToKill); + boolean addNpcNumToKill(Integer npcNumToKill); - void setCitizenNumToKill(final LinkedList citizenNumToKill); + void setNpcNumToKill(final LinkedList npcNumToKill); LinkedList getMobsToKill(); diff --git a/core/pom.xml b/core/pom.xml index f0ef32937..768c6c3e3 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 4.3.1 + 4.4.0 quests-core diff --git a/core/src/main/java/me/blackvein/quests/Dependencies.java b/core/src/main/java/me/blackvein/quests/Dependencies.java index 912b437a9..be08062f9 100644 --- a/core/src/main/java/me/blackvein/quests/Dependencies.java +++ b/core/src/main/java/me/blackvein/quests/Dependencies.java @@ -271,14 +271,28 @@ public class Dependencies implements IDependencies { public boolean runDenizenScript(final String scriptName, final IQuester quester) { return plugin.getDenizenTrigger().runDenizenScript(scriptName, quester); } - + + /** + * @deprecated Use {@link #getNPCLocation(UUID)} + */ public Location getNPCLocation(final int id) { return citizens.getNPCRegistry().getById(id).getStoredLocation(); } + public Location getNPCLocation(final UUID uuid) { + return citizens.getNPCRegistry().getByUniqueId(uuid).getStoredLocation(); + } + + /** + * @deprecated Use {@link #getNPCName(UUID)} + */ public String getNPCName(final int id) { return citizens.getNPCRegistry().getById(id).getName(); } + + public String getNPCName(final UUID uuid) { + return citizens.getNPCRegistry().getByUniqueId(uuid).getName(); + } public int getMcmmoSkillLevel(final SkillType st, final String player) { final McMMOPlayer mPlayer = UserManager.getPlayer(player); diff --git a/core/src/main/java/me/blackvein/quests/Quest.java b/core/src/main/java/me/blackvein/quests/Quest.java index 692771188..8c4a96405 100644 --- a/core/src/main/java/me/blackvein/quests/Quest.java +++ b/core/src/main/java/me/blackvein/quests/Quest.java @@ -449,14 +449,14 @@ public class Quest implements IQuest { final IQuest quest = this; Bukkit.getScheduler().runTask(plugin, () -> { Location targetLocation = null; - if (stage.getCitizensToInteract() != null && stage.getCitizensToInteract().size() > 0) { - targetLocation = plugin.getDependencies().getNPCLocation(stage.getCitizensToInteract().getFirst()); - } else if (stage.getCitizensToKill() != null && stage.getCitizensToKill().size() > 0) { - targetLocation = plugin.getDependencies().getNPCLocation(stage.getCitizensToKill().getFirst()); + if (stage.getNpcsToInteract() != null && stage.getNpcsToInteract().size() > 0) { + targetLocation = plugin.getDependencies().getNPCLocation(stage.getNpcsToInteract().getFirst()); + } else if (stage.getNpcsToKill() != null && stage.getNpcsToKill().size() > 0) { + targetLocation = plugin.getDependencies().getNPCLocation(stage.getNpcsToKill().getFirst()); } else if (stage.getLocationsToReach() != null && stage.getLocationsToReach().size() > 0) { targetLocation = stage.getLocationsToReach().getFirst(); } else if (stage.getItemDeliveryTargets() != null && stage.getItemDeliveryTargets().size() > 0) { - final NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getById(stage + final NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getByUniqueId(stage .getItemDeliveryTargets().getFirst()); targetLocation = npc.getStoredLocation(); } else if (stage.getPlayersToKill() != null && stage.getPlayersToKill() > 0) { diff --git a/core/src/main/java/me/blackvein/quests/Quester.java b/core/src/main/java/me/blackvein/quests/Quester.java index 8696b0303..e6ae22c5d 100644 --- a/core/src/main/java/me/blackvein/quests/Quester.java +++ b/core/src/main/java/me/blackvein/quests/Quester.java @@ -1341,7 +1341,7 @@ public class Quester implements IQuester { delivered = data.itemsDelivered.get(deliverIndex).getAmount(); } final int toDeliver = is.getAmount(); - final Integer npc = stage.getItemDeliveryTargets().get(deliverIndex); + final UUID npc = stage.getItemDeliveryTargets().get(deliverIndex); final ChatColor color = delivered < toDeliver ? ChatColor.GREEN : ChatColor.GRAY; String message = color + Lang.get(getPlayer(), "deliver").replace("", depends.getNPCName(npc)); if (message.contains("")) { @@ -1357,10 +1357,10 @@ public class Quester implements IQuester { deliverIndex++; } int interactIndex = 0; - for (final Integer n : stage.getCitizensToInteract()) { + for (final UUID n : stage.getNpcsToInteract()) { boolean interacted = false; - if (data.citizensInteracted.size() > interactIndex) { - interacted = data.citizensInteracted.get(interactIndex); + if (data.npcsInteracted.size() > interactIndex) { + interacted = data.npcsInteracted.get(interactIndex); } final ChatColor color = !interacted ? ChatColor.GREEN : ChatColor.GRAY; String message = color + Lang.get(getPlayer(), "talkTo") @@ -1372,12 +1372,12 @@ public class Quester implements IQuester { interactIndex++; } int npcKillIndex = 0; - for (final Integer n : stage.getCitizensToKill()) { + for (final UUID n : stage.getNpcsToKill()) { int npcKilled = 0; - if (data.citizensNumKilled.size() > npcKillIndex) { - npcKilled = data.citizensNumKilled.get(npcKillIndex); + if (data.npcsNumKilled.size() > npcKillIndex) { + npcKilled = data.npcsNumKilled.get(npcKillIndex); } - final int toNpcKill = stage.getCitizenNumToKill().get(npcKillIndex); + final int toNpcKill = stage.getNpcNumToKill().get(npcKillIndex); final ChatColor color = npcKilled < toNpcKill ? ChatColor.GREEN : ChatColor.GRAY; String message = color + Lang.get(getPlayer(), "kill"); if (message.contains("")) { @@ -1850,7 +1850,7 @@ public class Quester implements IQuester { final ItemStack progress = data.itemsDelivered.get(deliverIndex); final int delivered = progress.getAmount(); final int toDeliver = goal.getAmount(); - final Integer npc = stage.getItemDeliveryTargets().get(deliverIndex); + final UUID npc = stage.getItemDeliveryTargets().get(deliverIndex); final ChatColor color = delivered < toDeliver ? ChatColor.GREEN : ChatColor.GRAY; String message = color + Lang.get(getPlayer(), "deliver").replace("", depends.getNPCName(npc)); if (message.contains("")) { @@ -1870,10 +1870,10 @@ public class Quester implements IQuester { deliverIndex++; } int interactIndex = 0; - for (final Integer n : stage.getCitizensToInteract()) { + for (final UUID n : stage.getNpcsToInteract()) { boolean interacted = false; - if (data.citizensInteracted.size() > interactIndex) { - interacted = data.citizensInteracted.get(interactIndex); + if (data.npcsInteracted.size() > interactIndex) { + interacted = data.npcsInteracted.get(interactIndex); final ChatColor color = !interacted ? ChatColor.GREEN : ChatColor.GRAY; String message = color + Lang.get(getPlayer(), "talkTo") .replace("", depends.getNPCName(n)); @@ -1885,12 +1885,12 @@ public class Quester implements IQuester { interactIndex++; } int npcKillIndex = 0; - for (final Integer n : stage.getCitizensToKill()) { + for (final UUID n : stage.getNpcsToKill()) { int npcKilled = 0; - if (data.citizensNumKilled.size() > npcKillIndex) { - npcKilled = data.citizensNumKilled.get(npcKillIndex); + if (data.npcsNumKilled.size() > npcKillIndex) { + npcKilled = data.npcsNumKilled.get(npcKillIndex); } - final int toNpcKill = stage.getCitizenNumToKill().get(npcKillIndex); + final int toNpcKill = stage.getNpcNumToKill().get(npcKillIndex); final ChatColor color = npcKilled < toNpcKill ? ChatColor.GREEN : ChatColor.GRAY; String message = color + Lang.get(getPlayer(), "kill"); if (message.contains("")) { @@ -2967,7 +2967,7 @@ public class Quester implements IQuester { if (npc == null) { return; } - + int currentIndex = -1; final LinkedList matches = new LinkedList<>(); for (final ItemStack is : getQuestData(quest).itemsDelivered) { @@ -2982,7 +2982,7 @@ public class Quester implements IQuester { final Player player = getPlayer(); for (final Integer match : matches) { final LinkedList items = new LinkedList<>(getQuestData(quest).itemsDelivered); - if (!getCurrentStage(quest).getItemDeliveryTargets().get(match).equals(npc.getId())) { + if (!getCurrentStage(quest).getItemDeliveryTargets().get(match).equals(npc.getUniqueId())) { continue; } final ItemStack found = items.get(match); @@ -3025,7 +3025,7 @@ public class Quester implements IQuester { final String[] message = ConfigUtil.parseStringWithPossibleLineBreaks(getCurrentStage(quest) .getDeliverMessages().get(new Random().nextInt(getCurrentStage(quest).getDeliverMessages() .size())), plugin.getDependencies().getCitizens().getNPCRegistry() - .getById(getCurrentStage(quest).getItemDeliveryTargets().get(items.indexOf(found)))); + .getByUniqueId(getCurrentStage(quest).getItemDeliveryTargets().get(items.indexOf(found)))); player.sendMessage(message); } @@ -3054,12 +3054,12 @@ public class Quester implements IQuester { * @param npc The NPC being interacted with */ public void interactWithNPC(final IQuest quest, final NPC npc) { - if (!getCurrentStage(quest).getCitizensToInteract().contains(npc.getId())) { + if (!getCurrentStage(quest).getNpcsToInteract().contains(npc.getUniqueId())) { return; } - final int index = getCurrentStage(quest).getCitizensToInteract().indexOf(npc.getId()); - final boolean npcsInteracted = getQuestData(quest).citizensInteracted.get(index); + final int index = getCurrentStage(quest).getNpcsToInteract().indexOf(npc.getUniqueId()); + final boolean npcsInteracted = getQuestData(quest).npcsInteracted.get(index); final ObjectiveType type = ObjectiveType.TALK_TO_NPC; final Set dispatchedQuestIDs = new HashSet<>(); @@ -3068,14 +3068,14 @@ public class Quester implements IQuester { plugin.getServer().getPluginManager().callEvent(preEvent); if (!npcsInteracted) { - getQuestData(quest).citizensInteracted.set(index, true); + getQuestData(quest).npcsInteracted.set(index, true); finishObjective(quest, new BukkitObjective(type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1)), null, null, npc, null, null, null, null); dispatchedQuestIDs.addAll(dispatchMultiplayerEverything(quest, type, (final IQuester q, final IQuest cq) -> { if (!dispatchedQuestIDs.contains(cq.getId())) { - q.getQuestData(quest).citizensInteracted.set(index, true); + q.getQuestData(quest).npcsInteracted.set(index, true); if (q.testComplete(quest)) { quest.nextStage(q, false); } @@ -3096,13 +3096,13 @@ public class Quester implements IQuester { * @param npc The NPC being killed */ public void killNPC(final IQuest quest, final NPC npc) { - if (!getCurrentStage(quest).getCitizensToKill().contains(npc.getId())) { + if (!getCurrentStage(quest).getNpcsToKill().contains(npc.getUniqueId())) { return; } - final int index = getCurrentStage(quest).getCitizensToKill().indexOf(npc.getId()); - final int npcsKilled = getQuestData(quest).citizensNumKilled.get(index); - final int npcsToKill = getCurrentStage(quest).getCitizenNumToKill().get(index); + final int index = getCurrentStage(quest).getNpcsToKill().indexOf(npc.getUniqueId()); + final int npcsKilled = getQuestData(quest).npcsNumKilled.get(index); + final int npcsToKill = getCurrentStage(quest).getNpcNumToKill().get(index); final ObjectiveType type = ObjectiveType.KILL_NPC; final Set dispatchedQuestIDs = new HashSet<>(); @@ -3110,9 +3110,9 @@ public class Quester implements IQuester { new BukkitObjective(type, npcsKilled, npcsToKill)); plugin.getServer().getPluginManager().callEvent(preEvent); - final int newNpcsKilled = getQuestData(quest).citizensNumKilled.get(index) + 1; + final int newNpcsKilled = getQuestData(quest).npcsNumKilled.get(index) + 1; if (npcsKilled < npcsToKill) { - getQuestData(quest).citizensNumKilled.set(index, newNpcsKilled); + getQuestData(quest).npcsNumKilled.set(index, newNpcsKilled); if (newNpcsKilled >= npcsToKill) { finishObjective(quest, new BukkitObjective(type, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, npcsToKill)), null, null, npc, null, null, null, null); @@ -3121,7 +3121,7 @@ public class Quester implements IQuester { dispatchedQuestIDs.addAll(dispatchMultiplayerEverything(quest, type, (final IQuester q, final IQuest cq) -> { if (!dispatchedQuestIDs.contains(cq.getId())) { - q.getQuestData(quest).citizensNumKilled.set(index, newNpcsKilled); + q.getQuestData(quest).npcsNumKilled.set(index, newNpcsKilled); if (q.testComplete(quest)) { quest.nextStage(q, false); } @@ -4183,14 +4183,14 @@ public class Quester implements IQuester { data.itemsDelivered.add(temp); } } - if (!quest.getStage(stage).getCitizensToInteract().isEmpty()) { - for (final Integer ignored : quest.getStage(stage).getCitizensToInteract()) { - data.citizensInteracted.add(false); + if (!quest.getStage(stage).getNpcsToInteract().isEmpty()) { + for (final UUID ignored : quest.getStage(stage).getNpcsToInteract()) { + data.npcsInteracted.add(false); } } - if (!quest.getStage(stage).getCitizensToKill().isEmpty()) { - for (final Integer ignored : quest.getStage(stage).getCitizensToKill()) { - data.citizensNumKilled.add(0); + if (!quest.getStage(stage).getNpcsToKill().isEmpty()) { + for (final UUID ignored : quest.getStage(stage).getNpcsToKill()) { + data.npcsNumKilled.add(0); } } if (!quest.getStage(stage).getMobsToKill().isEmpty()) { @@ -4374,11 +4374,11 @@ public class Quester implements IQuester { } questSec.set("item-delivery-amounts", deliveryAmounts); } - if (!questData.citizensInteracted.isEmpty()) { - questSec.set("has-talked-to", questData.citizensInteracted); + if (!questData.npcsInteracted.isEmpty()) { + questSec.set("has-talked-to", questData.npcsInteracted); } - if (!questData.citizensNumKilled.isEmpty()) { - questSec.set("citizen-amounts-killed", questData.citizensNumKilled); + if (!questData.npcsNumKilled.isEmpty()) { + questSec.set("npc-killed-amounts", questData.npcsNumKilled); } if (!questData.mobNumKilled.isEmpty()) { questSec.set("mobs-killed-amounts", questData.mobNumKilled); diff --git a/core/src/main/java/me/blackvein/quests/Quests.java b/core/src/main/java/me/blackvein/quests/Quests.java index c8420a6c2..266f1166d 100644 --- a/core/src/main/java/me/blackvein/quests/Quests.java +++ b/core/src/main/java/me/blackvein/quests/Quests.java @@ -151,6 +151,7 @@ public class Quests extends JavaPlugin implements QuestsAPI { private final Collection quests = new ConcurrentSkipListSet<>(); private Collection actions = new ConcurrentSkipListSet<>(); private Collection conditions = new ConcurrentSkipListSet<>(); + private LinkedList questNpcUuids = new LinkedList<>(); private LinkedList questNpcIds = new LinkedList<>(); private TabExecutor cmdExecutor; private ConversationFactory conversationFactory; @@ -535,10 +536,24 @@ public class Quests extends JavaPlugin implements QuestsAPI { this.questers = new ConcurrentSkipListSet<>(questers); } + public LinkedList getQuestNpcUuids() { + return questNpcUuids; + } + + public void setQuestNpcUuids(final LinkedList questNpcUuids) { + this.questNpcUuids = questNpcUuids; + } + + /** + * @deprecated Use {@link #getQuestNpcUuids()} + */ public LinkedList getQuestNpcIds() { return questNpcIds; } + /** + * @deprecated Use {@link #setQuestNpcUuids(LinkedList)} + */ public void setQuestNpcIds(final LinkedList questNpcIds) { this.questNpcIds = questNpcIds; } @@ -1366,7 +1381,7 @@ public class Quests extends JavaPlugin implements QuestsAPI { delivered = data.itemsDelivered.get(deliverIndex).getAmount(); } final int toDeliver = is.getAmount(); - final Integer npc = stage.getItemDeliveryTargets().get(deliverIndex); + final UUID npc = stage.getItemDeliveryTargets().get(deliverIndex); final ChatColor color = delivered < toDeliver ? ChatColor.GREEN : ChatColor.GRAY; String message = color + "- " + Lang.get(quester.getPlayer(), "deliver").replace("", depends.getNPCName(npc)); if (message.contains("")) { @@ -1387,14 +1402,14 @@ public class Quests extends JavaPlugin implements QuestsAPI { deliverIndex++; } int interactIndex = 0; - for (final Integer n : stage.getCitizensToInteract()) { + for (final UUID uuid : stage.getNpcsToInteract()) { boolean interacted = false; - if (data.citizensInteracted.size() > interactIndex) { - interacted = data.citizensInteracted.get(interactIndex); + if (data.npcsInteracted.size() > interactIndex) { + interacted = data.npcsInteracted.get(interactIndex); } final ChatColor color = !interacted ? ChatColor.GREEN : ChatColor.GRAY; String message = color + "- " + Lang.get(quester.getPlayer(), "talkTo") - .replace("", depends.getNPCName(n)); + .replace("", depends.getNPCName(uuid)); if (depends.getPlaceholderApi() != null) { message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); } @@ -1402,18 +1417,18 @@ public class Quests extends JavaPlugin implements QuestsAPI { interactIndex++; } int npcKillIndex = 0; - for (final Integer n : stage.getCitizensToKill()) { + for (final UUID uuid : stage.getNpcsToKill()) { int npcKilled = 0; - if (data.citizensNumKilled.size() > npcKillIndex) { - npcKilled = data.citizensNumKilled.get(npcKillIndex); + if (data.npcsNumKilled.size() > npcKillIndex) { + npcKilled = data.npcsNumKilled.get(npcKillIndex); } - final int toNpcKill = stage.getCitizenNumToKill().get(npcKillIndex); + final int toNpcKill = stage.getNpcNumToKill().get(npcKillIndex); final ChatColor color = npcKilled < toNpcKill ? ChatColor.GREEN : ChatColor.GRAY; String message = color + "- " + Lang.get(quester.getPlayer(), "kill"); if (message.contains("")) { - message = message.replace("", depends.getNPCName(n)); + message = message.replace("", depends.getNPCName(uuid)); } else { - message += " " + depends.getNPCName(n); + message += " " + depends.getNPCName(uuid); } if (message.contains("")) { message = message.replace("", "" + color + npcKilled + "/" + toNpcKill); @@ -1830,11 +1845,23 @@ public class Quests extends JavaPlugin implements QuestsAPI { } else { throw new QuestFormatException("finish-message is missing", questKey); } - if (depends.getCitizens() != null && config.contains("quests." + questKey + ".npc-giver-id")) { + if (config.contains("quests." + questKey + ".npc-giver-uuid")) { + final UUID uuid = UUID.fromString(Objects.requireNonNull(config.getString("quests." + questKey + + ".npc-giver-uuid"))); + if (CitizensAPI.getNPCRegistry().getByUniqueId(uuid) != null) { + quest.setNpcStart(CitizensAPI.getNPCRegistry().getByUniqueId(uuid)); + questNpcUuids.add(uuid); + } else { + throw new QuestFormatException("npc-giver-uuid has invalid NPC UUID " + uuid, questKey); + } + } else if (depends.getCitizens() != null && config.contains("quests." + questKey + ".npc-giver-id")) { + // Legacy final int npcId = config.getInt("quests." + questKey + ".npc-giver-id"); if (CitizensAPI.getNPCRegistry().getById(npcId) != null) { - quest.setNpcStart(CitizensAPI.getNPCRegistry().getById(npcId)); + final NPC npc = CitizensAPI.getNPCRegistry().getById(npcId); + quest.setNpcStart(npc); questNpcIds.add(npcId); + questNpcUuids.add(npc.getUniqueId()); } else { throw new QuestFormatException("npc-giver-id has invalid NPC ID " + npcId, questKey); } @@ -2435,10 +2462,13 @@ public class Quests extends JavaPlugin implements QuestsAPI { final List itemsToEnchant; final List itemsToBrew; final List itemsToConsume; + final List npcUuidsToTalkTo; final List npcIdsToTalkTo; final List itemsToDeliver; + final List itemDeliveryTargetUuids; final List itemDeliveryTargetIds; final List deliveryMessages; + final List npcUuidsToKill; final List npcIdsToKill; final List npcAmountsToKill; // Legacy Denizen script load @@ -2896,15 +2926,45 @@ public class Quests extends JavaPlugin implements QuestsAPI { throw new StageFormatException("players-to-kill is not a number", quest, stageNum); } } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-talk-to")) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-uuids-to-talk-to")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-uuids-to-talk-to"), String.class)) { + npcUuidsToTalkTo = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-uuids-to-talk-to"); + for (final String s : npcUuidsToTalkTo) { + final UUID uuid = UUID.fromString(s); + if (getDependencies().getCitizens() != null) { + NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(uuid); + if (npc != null) { + oStage.addNpcToInteract(uuid); + questNpcIds.add(npc.getId()); + questNpcUuids.add(uuid); + } else { + throw new StageFormatException("npc-uuids-to-talk-to has invalid NPC UUID of " + + s, quest, stageNum); + } + } else { + throw new StageFormatException("Citizens not found for npc-uuids-to-talk-to", quest, + stageNum); + } + } + } else { + throw new StageFormatException("npc-ids-to-talk-to is not a list of numbers", quest, stageNum); + } + } else if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-talk-to")) { + // Legacy if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-talk-to"), Integer.class)) { npcIdsToTalkTo = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-talk-to"); for (final int i : npcIdsToTalkTo) { if (getDependencies().getCitizens() != null) { - if (CitizensAPI.getNPCRegistry().getById(i) != null) { - questNpcIds.add(i); + final NPC npc = CitizensAPI.getNPCRegistry().getById(i); + if (npc != null) { + final UUID npcUuid = npc.getUniqueId(); + oStage.addNpcToInteract(npcUuid); + questNpcIds.add(npc.getId()); + questNpcUuids.add(npcUuid); } else { throw new StageFormatException("npc-ids-to-talk-to has invalid NPC ID of " + i, quest, stageNum); @@ -2914,37 +2974,82 @@ public class Quests extends JavaPlugin implements QuestsAPI { stageNum); } } - oStage.setCitizensToInteract(new LinkedList<>(npcIdsToTalkTo)); } else { throw new StageFormatException("npc-ids-to-talk-to is not a list of numbers", quest, stageNum); } } if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-deliver")) { - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-delivery-ids")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-delivery-ids"), Integer.class)) { - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-delivery-uuids")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-delivery-uuids"), String.class)) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".delivery-messages")) { - itemsToDeliver = (List) config.get("quests." + questKey + ".stages.ordered." + itemsToDeliver = (List) config.get("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-deliver"); - itemDeliveryTargetIds = config.getIntegerList("quests." + questKey + ".stages.ordered." + itemDeliveryTargetUuids = config.getStringList("quests." + questKey + ".stages.ordered." + + stageNum + ".npc-delivery-uuids"); + deliveryMessages = config.getStringList("quests." + questKey + ".stages.ordered." + + stageNum + ".delivery-messages"); + int index = 0; + if (ConfigUtil.checkList(itemsToDeliver, ItemStack.class)) { + for (final ItemStack stack : itemsToDeliver) { + if (stack != null) { + final UUID npcUuid = UUID.fromString(itemDeliveryTargetUuids.get(index)); + final String msg = deliveryMessages.size() > index + ? deliveryMessages.get(index) + : deliveryMessages.get(deliveryMessages.size() - 1); + index++; + if (getDependencies().getCitizens() != null) { + final NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(npcUuid); + if (npc != null) { + oStage.addItemToDeliver(stack); + oStage.addItemDeliveryTarget(npcUuid); + oStage.addDeliverMessage(msg); + } else { + throw new StageFormatException("npc-delivery-ids has invalid NPC " + + "UUID of " + npcUuid, quest, stageNum); + } + } else { + throw new StageFormatException( + "Citizens not found for npc-delivery-uuids", quest, stageNum); + } + } + } + } else { + throw new StageFormatException("items-to-deliver has invalid formatting", quest, + stageNum); + } + } + } else { + throw new StageFormatException("npc-delivery-ids is not a list of numbers", quest, stageNum); + } + } else if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-delivery-ids")) { + // Legacy + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-delivery-ids"), Integer.class)) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + + ".delivery-messages")) { + itemsToDeliver = (List) config.get("quests." + questKey + ".stages.ordered." + + stageNum + ".items-to-deliver"); + itemDeliveryTargetIds = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + ".npc-delivery-ids"); - deliveryMessages = config.getStringList("quests." + questKey + ".stages.ordered." + deliveryMessages = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + ".delivery-messages"); int index = 0; if (ConfigUtil.checkList(itemsToDeliver, ItemStack.class)) { for (final ItemStack stack : itemsToDeliver) { if (stack != null) { final int npcId = itemDeliveryTargetIds.get(index); - final String msg = deliveryMessages.size() > index - ? deliveryMessages.get(index) + final String msg = deliveryMessages.size() > index + ? deliveryMessages.get(index) : deliveryMessages.get(deliveryMessages.size() - 1); index++; if (getDependencies().getCitizens() != null) { final NPC npc = CitizensAPI.getNPCRegistry().getById(npcId); if (npc != null) { oStage.addItemToDeliver(stack); - oStage.addItemDeliveryTarget(npcId); + oStage.addItemDeliveryTarget(npc.getUniqueId()); oStage.addDeliverMessage(msg); } else { throw new StageFormatException("npc-delivery-ids has invalid NPC " + @@ -2957,52 +3062,8 @@ public class Quests extends JavaPlugin implements QuestsAPI { } } } else { - final List items = config.getStringList("quests." + questKey - + ".stages.ordered." + stageNum + ".items-to-deliver"); - if (ConfigUtil.checkList(items, String.class)) { - // Legacy - for (final String item : items) { - final ItemStack is = ItemUtil.readItemStack("" + item); - if (index <= itemDeliveryTargetIds.size()) { - if (itemDeliveryTargetIds.size() != deliveryMessages.size()) { - throw new StageFormatException( - "delivery-messages must be same size as items-to-deliver", - quest, stageNum); - } - final int npcId = itemDeliveryTargetIds.get(index); - final String msg = deliveryMessages.get(index); - index++; - if (is != null) { - if (getDependencies().getCitizens() != null) { - final NPC npc = CitizensAPI.getNPCRegistry().getById(npcId); - if (npc != null) { - oStage.addItemToDeliver(is); - oStage.addItemDeliveryTarget(npcId); - oStage.addDeliverMessage(msg); - } else { - throw new StageFormatException( - "npc-delivery-ids has invalid NPC ID of " + npcId, - quest, stageNum); - } - } else { - throw new StageFormatException( - "Citizens was not found installed for npc-delivery-ids", - quest, stageNum); - } - } else { - throw new StageFormatException( - "items-to-deliver has invalid formatting " + item, quest, - stageNum); - } - } else { - throw new StageFormatException("items-to-deliver is missing target IDs" - , quest, stageNum); - } - } - } else { - throw new StageFormatException("items-to-deliver has invalid formatting", quest, - stageNum); - } + throw new StageFormatException("items-to-deliver has invalid formatting", quest, + stageNum); } } } else { @@ -3012,29 +3073,32 @@ public class Quests extends JavaPlugin implements QuestsAPI { throw new StageFormatException("npc-delivery-id is missing", quest, stageNum); } } - if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-kill")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-ids-to-kill"), Integer.class)) { + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-uuids-to-kill")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-uuids-to-kill"), String.class)) { if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-kill-amounts")) { - if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + ".npc-kill-amounts"), Integer.class)) { - npcIdsToKill = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum - + ".npc-ids-to-kill"); + npcUuidsToKill = config.getStringList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-uuids-to-kill"); npcAmountsToKill = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + ".npc-kill-amounts"); - for (final int i : npcIdsToKill) { - if (CitizensAPI.getNPCRegistry().getById(i) != null) { - if (npcAmountsToKill.get(npcIdsToKill.indexOf(i)) > 0) { - oStage.addCitizenToKill(i); - oStage.addCitizenNumToKill(npcAmountsToKill.get(npcIdsToKill.indexOf(i))); - questNpcIds.add(i); + for (final String s : npcUuidsToKill) { + final UUID npcUuid = UUID.fromString(s); + final NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(npcUuid); + if (npc != null) { + if (npcAmountsToKill.get(npcUuidsToKill.indexOf(s)) > 0) { + oStage.addNpcToKill(npcUuid); + oStage.addNpcNumToKill(npcAmountsToKill.get(npcUuidsToKill.indexOf(s))); + questNpcIds.add(npc.getId()); + questNpcUuids.add(npcUuid); } else { throw new StageFormatException("npc-kill-amounts is not a positive number", quest, stageNum); } } else { - throw new StageFormatException("npc-ids-to-kill has invalid NPC ID of " + i, quest, - stageNum); + throw new StageFormatException("npc-uuids-to-kill has invalid NPC UUID of " + s, + quest, stageNum); } } } else { @@ -3044,8 +3108,43 @@ public class Quests extends JavaPlugin implements QuestsAPI { } else { throw new StageFormatException("npc-kill-amounts is missing", quest, stageNum); } - } else { - throw new StageFormatException("npc-ids-to-kill is not a list of numbers", quest, stageNum); + } + } else if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-ids-to-kill")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-ids-to-kill"), Integer.class)) { + // Legacy + if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".npc-kill-amounts")) { + if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-kill-amounts"), Integer.class)) { + npcIdsToKill = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum + + ".npc-ids-to-kill"); + npcAmountsToKill = config.getIntegerList("quests." + questKey + ".stages.ordered." + + stageNum + ".npc-kill-amounts"); + for (final int i : npcIdsToKill) { + final NPC npc = CitizensAPI.getNPCRegistry().getById(i); + if (npc != null) { + if (npcAmountsToKill.get(npcIdsToKill.indexOf(i)) > 0) { + final UUID npcUuid = npc.getUniqueId(); + oStage.addNpcToKill(npcUuid); + oStage.addNpcNumToKill(npcAmountsToKill.get(npcIdsToKill.indexOf(i))); + questNpcIds.add(npc.getId()); + questNpcUuids.add(npcUuid); + } else { + throw new StageFormatException("npc-kill-amounts is not a positive number", + quest, stageNum); + } + } else { + throw new StageFormatException("npc-ids-to-kill has invalid NPC ID of " + i, quest, + stageNum); + } + } + } else { + throw new StageFormatException("npc-kill-amounts is not a list of numbers", quest, + stageNum); + } + } else { + throw new StageFormatException("npc-kill-amounts is missing", quest, stageNum); + } } } if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".mobs-to-kill")) { diff --git a/core/src/main/java/me/blackvein/quests/Stage.java b/core/src/main/java/me/blackvein/quests/Stage.java index e4009db46..53ab8910d 100644 --- a/core/src/main/java/me/blackvein/quests/Stage.java +++ b/core/src/main/java/me/blackvein/quests/Stage.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.Map.Entry; +import java.util.UUID; public class Stage implements IStage { @@ -42,7 +43,7 @@ public class Stage implements IStage { private LinkedList itemsToBrew = new LinkedList<>(); private LinkedList itemsToConsume = new LinkedList<>(); private LinkedList itemsToDeliver = new LinkedList<>(); - private LinkedList itemDeliveryTargets = new LinkedList() { + private LinkedList itemDeliveryTargets = new LinkedList() { private static final long serialVersionUID = -2774443496142382127L; @@ -50,11 +51,10 @@ public class Stage implements IStage { public boolean equals(final Object o) { if (o instanceof LinkedList) { @SuppressWarnings("unchecked") - final - LinkedList otherList = (LinkedList) o; - for (final Integer i : this) { - final Integer other = otherList.get(this.indexOf(i)); - if (!other.equals(i)) { + final LinkedList otherList = (LinkedList) o; + for (final UUID uuid : this) { + final UUID other = otherList.get(this.indexOf(uuid)); + if (!other.equals(uuid)) { return false; } } @@ -63,7 +63,7 @@ public class Stage implements IStage { } }; private LinkedList deliverMessages = new LinkedList<>(); - private LinkedList citizensToInteract = new LinkedList() { + private LinkedList npcsToInteract = new LinkedList() { private static final long serialVersionUID = -4086855121042524435L; @@ -71,11 +71,10 @@ public class Stage implements IStage { public boolean equals(final Object o) { if (o instanceof LinkedList) { @SuppressWarnings("unchecked") - final - LinkedList otherList = (LinkedList) o; - for (final Integer i : this) { - final Integer other = otherList.get(this.indexOf(i)); - if (!other.equals(i)) { + final LinkedList otherList = (LinkedList) o; + for (final UUID uuid : this) { + final UUID other = otherList.get(this.indexOf(uuid)); + if (!other.equals(uuid)) { return false; } } @@ -83,7 +82,7 @@ public class Stage implements IStage { return true; } }; - private LinkedList citizensToKill = new LinkedList() { + private LinkedList npcsToKill = new LinkedList() { private static final long serialVersionUID = 7705964814014176415L; @@ -91,11 +90,10 @@ public class Stage implements IStage { public boolean equals(final Object o) { if (o instanceof LinkedList) { @SuppressWarnings("unchecked") - final - LinkedList otherList = (LinkedList) o; - for (final Integer i : this) { - final Integer other = otherList.get(this.indexOf(i)); - if (!other.equals(i)) { + final LinkedList otherList = (LinkedList) o; + for (final UUID uuid : this) { + final UUID other = otherList.get(this.indexOf(uuid)); + if (!other.equals(uuid)) { return false; } } @@ -103,7 +101,7 @@ public class Stage implements IStage { return true; } }; - private LinkedList citizenNumToKill = new LinkedList<>(); + private LinkedList npcNumToKill = new LinkedList<>(); private LinkedList mobsToKill = new LinkedList<>(); private LinkedList mobNumToKill = new LinkedList<>(); private LinkedList locationsToKillWithin = new LinkedList<>(); @@ -284,16 +282,16 @@ public class Stage implements IStage { this.itemsToDeliver = itemsToDeliver; } - public LinkedList getItemDeliveryTargets() { + public LinkedList getItemDeliveryTargets() { return itemDeliveryTargets; } @Override - public boolean addItemDeliveryTarget(Integer itemDeliveryTarget) { + public boolean addItemDeliveryTarget(UUID itemDeliveryTarget) { return itemDeliveryTargets.add(itemDeliveryTarget); } - public void setItemDeliveryTargets(final LinkedList itemDeliveryTargets) { + public void setItemDeliveryTargets(final LinkedList itemDeliveryTargets) { this.itemDeliveryTargets = itemDeliveryTargets; } @@ -310,43 +308,42 @@ public class Stage implements IStage { this.deliverMessages = deliverMessages; } - public LinkedList getCitizensToInteract() { - return citizensToInteract; + public LinkedList getNpcsToInteract() { + return npcsToInteract; } @Override - public boolean addCitizenToInteract(Integer citizenToInteract) { - return citizensToInteract.add(citizenToInteract); + public boolean addNpcToInteract(UUID npcToInteract) { + return npcsToInteract.add(npcToInteract); } - public void setCitizensToInteract(final LinkedList citizensToInteract) { - this.citizensToInteract = citizensToInteract; + public void setNpcsToInteract(final LinkedList npcsToInteract) { + this.npcsToInteract = npcsToInteract; } - public LinkedList getCitizensToKill() { - return citizensToKill; + public LinkedList getNpcsToKill() { + return npcsToKill; } @Override - public boolean addCitizenToKill(Integer citizenToKill) { - return citizensToKill.add(citizenToKill); + public boolean addNpcToKill(UUID npcToKill) { + return npcsToKill.add(npcToKill); } - public void setCitizensToKill(final LinkedList citizensToKill) { - this.citizensToKill = citizensToKill; + public void setNpcsToKill(final LinkedList npcsToKill) { + this.npcsToKill = npcsToKill; } - public LinkedList getCitizenNumToKill() { - return citizenNumToKill; + public LinkedList getNpcNumToKill() { + return npcNumToKill; } - @Override - public boolean addCitizenNumToKill(Integer citizenNumToKill) { - return this.citizenNumToKill.add(citizenNumToKill); + public boolean addNpcNumToKill(Integer npcNumToKill) { + return this.npcNumToKill.add(npcNumToKill); } - public void setCitizenNumToKill(final LinkedList citizenNumToKill) { - this.citizenNumToKill = citizenNumToKill; + public void setNpcNumToKill(final LinkedList npcNumToKill) { + this.npcNumToKill = npcNumToKill; } public LinkedList getMobsToKill() { @@ -761,8 +758,8 @@ public class Stage implements IStage { if (!itemsToBrew.isEmpty()) { return true; } if (!itemsToConsume.isEmpty()) { return true; } if (!itemsToDeliver.isEmpty()) { return true; } - if (!citizensToInteract.isEmpty()) { return true; } - if (!citizensToKill.isEmpty()) { return true; } + if (!npcsToInteract.isEmpty()) { return true; } + if (!npcsToKill.isEmpty()) { return true; } if (!locationsToReach.isEmpty()) { return true; } if (!mobsToKill.isEmpty()) {return true; } if (!mobsToTame.isEmpty()) { return true; } @@ -777,8 +774,8 @@ public class Stage implements IStage { * @return true if stage contains a locatable objective */ public boolean hasLocatableObjective() { - if (!citizensToInteract.isEmpty()) { return true; } - if (!citizensToKill.isEmpty()) { return true; } + if (!npcsToInteract.isEmpty()) { return true; } + if (!npcsToKill.isEmpty()) { return true; } if (!locationsToReach.isEmpty()) { return true; } if (!itemDeliveryTargets.isEmpty()) { return true; } if (playersToKill != null) { return true; } @@ -826,9 +823,9 @@ public class Stage implements IStage { } else if (type.equals(ObjectiveType.KILL_PLAYER)) { return playersToKill != null; } else if (type.equals(ObjectiveType.TALK_TO_NPC)) { - return !citizensToInteract.isEmpty(); + return !npcsToInteract.isEmpty(); } else if (type.equals(ObjectiveType.KILL_NPC)) { - return !citizensToKill.isEmpty(); + return !npcsToKill.isEmpty(); } else if (type.equals(ObjectiveType.TAME_MOB)) { return !mobsToTame.isEmpty(); } else if (type.equals(ObjectiveType.SHEAR_SHEEP)) { diff --git a/core/src/main/java/me/blackvein/quests/convo/conditions/tasks/EntityPrompt.java b/core/src/main/java/me/blackvein/quests/convo/conditions/tasks/EntityPrompt.java index 461bc6d9b..16d0f8000 100644 --- a/core/src/main/java/me/blackvein/quests/convo/conditions/tasks/EntityPrompt.java +++ b/core/src/main/java/me/blackvein/quests/convo/conditions/tasks/EntityPrompt.java @@ -251,7 +251,7 @@ public class EntityPrompt extends QuestsEditorNumericPrompt { @Override public String getQueryText(final ConversationContext context) { - return Lang.get("conditionEditorNpcsPrompt"); + return Lang.get("enterNpcUniqueIds"); } @Override diff --git a/core/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java b/core/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java index d1de7f394..fb1989942 100644 --- a/core/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java +++ b/core/src/main/java/me/blackvein/quests/convo/quests/main/QuestMainPrompt.java @@ -13,7 +13,6 @@ package me.blackvein.quests.convo.quests.main; import com.sk89q.worldguard.protection.managers.RegionManager; -import me.blackvein.quests.quests.IQuest; import me.blackvein.quests.Quests; import me.blackvein.quests.convo.QuestsNumericPrompt; import me.blackvein.quests.convo.generic.ItemStackPrompt; @@ -26,6 +25,7 @@ import me.blackvein.quests.convo.quests.rewards.RewardsPrompt; import me.blackvein.quests.convo.quests.stages.StageMenuPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent; +import me.blackvein.quests.quests.IQuest; import me.blackvein.quests.reflect.worldguard.WorldGuardAPI; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; @@ -49,6 +49,7 @@ import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.UUID; @@ -192,16 +193,13 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt { return ChatColor.GRAY + "(" + ChatColor.AQUA + context.getSessionData(CK.Q_FINISH_MESSAGE) + ChatColor.RESET + ChatColor.GRAY + ")"; case 4: - if (context.getSessionData(CK.Q_START_NPC) == null && plugin.getDependencies().getCitizens() + if (context.getSessionData(CK.Q_START_NPC) == null && plugin.getDependencies().getCitizens() != null) { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else if (plugin.getDependencies().getCitizens() != null) { - final Integer id = (Integer) context.getSessionData(CK.Q_START_NPC); - if (id != null) { - return ChatColor.GRAY + "(" + ChatColor.AQUA + CitizensAPI.getNPCRegistry().getById(id).getName() - + ChatColor.RESET + ChatColor.GRAY + ")"; - } - + final UUID uuid = UUID.fromString((String) Objects.requireNonNull(context.getSessionData(CK.Q_START_NPC))); + return ChatColor.GRAY + "(" + ChatColor.AQUA + CitizensAPI.getNPCRegistry().getByUniqueId(uuid) + .getName() + ChatColor.RESET + ChatColor.GRAY + ")"; } else { return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")"; } @@ -246,11 +244,17 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt { public @NotNull String getBasicPromptText(final @NotNull ConversationContext context) { final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this); plugin.getServer().getPluginManager().callEvent(event); - + final StringBuilder text = new StringBuilder(ChatColor.GOLD + "- " + getTitle(context).replaceFirst(": ", ": " + ChatColor.AQUA) + ChatColor.GOLD + " -"); - for (int i = 1; i <= size; i++) { - text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ").append(getAdditionalText(context, i)); + try { + for (int i = 1; i <= size; i++) { + text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i) + .append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ") + .append(getAdditionalText(context, i)); + } + } catch (Exception e) { + e.printStackTrace(); } return text.toString(); } @@ -475,15 +479,15 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt { @Override public @NotNull String getPromptText(final @NotNull ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); plugin.getServer().getPluginManager().callEvent(event); if (context.getForWhom() instanceof Player) { final Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); selectingNpcs.add(((Player) context.getForWhom()).getUniqueId()); plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); - return ChatColor.YELLOW + getQueryText(context) + "\n" - + ChatColor.GOLD + Lang.get("npcHint"); + return ChatColor.YELLOW + Lang.get("questEditorClickNPCStart"); } else { return ChatColor.YELLOW + getQueryText(context); } @@ -496,23 +500,23 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt { } if (!input.equalsIgnoreCase(Lang.get("cmdCancel")) && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { try { - final int i = Integer.parseInt(input); - if (i > -1) { - if (CitizensAPI.getNPCRegistry().getById(i) == null) { + final UUID uuid = UUID.fromString(input); + if (plugin.getDependencies().getCitizens() != null) { + if (CitizensAPI.getNPCRegistry().getByUniqueId(uuid) == null) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorInvalidNPC")); return new QuestNPCStartPrompt(context); } - context.setSessionData(CK.Q_START_NPC, i); - if (context.getForWhom() instanceof Player) { - final Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); - selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); - plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); - } - return new QuestMainPrompt(context); + context.setSessionData(CK.Q_START_NPC, uuid.toString()); } - } catch (final NumberFormatException e) { + if (context.getForWhom() instanceof Player) { + final Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); + } + return new QuestMainPrompt(context); + } catch (final IllegalArgumentException e) { context.getForWhom().sendRawMessage(ChatColor.RED - + Lang.get("reqNotANumber").replace("", input)); + + Lang.get("reqNotAUniqueId").replace("", input)); return new QuestNPCStartPrompt(context); } } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { @@ -606,7 +610,8 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt { @Override public @NotNull String getPromptText(final @NotNull ConversationContext context) { - final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this); + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); plugin.getServer().getPluginManager().callEvent(event); StringBuilder text = new StringBuilder(ChatColor.AQUA + getTitle(context) + "\n"); diff --git a/core/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java b/core/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java index 5978d3701..1d6b8ae0d 100644 --- a/core/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java +++ b/core/src/main/java/me/blackvein/quests/convo/quests/objectives/BlocksPrompt.java @@ -438,8 +438,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockBreakNamesPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockBreakNamesPrompt(context); } } @@ -508,8 +508,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockBreakAmountsPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockBreakAmountsPrompt(context); } } @@ -565,8 +565,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockBreakDurabilityPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockBreakDurabilityPrompt(context); } } @@ -808,8 +808,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockDamageNamesPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockDamageNamesPrompt(context); } } @@ -877,8 +877,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockDamageAmountsPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockDamageAmountsPrompt(context); } } @@ -933,8 +933,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockDamageDurabilityPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockDamageDurabilityPrompt(context); } } @@ -1176,8 +1176,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockPlaceNamesPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockPlaceNamesPrompt(context); } } @@ -1245,8 +1245,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockPlaceAmountsPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockPlaceAmountsPrompt(context); } } @@ -1301,8 +1301,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockPlaceDurabilityPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockPlaceDurabilityPrompt(context); } } @@ -1542,8 +1542,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockUseNamesPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockUseNamesPrompt(context); } } @@ -1610,8 +1610,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockUseAmountsPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockUseAmountsPrompt(context); } } @@ -1666,8 +1666,8 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt { return new BlockUseDurabilityPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfNumbers") + .replace("", s)); return new BlockUseDurabilityPrompt(context); } } diff --git a/core/src/main/java/me/blackvein/quests/convo/quests/objectives/NpcsPrompt.java b/core/src/main/java/me/blackvein/quests/convo/quests/objectives/NpcsPrompt.java index 8e5f77560..eb76faeb3 100644 --- a/core/src/main/java/me/blackvein/quests/convo/quests/objectives/NpcsPrompt.java +++ b/core/src/main/java/me/blackvein/quests/convo/quests/objectives/NpcsPrompt.java @@ -18,6 +18,7 @@ import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt; import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; +import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; @@ -98,7 +99,8 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { final StringBuilder text = new StringBuilder(); - final LinkedList npcs = (LinkedList) context.getSessionData(pref + CK.S_DELIVERY_NPCS); + final LinkedList npcs + = (LinkedList) context.getSessionData(pref + CK.S_DELIVERY_NPCS); final LinkedList items = (LinkedList) context.getSessionData(pref + CK.S_DELIVERY_ITEMS); if (npcs != null && items != null) { @@ -106,9 +108,9 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE) .append(ItemUtil.getName(items.get(i))).append(ChatColor.GRAY).append(" x ") .append(ChatColor.AQUA).append(items.get(i).getAmount()).append(ChatColor.GRAY) - .append(" ").append(Lang.get("to")).append(" ").append(ChatColor.DARK_AQUA) + .append(" ").append(Lang.get("to")).append(" ").append(ChatColor.BLUE) .append(plugin.getDependencies().getCitizens().getNPCRegistry() - .getById(npcs.get(i)).getName()); + .getByUniqueId(UUID.fromString(npcs.get(i))).getName()); } } return text.toString(); @@ -122,13 +124,13 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { final StringBuilder text = new StringBuilder(); - final LinkedList npcs - = (LinkedList) context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO); + final LinkedList npcs + = (LinkedList) context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO); if (npcs != null) { - for (final Integer npc : npcs) { - text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE) + for (final String npc : npcs) { + text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE) .append(plugin.getDependencies().getCitizens().getNPCRegistry() - .getById(npc).getName()).append("\n"); + .getByUniqueId(UUID.fromString(npc)).getName()); } } return text.toString(); @@ -142,15 +144,16 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { final StringBuilder text = new StringBuilder(); - final LinkedList npcs = (LinkedList) context.getSessionData(pref + CK.S_NPCS_TO_KILL); + final LinkedList npcs + = (LinkedList) context.getSessionData(pref + CK.S_NPCS_TO_KILL); final LinkedList amounts = (LinkedList) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS); if (npcs != null && amounts != null) { for (int i = 0; i < npcs.size(); i++) { text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE) .append(plugin.getDependencies().getCitizens().getNPCRegistry() - .getById(npcs.get(i)).getName()).append(ChatColor.GRAY).append(" x ") - .append(ChatColor.AQUA).append(amounts.get(i)); + .getByUniqueId(UUID.fromString(npcs.get(i))).getName()).append(ChatColor.GRAY) + .append(" x ").append(ChatColor.AQUA).append(amounts.get(i)); } } return text.toString(); @@ -260,7 +263,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { case 1: return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem"); case 2: - return ChatColor.YELLOW + Lang.get("stageEditorDeliveryNPCs"); + return ChatColor.YELLOW + Lang.get("stageEditorNPCUniqueIds"); case 3: return ChatColor.YELLOW + Lang.get("stageEditorDeliveryMessages"); case 4: @@ -296,14 +299,14 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { final StringBuilder text = new StringBuilder(); - final List deliveryNpcs - = (List) context.getSessionData(pref + CK.S_DELIVERY_NPCS); + final List deliveryNpcs = (List) context.getSessionData(pref + CK.S_DELIVERY_NPCS); if (deliveryNpcs != null) { - for (final int i : deliveryNpcs) { - text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(i) - .append(ChatColor.GRAY).append(" (").append(ChatColor.AQUA) - .append(plugin.getDependencies().getCitizens().getNPCRegistry() - .getById(i).getName()).append(ChatColor.GRAY).append(")"); + for (final String s : deliveryNpcs) { + final UUID uuid = UUID.fromString(s); + text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA) + .append(plugin.getDependencies().getCitizens().getNPCRegistry().getByUniqueId(uuid) + .getName()).append(ChatColor.GRAY).append(" (").append(ChatColor.BLUE).append(s) + .append(ChatColor.GRAY).append(")"); } } return text.toString(); @@ -386,7 +389,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { final int one; final int two; final List items = (List) context.getSessionData(pref + CK.S_DELIVERY_ITEMS); - final List npcs = (List) context.getSessionData(pref + CK.S_DELIVERY_NPCS); + final List npcs = (List) context.getSessionData(pref + CK.S_DELIVERY_NPCS); if (items != null) { one = items.size(); } else { @@ -427,56 +430,69 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { @Override public String getQueryText(final ConversationContext context) { - return Lang.get("stageEditorNPCPrompt"); + return Lang.get("enterNpcUniqueIds"); } @Override - public @NotNull String getPromptText(final ConversationContext context) { - final Set temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.add(((Player) context.getForWhom()).getUniqueId()); - plugin.getQuestFactory().setSelectingNpcs(temp); - return ChatColor.YELLOW + getQueryText(context) + "\n" + ChatColor.GOLD + Lang.get("npcHint"); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + } + + if (context.getForWhom() instanceof Player) { + final Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.add(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); + return ChatColor.YELLOW + Lang.get("questEditorClickNPCStart"); + } else { + return ChatColor.YELLOW + getQueryText(context); + } } @Override + @SuppressWarnings("unchecked") public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { if (input == null) { return null; } if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) { final String[] args = input.split(" "); - final LinkedList npcs = new LinkedList<>(); + final LinkedList npcs = context.getSessionData(pref + CK.S_DELIVERY_NPCS) != null + ? (LinkedList) context.getSessionData(pref + CK.S_DELIVERY_NPCS) : new LinkedList<>(); for (final String s : args) { try { - final int i = Integer.parseInt(s); - if (plugin.getDependencies().getCitizens().getNPCRegistry().getById(i) != null) { - npcs.add(i); + final UUID uuid = UUID.fromString(s); + if (plugin.getDependencies().getCitizens().getNPCRegistry().getByUniqueId(uuid) != null + && npcs != null) { + npcs.add(uuid.toString()); } else { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + "" + i + ChatColor.RED + " " + context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + "" + uuid + ChatColor.RED + " " + Lang.get("stageEditorInvalidNPC")); return new NpcDeliveryNpcsPrompt(context); } - } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + } catch (final IllegalArgumentException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfUniqueIds") + .replace("", s)); return new NpcDeliveryNpcsPrompt(context); } } context.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs); } - final Set temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.remove(((Player) context.getForWhom()).getUniqueId()); - plugin.getQuestFactory().setSelectingNpcs(temp); + final Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); return new NpcsDeliveryListPrompt(context); } } public class NpcDeliveryMessagesPrompt extends QuestsEditorStringPrompt { - + public NpcDeliveryMessagesPrompt(final ConversationContext context) { super(context); } - + @Override public String getTitle(final ConversationContext context) { return null; @@ -488,6 +504,12 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { } @Override public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + } + return ChatColor.YELLOW + getQueryText(context) + "\n" + ChatColor.GOLD + Lang.get("stageEditorNPCNote"); } @@ -506,11 +528,11 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { } public class NpcsIdsToTalkToPrompt extends QuestsEditorStringPrompt { - + public NpcsIdsToTalkToPrompt(final ConversationContext context) { super(context); } - + @Override public String getTitle(final ConversationContext context) { return null; @@ -518,39 +540,51 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { @Override public String getQueryText(final ConversationContext context) { - return Lang.get("stageEditorNPCToTalkToPrompt"); + return Lang.get("enterOrClearNpcUniqueIds"); } @Override - public @NotNull String getPromptText(final ConversationContext context) { - final Set temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.add(((Player) context.getForWhom()).getUniqueId()); - plugin.getQuestFactory().setSelectingNpcs(temp); - return ChatColor.YELLOW + getQueryText(context) + "\n" + ChatColor.GOLD - + Lang.get("npcHint"); + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + } + + if (context.getForWhom() instanceof Player) { + final Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.add(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); + return ChatColor.YELLOW + Lang.get("questEditorClickNPCStart"); + } else { + return ChatColor.YELLOW + getQueryText(context); + } } @Override + @SuppressWarnings("unchecked") public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { if (input == null) { return null; } if (!input.equalsIgnoreCase(Lang.get("cmdCancel")) && !input.equalsIgnoreCase(Lang.get("cmdClear"))) { final String[] args = input.split(" "); - final LinkedList npcs = new LinkedList<>(); + final LinkedList npcs = context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) != null + ? (LinkedList) context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) : new LinkedList<>(); for (final String s : args) { try { - final int i = Integer.parseInt(s); - if (plugin.getDependencies().getCitizens().getNPCRegistry().getById(i) != null) { - npcs.add(i); + final UUID uuid = UUID.fromString(s); + if (plugin.getDependencies().getCitizens().getNPCRegistry().getByUniqueId(uuid) != null + && npcs != null) { + npcs.add(uuid.toString()); } else { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + "" + i + ChatColor.RED + " " + context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + "" + uuid + ChatColor.RED + " " + Lang.get("stageEditorInvalidNPC")); return new NpcsIdsToTalkToPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfUniqueIds") + .replace("", s)); return new NpcsIdsToTalkToPrompt(context); } } @@ -559,9 +593,9 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, null); } if (context.getForWhom() instanceof Player) { - final Set temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.remove(((Player) context.getForWhom()).getUniqueId()); - plugin.getQuestFactory().setSelectingNpcs(temp); + final Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); } return new StageMainPrompt(stageNum, context); } @@ -572,19 +606,19 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { public NpcsKillListPrompt(final ConversationContext context) { super(context); } - + private final int size = 4; - + @Override public int getSize() { return size; } - + @Override public String getTitle(final ConversationContext context) { return Lang.get("stageEditorNPCs"); } - + @Override public ChatColor getNumberColor(final ConversationContext context, final int number) { switch (number) { @@ -599,12 +633,12 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { return null; } } - + @Override public String getSelectionText(final ConversationContext context, final int number) { switch(number) { case 1: - return ChatColor.YELLOW + Lang.get("stageEditorSetKillIds"); + return ChatColor.YELLOW + Lang.get("stageEditorNPCUniqueIds"); case 2: return ChatColor.YELLOW + Lang.get("stageEditorSetKillAmounts"); case 3: @@ -615,7 +649,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { return null; } } - + @Override @SuppressWarnings("unchecked") public String getAdditionalText(final ConversationContext context, final int number) { @@ -626,13 +660,13 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")"; } else { final StringBuilder text = new StringBuilder(); - final List npcsToKill = (List) context.getSessionData(pref + CK.S_NPCS_TO_KILL); + final List npcsToKill = (List) context.getSessionData(pref + CK.S_NPCS_TO_KILL); if (npcsToKill != null) { - for (final Integer i : npcsToKill) { - text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA) + for (final String s : npcsToKill) { + text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE) .append(plugin.getDependencies().getCitizens().getNPCRegistry() - .getById(i).getName()).append(ChatColor.DARK_AQUA).append(" (").append(i) - .append(")"); + .getByUniqueId(UUID.fromString(s)).getName()).append(ChatColor.GRAY).append(" (") + .append(ChatColor.AQUA).append(s).append(ChatColor.GRAY).append(")"); } } return text.toString(); @@ -678,7 +712,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { } return text.toString(); } - + @SuppressWarnings("unchecked") @Override protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) { @@ -695,7 +729,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { case 4: final int one; final int two; - final List kill = (List) context.getSessionData(pref + CK.S_NPCS_TO_KILL); + final List kill = (List) context.getSessionData(pref + CK.S_NPCS_TO_KILL); final List killAmounts = (List) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS); if (kill != null) { @@ -721,11 +755,11 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { } public class NpcIdsToKillPrompt extends QuestsEditorStringPrompt { - + public NpcIdsToKillPrompt(final ConversationContext context) { super(context); } - + @Override public String getTitle(final ConversationContext context) { return null; @@ -733,46 +767,59 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { @Override public String getQueryText(final ConversationContext context) { - return Lang.get("stageEditorNPCPrompt"); - } - - @Override - public @NotNull String getPromptText(final ConversationContext context) { - final Set temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.add(((Player) context.getForWhom()).getUniqueId()); - plugin.getQuestFactory().setSelectingNpcs(temp); - return ChatColor.YELLOW + getQueryText(context) + "\n" + ChatColor.GOLD + Lang.get("npcHint"); + return Lang.get("enterNpcUniqueIds"); } @Override + public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + } + + if (context.getForWhom() instanceof Player) { + final Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.add(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); + return ChatColor.YELLOW + Lang.get("questEditorClickNPCStart"); + } else { + return ChatColor.YELLOW + getQueryText(context); + } + } + + @Override + @SuppressWarnings("unchecked") public Prompt acceptInput(final @NotNull ConversationContext context, final String input) { if (input == null) { return null; } if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) { final String[] args = input.split(" "); - final LinkedList npcs = new LinkedList<>(); + final LinkedList npcs = context.getSessionData(pref + CK.S_NPCS_TO_KILL) != null + ? (LinkedList) context.getSessionData(pref + CK.S_NPCS_TO_KILL) : new LinkedList<>(); for (final String s : args) { try { - final int i = Integer.parseInt(s); - if (plugin.getDependencies().getCitizens().getNPCRegistry().getById(i) != null) { - npcs.add(i); + final UUID uuid = UUID.fromString(s); + if (plugin.getDependencies().getCitizens().getNPCRegistry().getByUniqueId(uuid) != null + && npcs != null) { + npcs.add(uuid.toString()); } else { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + "" + i + ChatColor.RED + " " + context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + "" + uuid + ChatColor.RED + " " + Lang.get("stageEditorInvalidNPC")); return new NpcIdsToKillPrompt(context); } - } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + } catch (final IllegalArgumentException e) { + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfUniqueIds") + .replace("", s)); return new NpcIdsToKillPrompt(context); } } context.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs); } - final Set temp = plugin.getQuestFactory().getSelectingNpcs(); - temp.remove(((Player) context.getForWhom()).getUniqueId()); - plugin.getQuestFactory().setSelectingNpcs(temp); + final Set selectingNpcs = plugin.getQuestFactory().getSelectingNpcs(); + selectingNpcs.remove(((Player) context.getForWhom()).getUniqueId()); + plugin.getQuestFactory().setSelectingNpcs(selectingNpcs); return new NpcsKillListPrompt(context); } } @@ -795,6 +842,12 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { @Override public @NotNull String getPromptText(final @NotNull ConversationContext context) { + if (context.getPlugin() != null) { + final QuestsEditorPostOpenStringPromptEvent event + = new QuestsEditorPostOpenStringPromptEvent(context, this); + plugin.getServer().getPluginManager().callEvent(event); + } + return ChatColor.YELLOW + getQueryText(context); } @@ -816,8 +869,8 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt { return new NpcAmountsToKillPrompt(context); } } catch (final NumberFormatException e) { - context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED - + Lang.get("stageEditorNotListofNumbers")); + context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNotListOfUniqueIds") + .replace("", s)); return new NpcAmountsToKillPrompt(context); } } diff --git a/core/src/main/java/me/blackvein/quests/listeners/NpcListener.java b/core/src/main/java/me/blackvein/quests/listeners/NpcListener.java index d4a2fdccf..5ac96e7e8 100644 --- a/core/src/main/java/me/blackvein/quests/listeners/NpcListener.java +++ b/core/src/main/java/me/blackvein/quests/listeners/NpcListener.java @@ -12,10 +12,10 @@ package me.blackvein.quests.listeners; -import me.blackvein.quests.quests.IQuest; -import me.blackvein.quests.player.IQuester; import me.blackvein.quests.Quests; import me.blackvein.quests.enums.ObjectiveType; +import me.blackvein.quests.player.IQuester; +import me.blackvein.quests.quests.IQuest; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; import net.citizensnpcs.api.event.NPCDeathEvent; @@ -42,6 +42,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.Map.Entry; import java.util.Set; +import java.util.UUID; public class NpcListener implements Listener { @@ -58,9 +59,11 @@ public class NpcListener implements Listener { return; } 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()); - return; + if (evt.getNPC() == null) { + plugin.getLogger().severe("NPC was null while selecting by right-click"); + return; + } + evt.getClicker().acceptConversationInput(String.valueOf(evt.getNPC().getUniqueId())); } if (!evt.getClicker().isConversing()) { final Player player = evt.getClicker(); @@ -81,15 +84,15 @@ public class NpcListener implements Listener { final NPC clicked = evt.getNPC(); if (!matches.isEmpty()) { for (final Integer match : matches) { - final Integer id = quester.getCurrentStage(quest).getItemDeliveryTargets().get(match); - if (id.equals(clicked.getId())) { + final UUID uuid = quester.getCurrentStage(quest).getItemDeliveryTargets().get(match); + if (uuid.equals(clicked.getUniqueId())) { quester.deliverToNPC(quest, clicked, hand); return; } } } else if (!hand.getType().equals(Material.AIR)) { - for (final Integer n : quester.getCurrentStage(quest).getItemDeliveryTargets()) { - if (n.equals(clicked.getId())) { + for (final UUID uuid : quester.getCurrentStage(quest).getItemDeliveryTargets()) { + if (uuid.equals(clicked.getUniqueId())) { String text = ""; final boolean hasMeta = hand.getItemMeta() != null; if (hasMeta) { @@ -189,10 +192,10 @@ public class NpcListener implements Listener { boolean hasObjective = false; for (final IQuest quest : quester.getCurrentQuestsTemp().keySet()) { if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.TALK_TO_NPC)) { - final int npcIndex - = quester.getCurrentStage(quest).getCitizensToInteract().indexOf(evt.getNPC().getId()); + final int npcIndex = quester.getCurrentStage(quest).getNpcsToInteract().indexOf(evt.getNPC() + .getUniqueId()); if (quester.getQuestData(quest) != null && npcIndex > -1 - && !quester.getQuestData(quest).citizensInteracted.get(npcIndex)) { + && !quester.getQuestData(quest).npcsInteracted.get(npcIndex)) { hasObjective = true; } quester.interactWithNPC(quest, evt.getNPC()); @@ -262,8 +265,11 @@ public class NpcListener implements Listener { return; } 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()); + if (evt.getNPC() == null) { + plugin.getLogger().severe("NPC was null while selecting by left-click"); + return; + } + evt.getClicker().acceptConversationInput(String.valueOf(evt.getNPC().getUniqueId())); } } diff --git a/core/src/main/java/me/blackvein/quests/quests/BukkitQuestFactory.java b/core/src/main/java/me/blackvein/quests/quests/BukkitQuestFactory.java index f4069f56c..e54000b94 100644 --- a/core/src/main/java/me/blackvein/quests/quests/BukkitQuestFactory.java +++ b/core/src/main/java/me/blackvein/quests/quests/BukkitQuestFactory.java @@ -12,12 +12,12 @@ package me.blackvein.quests.quests; -import me.blackvein.quests.module.ICustomObjective; import me.blackvein.quests.Quests; import me.blackvein.quests.convo.quests.main.QuestMainPrompt; import me.blackvein.quests.convo.quests.menu.QuestMenuPrompt; import me.blackvein.quests.convo.quests.stages.StageMenuPrompt; import me.blackvein.quests.interfaces.ReloadCallback; +import me.blackvein.quests.module.ICustomObjective; import me.blackvein.quests.util.CK; import me.blackvein.quests.util.ConfigUtil; import me.blackvein.quests.util.FakeConversable; @@ -144,377 +144,390 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi @SuppressWarnings("deprecation") public void loadQuest(final ConversationContext context, final IQuest q) { - context.setSessionData(CK.ED_QUEST_EDIT, q.getName()); - context.setSessionData(CK.Q_ID, q.getId()); - context.setSessionData(CK.Q_NAME, q.getName()); - context.setSessionData(CK.Q_ASK_MESSAGE, q.getDescription()); - context.setSessionData(CK.Q_FINISH_MESSAGE, q.getFinished()); - if (plugin.getDependencies().getCitizens() != null) { - if (q.getNpcStart() != null) { - context.setSessionData(CK.Q_START_NPC, q.getNpcStart().getId()); - } - } - context.setSessionData(CK.Q_START_BLOCK, q.getBlockStart()); - if (q.getInitialAction() != null) { - context.setSessionData(CK.Q_INITIAL_EVENT, q.getInitialAction().getName()); - } - if (q.getRegionStart() != null) { - context.setSessionData(CK.Q_REGION, q.getRegionStart()); - } - if (q.getGUIDisplay() != null) { - context.setSessionData(CK.Q_GUIDISPLAY, q.getGUIDisplay()); - } - final Requirements requirements = q.getRequirements(); - if (requirements.getMoney() != 0) { - context.setSessionData(CK.REQ_MONEY, requirements.getMoney()); - } - if (requirements.getQuestPoints() != 0) { - context.setSessionData(CK.REQ_QUEST_POINTS, requirements.getQuestPoints()); - } - if (requirements.getExp() != 0) { - context.setSessionData(CK.REW_EXP, requirements.getExp()); - } - if (!requirements.getItems().isEmpty()) { - context.setSessionData(CK.REQ_ITEMS, requirements.getItems()); - context.setSessionData(CK.REQ_ITEMS_REMOVE, requirements.getRemoveItems()); - } - if (!requirements.getNeededQuests().isEmpty()) { - final List ids = requirements.getNeededQuests().stream().map(IQuest::getId).collect(Collectors.toList()); - context.setSessionData(CK.REQ_QUEST, ids); - } - if (!requirements.getBlockQuests().isEmpty()) { - final List ids = requirements.getBlockQuests().stream().map(IQuest::getId).collect(Collectors.toList()); - context.setSessionData(CK.REQ_QUEST_BLOCK, ids); - } - if (!requirements.getMcmmoSkills().isEmpty()) { - context.setSessionData(CK.REQ_MCMMO_SKILLS, requirements.getMcmmoAmounts()); - context.setSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS, requirements.getMcmmoAmounts()); - } - if (!requirements.getPermissions().isEmpty()) { - context.setSessionData(CK.REQ_PERMISSION, requirements.getPermissions()); - } - if (requirements.getHeroesPrimaryClass() != null) { - context.setSessionData(CK.REQ_HEROES_PRIMARY_CLASS, requirements.getHeroesPrimaryClass()); - } - if (requirements.getHeroesSecondaryClass() != null) { - context.setSessionData(CK.REQ_HEROES_SECONDARY_CLASS, requirements.getHeroesSecondaryClass()); - } - if (!requirements.getCustomRequirements().isEmpty()) { - final LinkedList list = new LinkedList<>(); - final LinkedList> dataMapList = new LinkedList<>(); - for (final Entry> entry : requirements.getCustomRequirements().entrySet()) { - list.add(entry.getKey()); - dataMapList.add(entry.getValue()); - } - context.setSessionData(CK.REQ_CUSTOM, list); - context.setSessionData(CK.REQ_CUSTOM_DATA, dataMapList); - } - if (!requirements.getDetailsOverride().isEmpty()) { - context.setSessionData(CK.REQ_FAIL_MESSAGE, requirements.getDetailsOverride()); - } - final Rewards rewards = q.getRewards(); - if (rewards.getMoney() != 0) { - context.setSessionData(CK.REW_MONEY, rewards.getMoney()); - } - if (rewards.getQuestPoints() != 0) { - context.setSessionData(CK.REW_QUEST_POINTS, rewards.getQuestPoints()); - } - if (rewards.getExp() != 0) { - context.setSessionData(CK.REW_EXP, rewards.getExp()); - } - if (!rewards.getItems().isEmpty()) { - context.setSessionData(CK.REW_ITEMS, rewards.getItems()); - } - if (!rewards.getCommands().isEmpty()) { - context.setSessionData(CK.REW_COMMAND, rewards.getCommands()); - } - if (!rewards.getCommandsOverrideDisplay().isEmpty()) { - context.setSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY, rewards.getCommandsOverrideDisplay()); - } - if (!rewards.getPermissions().isEmpty()) { - context.setSessionData(CK.REW_PERMISSION, rewards.getPermissions()); - } - if (!rewards.getPermissions().isEmpty()) { - context.setSessionData(CK.REW_PERMISSION_WORLDS, rewards.getPermissionWorlds()); - } - if (!rewards.getMcmmoSkills().isEmpty()) { - context.setSessionData(CK.REW_MCMMO_SKILLS, rewards.getMcmmoSkills()); - context.setSessionData(CK.REW_MCMMO_AMOUNTS, rewards.getMcmmoAmounts()); - } - if (!rewards.getHeroesClasses().isEmpty()) { - context.setSessionData(CK.REW_HEROES_CLASSES, rewards.getHeroesClasses()); - context.setSessionData(CK.REW_HEROES_AMOUNTS, rewards.getHeroesAmounts()); - } - if (rewards.getPartiesExperience() != 0) { - context.setSessionData(CK.REW_PARTIES_EXPERIENCE, rewards.getPartiesExperience()); - } - if (!rewards.getPhatLoots().isEmpty()) { - context.setSessionData(CK.REW_PHAT_LOOTS, rewards.getPhatLoots()); - } - if (!rewards.getCustomRewards().isEmpty()) { - context.setSessionData(CK.REW_CUSTOM, new LinkedList<>(rewards.getCustomRewards().keySet())); - context.setSessionData(CK.REW_CUSTOM_DATA, new LinkedList(rewards.getCustomRewards().values())); - } - if (!rewards.getDetailsOverride().isEmpty()) { - context.setSessionData(CK.REW_DETAILS_OVERRIDE, rewards.getDetailsOverride()); - } - final Planner pln = q.getPlanner(); - if (pln.getStart() != null) { - context.setSessionData(CK.PLN_START_DATE, pln.getStart()); - } - if (pln.getEnd() != null) { - context.setSessionData(CK.PLN_END_DATE, pln.getEnd()); - } - if (pln.getRepeat() != -1) { - context.setSessionData(CK.PLN_REPEAT_CYCLE, pln.getRepeat()); - } - if (pln.getCooldown() != -1) { - context.setSessionData(CK.PLN_COOLDOWN, pln.getCooldown()); - } - context.setSessionData(CK.PLN_OVERRIDE, pln.getOverride()); - final Options opt = q.getOptions(); - context.setSessionData(CK.OPT_ALLOW_COMMANDS, opt.canAllowCommands()); - context.setSessionData(CK.OPT_ALLOW_QUITTING, opt.canAllowQuitting()); - context.setSessionData(CK.OPT_IGNORE_SILK_TOUCH, opt.canIgnoreSilkTouch()); - context.setSessionData(CK.OPT_EXTERNAL_PARTY_PLUGIN, opt.getExternalPartyPlugin()); - context.setSessionData(CK.OPT_USE_PARTIES_PLUGIN, opt.canUsePartiesPlugin()); - context.setSessionData(CK.OPT_SHARE_PROGRESS_LEVEL, opt.getShareProgressLevel()); - context.setSessionData(CK.OPT_SHARE_SAME_QUEST_ONLY, opt.canShareSameQuestOnly()); - context.setSessionData(CK.OPT_SHARE_DISTANCE, opt.getShareDistance()); - context.setSessionData(CK.OPT_HANDLE_OFFLINE_PLAYERS, opt.canHandleOfflinePlayers()); - // Stages (Objectives) - int index = 1; - for (final IStage stage : q.getStages()) { - final String pref = "stage" + index; - index++; - context.setSessionData(pref, Boolean.TRUE); - if (!stage.getBlocksToBreak().isEmpty()) { - final LinkedList names = new LinkedList<>(); - final LinkedList amounts = new LinkedList<>(); - final LinkedList durability = new LinkedList<>(); - for (final ItemStack e : stage.getBlocksToBreak()) { - names.add(e.getType().name()); - amounts.add(e.getAmount()); - durability.add(e.getDurability()); + try { + context.setSessionData(CK.ED_QUEST_EDIT, q.getName()); + context.setSessionData(CK.Q_ID, q.getId()); + context.setSessionData(CK.Q_NAME, q.getName()); + context.setSessionData(CK.Q_ASK_MESSAGE, q.getDescription()); + context.setSessionData(CK.Q_FINISH_MESSAGE, q.getFinished()); + if (plugin.getDependencies().getCitizens() != null) { + if (q.getNpcStart() != null) { + context.setSessionData(CK.Q_START_NPC, q.getNpcStart().getUniqueId().toString()); } - context.setSessionData(pref + CK.S_BREAK_NAMES, names); - context.setSessionData(pref + CK.S_BREAK_AMOUNTS, amounts); - context.setSessionData(pref + CK.S_BREAK_DURABILITY, durability); } - if (!stage.getBlocksToDamage().isEmpty()) { - final LinkedList names = new LinkedList<>(); - final LinkedList amounts = new LinkedList<>(); - final LinkedList durability = new LinkedList<>(); - for (final ItemStack e : stage.getBlocksToDamage()) { - names.add(e.getType().name()); - amounts.add(e.getAmount()); - durability.add(e.getDurability()); + context.setSessionData(CK.Q_START_BLOCK, q.getBlockStart()); + if (q.getInitialAction() != null) { + context.setSessionData(CK.Q_INITIAL_EVENT, q.getInitialAction().getName()); + } + if (q.getRegionStart() != null) { + context.setSessionData(CK.Q_REGION, q.getRegionStart()); + } + if (q.getGUIDisplay() != null) { + context.setSessionData(CK.Q_GUIDISPLAY, q.getGUIDisplay()); + } + final Requirements requirements = q.getRequirements(); + if (requirements.getMoney() != 0) { + context.setSessionData(CK.REQ_MONEY, requirements.getMoney()); + } + if (requirements.getQuestPoints() != 0) { + context.setSessionData(CK.REQ_QUEST_POINTS, requirements.getQuestPoints()); + } + if (requirements.getExp() != 0) { + context.setSessionData(CK.REW_EXP, requirements.getExp()); + } + if (!requirements.getItems().isEmpty()) { + context.setSessionData(CK.REQ_ITEMS, requirements.getItems()); + context.setSessionData(CK.REQ_ITEMS_REMOVE, requirements.getRemoveItems()); + } + if (!requirements.getNeededQuests().isEmpty()) { + final List ids = requirements.getNeededQuests().stream().map(IQuest::getId).collect(Collectors.toList()); + context.setSessionData(CK.REQ_QUEST, ids); + } + if (!requirements.getBlockQuests().isEmpty()) { + final List ids = requirements.getBlockQuests().stream().map(IQuest::getId).collect(Collectors.toList()); + context.setSessionData(CK.REQ_QUEST_BLOCK, ids); + } + if (!requirements.getMcmmoSkills().isEmpty()) { + context.setSessionData(CK.REQ_MCMMO_SKILLS, requirements.getMcmmoAmounts()); + context.setSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS, requirements.getMcmmoAmounts()); + } + if (!requirements.getPermissions().isEmpty()) { + context.setSessionData(CK.REQ_PERMISSION, requirements.getPermissions()); + } + if (requirements.getHeroesPrimaryClass() != null) { + context.setSessionData(CK.REQ_HEROES_PRIMARY_CLASS, requirements.getHeroesPrimaryClass()); + } + if (requirements.getHeroesSecondaryClass() != null) { + context.setSessionData(CK.REQ_HEROES_SECONDARY_CLASS, requirements.getHeroesSecondaryClass()); + } + if (!requirements.getCustomRequirements().isEmpty()) { + final LinkedList list = new LinkedList<>(); + final LinkedList> dataMapList = new LinkedList<>(); + for (final Entry> entry : requirements.getCustomRequirements().entrySet()) { + list.add(entry.getKey()); + dataMapList.add(entry.getValue()); } - context.setSessionData(pref + CK.S_DAMAGE_NAMES, names); - context.setSessionData(pref + CK.S_DAMAGE_AMOUNTS, amounts); - context.setSessionData(pref + CK.S_DAMAGE_DURABILITY, durability); + context.setSessionData(CK.REQ_CUSTOM, list); + context.setSessionData(CK.REQ_CUSTOM_DATA, dataMapList); } - if (!stage.getBlocksToPlace().isEmpty()) { - final LinkedList names = new LinkedList<>(); - final LinkedList amounts = new LinkedList<>(); - final LinkedList durability = new LinkedList<>(); - for (final ItemStack e : stage.getBlocksToPlace()) { - names.add(e.getType().name()); - amounts.add(e.getAmount()); - durability.add(e.getDurability()); + if (!requirements.getDetailsOverride().isEmpty()) { + context.setSessionData(CK.REQ_FAIL_MESSAGE, requirements.getDetailsOverride()); + } + final Rewards rewards = q.getRewards(); + if (rewards.getMoney() != 0) { + context.setSessionData(CK.REW_MONEY, rewards.getMoney()); + } + if (rewards.getQuestPoints() != 0) { + context.setSessionData(CK.REW_QUEST_POINTS, rewards.getQuestPoints()); + } + if (rewards.getExp() != 0) { + context.setSessionData(CK.REW_EXP, rewards.getExp()); + } + if (!rewards.getItems().isEmpty()) { + context.setSessionData(CK.REW_ITEMS, rewards.getItems()); + } + if (!rewards.getCommands().isEmpty()) { + context.setSessionData(CK.REW_COMMAND, rewards.getCommands()); + } + if (!rewards.getCommandsOverrideDisplay().isEmpty()) { + context.setSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY, rewards.getCommandsOverrideDisplay()); + } + if (!rewards.getPermissions().isEmpty()) { + context.setSessionData(CK.REW_PERMISSION, rewards.getPermissions()); + } + if (!rewards.getPermissions().isEmpty()) { + context.setSessionData(CK.REW_PERMISSION_WORLDS, rewards.getPermissionWorlds()); + } + if (!rewards.getMcmmoSkills().isEmpty()) { + context.setSessionData(CK.REW_MCMMO_SKILLS, rewards.getMcmmoSkills()); + context.setSessionData(CK.REW_MCMMO_AMOUNTS, rewards.getMcmmoAmounts()); + } + if (!rewards.getHeroesClasses().isEmpty()) { + context.setSessionData(CK.REW_HEROES_CLASSES, rewards.getHeroesClasses()); + context.setSessionData(CK.REW_HEROES_AMOUNTS, rewards.getHeroesAmounts()); + } + if (rewards.getPartiesExperience() != 0) { + context.setSessionData(CK.REW_PARTIES_EXPERIENCE, rewards.getPartiesExperience()); + } + if (!rewards.getPhatLoots().isEmpty()) { + context.setSessionData(CK.REW_PHAT_LOOTS, rewards.getPhatLoots()); + } + if (!rewards.getCustomRewards().isEmpty()) { + context.setSessionData(CK.REW_CUSTOM, new LinkedList<>(rewards.getCustomRewards().keySet())); + context.setSessionData(CK.REW_CUSTOM_DATA, new LinkedList(rewards.getCustomRewards().values())); + } + if (!rewards.getDetailsOverride().isEmpty()) { + context.setSessionData(CK.REW_DETAILS_OVERRIDE, rewards.getDetailsOverride()); + } + final Planner pln = q.getPlanner(); + if (pln.getStart() != null) { + context.setSessionData(CK.PLN_START_DATE, pln.getStart()); + } + if (pln.getEnd() != null) { + context.setSessionData(CK.PLN_END_DATE, pln.getEnd()); + } + if (pln.getRepeat() != -1) { + context.setSessionData(CK.PLN_REPEAT_CYCLE, pln.getRepeat()); + } + if (pln.getCooldown() != -1) { + context.setSessionData(CK.PLN_COOLDOWN, pln.getCooldown()); + } + context.setSessionData(CK.PLN_OVERRIDE, pln.getOverride()); + final Options opt = q.getOptions(); + context.setSessionData(CK.OPT_ALLOW_COMMANDS, opt.canAllowCommands()); + context.setSessionData(CK.OPT_ALLOW_QUITTING, opt.canAllowQuitting()); + context.setSessionData(CK.OPT_IGNORE_SILK_TOUCH, opt.canIgnoreSilkTouch()); + context.setSessionData(CK.OPT_EXTERNAL_PARTY_PLUGIN, opt.getExternalPartyPlugin()); + context.setSessionData(CK.OPT_USE_PARTIES_PLUGIN, opt.canUsePartiesPlugin()); + context.setSessionData(CK.OPT_SHARE_PROGRESS_LEVEL, opt.getShareProgressLevel()); + context.setSessionData(CK.OPT_SHARE_SAME_QUEST_ONLY, opt.canShareSameQuestOnly()); + context.setSessionData(CK.OPT_SHARE_DISTANCE, opt.getShareDistance()); + context.setSessionData(CK.OPT_HANDLE_OFFLINE_PLAYERS, opt.canHandleOfflinePlayers()); + // Stages (Objectives) + int index = 1; + for (final IStage stage : q.getStages()) { + final String pref = "stage" + index; + index++; + context.setSessionData(pref, Boolean.TRUE); + if (!stage.getBlocksToBreak().isEmpty()) { + final LinkedList names = new LinkedList<>(); + final LinkedList amounts = new LinkedList<>(); + final LinkedList durability = new LinkedList<>(); + for (final ItemStack e : stage.getBlocksToBreak()) { + names.add(e.getType().name()); + amounts.add(e.getAmount()); + durability.add(e.getDurability()); + } + context.setSessionData(pref + CK.S_BREAK_NAMES, names); + context.setSessionData(pref + CK.S_BREAK_AMOUNTS, amounts); + context.setSessionData(pref + CK.S_BREAK_DURABILITY, durability); } - context.setSessionData(pref + CK.S_PLACE_NAMES, names); - context.setSessionData(pref + CK.S_PLACE_AMOUNTS, amounts); - context.setSessionData(pref + CK.S_PLACE_DURABILITY, durability); - } - if (!stage.getBlocksToUse().isEmpty()) { - final LinkedList names = new LinkedList<>(); - final LinkedList amounts = new LinkedList<>(); - final LinkedList durability = new LinkedList<>(); - for (final ItemStack e : stage.getBlocksToUse()) { - names.add(e.getType().name()); - amounts.add(e.getAmount()); - durability.add(e.getDurability()); + if (!stage.getBlocksToDamage().isEmpty()) { + final LinkedList names = new LinkedList<>(); + final LinkedList amounts = new LinkedList<>(); + final LinkedList durability = new LinkedList<>(); + for (final ItemStack e : stage.getBlocksToDamage()) { + names.add(e.getType().name()); + amounts.add(e.getAmount()); + durability.add(e.getDurability()); + } + context.setSessionData(pref + CK.S_DAMAGE_NAMES, names); + context.setSessionData(pref + CK.S_DAMAGE_AMOUNTS, amounts); + context.setSessionData(pref + CK.S_DAMAGE_DURABILITY, durability); } - context.setSessionData(pref + CK.S_USE_NAMES, names); - context.setSessionData(pref + CK.S_USE_AMOUNTS, amounts); - context.setSessionData(pref + CK.S_USE_DURABILITY, durability); - } - if (!stage.getBlocksToCut().isEmpty()) { - final LinkedList names = new LinkedList<>(); - final LinkedList amounts = new LinkedList<>(); - final LinkedList durability = new LinkedList<>(); - for (final ItemStack e : stage.getBlocksToCut()) { - names.add(e.getType().name()); - amounts.add(e.getAmount()); - durability.add(e.getDurability()); + if (!stage.getBlocksToPlace().isEmpty()) { + final LinkedList names = new LinkedList<>(); + final LinkedList amounts = new LinkedList<>(); + final LinkedList durability = new LinkedList<>(); + for (final ItemStack e : stage.getBlocksToPlace()) { + names.add(e.getType().name()); + amounts.add(e.getAmount()); + durability.add(e.getDurability()); + } + context.setSessionData(pref + CK.S_PLACE_NAMES, names); + context.setSessionData(pref + CK.S_PLACE_AMOUNTS, amounts); + context.setSessionData(pref + CK.S_PLACE_DURABILITY, durability); } - context.setSessionData(pref + CK.S_CUT_NAMES, names); - context.setSessionData(pref + CK.S_CUT_AMOUNTS, amounts); - context.setSessionData(pref + CK.S_CUT_DURABILITY, durability); - } - if (!stage.getItemsToCraft().isEmpty()) { - final LinkedList items = new LinkedList<>(stage.getItemsToCraft()); - context.setSessionData(pref + CK.S_CRAFT_ITEMS, items); - } - if (!stage.getItemsToSmelt().isEmpty()) { - final LinkedList items = new LinkedList<>(stage.getItemsToSmelt()); - context.setSessionData(pref + CK.S_SMELT_ITEMS, items); - } - if (!stage.getItemsToEnchant().isEmpty()) { - final LinkedList items = new LinkedList<>(stage.getItemsToEnchant()); - context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items); - } - if (!stage.getItemsToBrew().isEmpty()) { - final LinkedList items = new LinkedList<>(stage.getItemsToBrew()); - context.setSessionData(pref + CK.S_BREW_ITEMS, items); - } - if (!stage.getItemsToConsume().isEmpty()) { - final LinkedList items = new LinkedList<>(stage.getItemsToConsume()); - context.setSessionData(pref + CK.S_CONSUME_ITEMS, items); - } - if (stage.getCowsToMilk() != null) { - context.setSessionData(pref + CK.S_COW_MILK, stage.getCowsToMilk()); - } - if (stage.getFishToCatch() != null) { - context.setSessionData(pref + CK.S_FISH, stage.getFishToCatch()); - } - if (stage.getPlayersToKill() != null) { - context.setSessionData(pref + CK.S_PLAYER_KILL, stage.getPlayersToKill()); - } - if (!stage.getItemsToDeliver().isEmpty()) { - final LinkedList items = new LinkedList<>(stage.getItemsToDeliver()); - final LinkedList npcs = new LinkedList<>(stage.getItemDeliveryTargets()); - context.setSessionData(pref + CK.S_DELIVERY_ITEMS, items); - context.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs); - context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, stage.getDeliverMessages()); - } - if (!stage.getCitizensToInteract().isEmpty()) { - final LinkedList npcs = new LinkedList<>(stage.getCitizensToInteract()); - context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs); - } - if (!stage.getCitizensToKill().isEmpty()) { - final LinkedList npcs = new LinkedList<>(stage.getCitizensToKill()); - context.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs); - context.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, stage.getCitizenNumToKill()); - } - if (!stage.getMobsToKill().isEmpty()) { - final LinkedList mobs = new LinkedList<>(); - for (final EntityType et : stage.getMobsToKill()) { - mobs.add(MiscUtil.getPrettyMobName(et)); + if (!stage.getBlocksToUse().isEmpty()) { + final LinkedList names = new LinkedList<>(); + final LinkedList amounts = new LinkedList<>(); + final LinkedList durability = new LinkedList<>(); + for (final ItemStack e : stage.getBlocksToUse()) { + names.add(e.getType().name()); + amounts.add(e.getAmount()); + durability.add(e.getDurability()); + } + context.setSessionData(pref + CK.S_USE_NAMES, names); + context.setSessionData(pref + CK.S_USE_AMOUNTS, amounts); + context.setSessionData(pref + CK.S_USE_DURABILITY, durability); } - context.setSessionData(pref + CK.S_MOB_TYPES, mobs); - context.setSessionData(pref + CK.S_MOB_AMOUNTS, stage.getMobNumToKill()); - if (!stage.getLocationsToKillWithin().isEmpty()) { + if (!stage.getBlocksToCut().isEmpty()) { + final LinkedList names = new LinkedList<>(); + final LinkedList amounts = new LinkedList<>(); + final LinkedList durability = new LinkedList<>(); + for (final ItemStack e : stage.getBlocksToCut()) { + names.add(e.getType().name()); + amounts.add(e.getAmount()); + durability.add(e.getDurability()); + } + context.setSessionData(pref + CK.S_CUT_NAMES, names); + context.setSessionData(pref + CK.S_CUT_AMOUNTS, amounts); + context.setSessionData(pref + CK.S_CUT_DURABILITY, durability); + } + if (!stage.getItemsToCraft().isEmpty()) { + final LinkedList items = new LinkedList<>(stage.getItemsToCraft()); + context.setSessionData(pref + CK.S_CRAFT_ITEMS, items); + } + if (!stage.getItemsToSmelt().isEmpty()) { + final LinkedList items = new LinkedList<>(stage.getItemsToSmelt()); + context.setSessionData(pref + CK.S_SMELT_ITEMS, items); + } + if (!stage.getItemsToEnchant().isEmpty()) { + final LinkedList items = new LinkedList<>(stage.getItemsToEnchant()); + context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items); + } + if (!stage.getItemsToBrew().isEmpty()) { + final LinkedList items = new LinkedList<>(stage.getItemsToBrew()); + context.setSessionData(pref + CK.S_BREW_ITEMS, items); + } + if (!stage.getItemsToConsume().isEmpty()) { + final LinkedList items = new LinkedList<>(stage.getItemsToConsume()); + context.setSessionData(pref + CK.S_CONSUME_ITEMS, items); + } + if (stage.getCowsToMilk() != null) { + context.setSessionData(pref + CK.S_COW_MILK, stage.getCowsToMilk()); + } + if (stage.getFishToCatch() != null) { + context.setSessionData(pref + CK.S_FISH, stage.getFishToCatch()); + } + if (stage.getPlayersToKill() != null) { + context.setSessionData(pref + CK.S_PLAYER_KILL, stage.getPlayersToKill()); + } + if (!stage.getItemsToDeliver().isEmpty()) { + final LinkedList items = new LinkedList<>(stage.getItemsToDeliver()); + final LinkedList npcs = new LinkedList<>(); + for (UUID uuid : stage.getItemDeliveryTargets()) { + npcs.add(uuid.toString()); + } + context.setSessionData(pref + CK.S_DELIVERY_ITEMS, items); + context.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs); + context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, stage.getDeliverMessages()); + } + if (!stage.getNpcsToInteract().isEmpty()) { + final LinkedList npcs = new LinkedList<>(); + for (UUID uuid : stage.getNpcsToInteract()) { + npcs.add(uuid.toString()); + } + context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs); + } + if (!stage.getNpcsToKill().isEmpty()) { + final LinkedList npcs = new LinkedList<>(); + for (UUID uuid : stage.getNpcsToKill()) { + npcs.add(uuid.toString()); + } + context.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs); + context.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, stage.getNpcNumToKill()); + } + if (!stage.getMobsToKill().isEmpty()) { + final LinkedList mobs = new LinkedList<>(); + for (final EntityType et : stage.getMobsToKill()) { + mobs.add(MiscUtil.getPrettyMobName(et)); + } + context.setSessionData(pref + CK.S_MOB_TYPES, mobs); + context.setSessionData(pref + CK.S_MOB_AMOUNTS, stage.getMobNumToKill()); + if (!stage.getLocationsToKillWithin().isEmpty()) { + final LinkedList locations = new LinkedList<>(); + for (final Location l : stage.getLocationsToKillWithin()) { + locations.add(ConfigUtil.getLocationInfo(l)); + } + context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS, locations); + context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS, stage.getRadiiToKillWithin()); + context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, stage.getKillNames()); + } + } + if (!stage.getLocationsToReach().isEmpty()) { final LinkedList locations = new LinkedList<>(); - for (final Location l : stage.getLocationsToKillWithin()) { + for (final Location l : stage.getLocationsToReach()) { locations.add(ConfigUtil.getLocationInfo(l)); } - context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS, locations); - context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS, stage.getRadiiToKillWithin()); - context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, stage.getKillNames()); + context.setSessionData(pref + CK.S_REACH_LOCATIONS, locations); + context.setSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS, stage.getRadiiToReachWithin()); + context.setSessionData(pref + CK.S_REACH_LOCATIONS_NAMES, stage.getLocationNames()); } - } - if (!stage.getLocationsToReach().isEmpty()) { - final LinkedList locations = new LinkedList<>(); - for (final Location l : stage.getLocationsToReach()) { - locations.add(ConfigUtil.getLocationInfo(l)); + if (!stage.getMobsToTame().isEmpty()) { + final LinkedList mobs = new LinkedList<>(); + for (final EntityType e : stage.getMobsToTame()) { + mobs.add(MiscUtil.getPrettyMobName(e)); + } + final LinkedList amounts = new LinkedList<>(stage.getMobNumToTame()); + context.setSessionData(pref + CK.S_TAME_TYPES, mobs); + context.setSessionData(pref + CK.S_TAME_AMOUNTS, amounts); } - context.setSessionData(pref + CK.S_REACH_LOCATIONS, locations); - context.setSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS, stage.getRadiiToReachWithin()); - context.setSessionData(pref + CK.S_REACH_LOCATIONS_NAMES, stage.getLocationNames()); - } - if (!stage.getMobsToTame().isEmpty()) { - final LinkedList mobs = new LinkedList<>(); - for (final EntityType e : stage.getMobsToTame()) { - mobs.add(MiscUtil.getPrettyMobName(e)); - } - final LinkedList amounts = new LinkedList<>(stage.getMobNumToTame()); - context.setSessionData(pref + CK.S_TAME_TYPES, mobs); - context.setSessionData(pref + CK.S_TAME_AMOUNTS, amounts); - } - if (!stage.getSheepToShear().isEmpty()) { - final LinkedList colors = new LinkedList<>(); - for (final DyeColor d : stage.getSheepToShear()) { - colors.add(MiscUtil.getPrettyDyeColorName(d)); + if (!stage.getSheepToShear().isEmpty()) { + final LinkedList colors = new LinkedList<>(); + for (final DyeColor d : stage.getSheepToShear()) { + colors.add(MiscUtil.getPrettyDyeColorName(d)); + } + final LinkedList amounts = new LinkedList<>(stage.getSheepNumToShear()); + context.setSessionData(pref + CK.S_SHEAR_COLORS, colors); + context.setSessionData(pref + CK.S_SHEAR_AMOUNTS, amounts); } - final LinkedList amounts = new LinkedList<>(stage.getSheepNumToShear()); - context.setSessionData(pref + CK.S_SHEAR_COLORS, colors); - context.setSessionData(pref + CK.S_SHEAR_AMOUNTS, amounts); - } - if (!stage.getPasswordDisplays().isEmpty()) { - context.setSessionData(pref + CK.S_PASSWORD_DISPLAYS, stage.getPasswordDisplays()); - context.setSessionData(pref + CK.S_PASSWORD_PHRASES, stage.getPasswordPhrases()); - } - if (!stage.getCustomObjectives().isEmpty()) { - final LinkedList list = new LinkedList<>(); - final LinkedList countList = new LinkedList<>(); - for (int i = 0; i < stage.getCustomObjectives().size(); i++) { - list.add(stage.getCustomObjectives().get(i).getName()); - countList.add(stage.getCustomObjectiveCounts().get(i)); + if (!stage.getPasswordDisplays().isEmpty()) { + context.setSessionData(pref + CK.S_PASSWORD_DISPLAYS, stage.getPasswordDisplays()); + context.setSessionData(pref + CK.S_PASSWORD_PHRASES, stage.getPasswordPhrases()); } - final LinkedList> dataMapList = new LinkedList<>(stage.getCustomObjectiveData()); - context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list); - context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT, countList); - context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, dataMapList); - } - if (stage.getStartAction() != null) { - context.setSessionData(pref + CK.S_START_EVENT, stage.getStartAction().getName()); - } - if (stage.getFinishAction() != null) { - context.setSessionData(pref + CK.S_FINISH_EVENT, stage.getFinishAction().getName()); - } - if (stage.getFailAction() != null) { - context.setSessionData(pref + CK.S_FAIL_EVENT, stage.getFailAction().getName()); - } - if (stage.getDeathAction() != null) { - context.setSessionData(pref + CK.S_DEATH_EVENT, stage.getDeathAction().getName()); - } - if (stage.getDisconnectAction() != null) { - context.setSessionData(pref + CK.S_DISCONNECT_EVENT, stage.getDisconnectAction().getName()); - } - if (!stage.getChatActions().isEmpty()) { - final LinkedList chatEvents = new LinkedList<>(); - final LinkedList chatEventTriggers = new LinkedList<>(); - for (final String s : stage.getChatActions().keySet()) { - chatEventTriggers.add(s); - chatEvents.add(stage.getChatActions().get(s).getName()); + if (!stage.getCustomObjectives().isEmpty()) { + final LinkedList list = new LinkedList<>(); + final LinkedList countList = new LinkedList<>(); + for (int i = 0; i < stage.getCustomObjectives().size(); i++) { + list.add(stage.getCustomObjectives().get(i).getName()); + countList.add(stage.getCustomObjectiveCounts().get(i)); + } + final LinkedList> dataMapList = new LinkedList<>(stage.getCustomObjectiveData()); + context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list); + context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT, countList); + context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, dataMapList); } - context.setSessionData(pref + CK.S_CHAT_EVENTS, chatEvents); - context.setSessionData(pref + CK.S_CHAT_EVENT_TRIGGERS, chatEventTriggers); - } - if (!stage.getCommandActions().isEmpty()) { - final LinkedList commandEvents = new LinkedList<>(); - final LinkedList commandEventTriggers = new LinkedList<>(); - for (final String s : stage.getCommandActions().keySet()) { - commandEventTriggers.add(s); - commandEvents.add(stage.getCommandActions().get(s).getName()); + if (stage.getStartAction() != null) { + context.setSessionData(pref + CK.S_START_EVENT, stage.getStartAction().getName()); } - context.setSessionData(pref + CK.S_COMMAND_EVENTS, commandEvents); - context.setSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS, commandEventTriggers); - } - if (stage.getCondition() != null) { - context.setSessionData(pref + CK.S_CONDITION, stage.getCondition().getName()); - } - if (stage.getDelay() != -1) { - context.setSessionData(pref + CK.S_DELAY, stage.getDelay()); - if (stage.getDelayMessage() != null) { - context.setSessionData(pref + CK.S_DELAY_MESSAGE, stage.getDelayMessage()); + if (stage.getFinishAction() != null) { + context.setSessionData(pref + CK.S_FINISH_EVENT, stage.getFinishAction().getName()); + } + if (stage.getFailAction() != null) { + context.setSessionData(pref + CK.S_FAIL_EVENT, stage.getFailAction().getName()); + } + if (stage.getDeathAction() != null) { + context.setSessionData(pref + CK.S_DEATH_EVENT, stage.getDeathAction().getName()); + } + if (stage.getDisconnectAction() != null) { + context.setSessionData(pref + CK.S_DISCONNECT_EVENT, stage.getDisconnectAction().getName()); + } + if (!stage.getChatActions().isEmpty()) { + final LinkedList chatEvents = new LinkedList<>(); + final LinkedList chatEventTriggers = new LinkedList<>(); + for (final String s : stage.getChatActions().keySet()) { + chatEventTriggers.add(s); + chatEvents.add(stage.getChatActions().get(s).getName()); + } + context.setSessionData(pref + CK.S_CHAT_EVENTS, chatEvents); + context.setSessionData(pref + CK.S_CHAT_EVENT_TRIGGERS, chatEventTriggers); + } + if (!stage.getCommandActions().isEmpty()) { + final LinkedList commandEvents = new LinkedList<>(); + final LinkedList commandEventTriggers = new LinkedList<>(); + for (final String s : stage.getCommandActions().keySet()) { + commandEventTriggers.add(s); + commandEvents.add(stage.getCommandActions().get(s).getName()); + } + context.setSessionData(pref + CK.S_COMMAND_EVENTS, commandEvents); + context.setSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS, commandEventTriggers); + } + if (stage.getCondition() != null) { + context.setSessionData(pref + CK.S_CONDITION, stage.getCondition().getName()); + } + if (stage.getDelay() != -1) { + context.setSessionData(pref + CK.S_DELAY, stage.getDelay()); + if (stage.getDelayMessage() != null) { + context.setSessionData(pref + CK.S_DELAY_MESSAGE, stage.getDelayMessage()); + } + } + if (stage.getScript() != null) { + context.setSessionData(pref + CK.S_DENIZEN, stage.getScript()); + } + if (stage.getCompleteMessage() != null) { + context.setSessionData(pref + CK.S_COMPLETE_MESSAGE, stage.getCompleteMessage()); + } + if (stage.getStartMessage() != null) { + context.setSessionData(pref + CK.S_START_MESSAGE, stage.getStartMessage()); + } + if (!stage.getObjectiveOverrides().isEmpty()) { + context.setSessionData(pref + CK.S_OVERRIDE_DISPLAY, stage.getObjectiveOverrides()); } } - if (stage.getScript() != null) { - context.setSessionData(pref + CK.S_DENIZEN, stage.getScript()); - } - if (stage.getCompleteMessage() != null) { - context.setSessionData(pref + CK.S_COMPLETE_MESSAGE, stage.getCompleteMessage()); - } - if (stage.getStartMessage() != null) { - context.setSessionData(pref + CK.S_START_MESSAGE, stage.getStartMessage()); - } - if (!stage.getObjectiveOverrides().isEmpty()) { - context.setSessionData(pref + CK.S_OVERRIDE_DISPLAY, stage.getObjectiveOverrides()); - } + } catch (Exception e) { + e.printStackTrace(); } } @@ -585,7 +598,7 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi ? context.getSessionData(CK.Q_ASK_MESSAGE) : null); section.set("finish-message", context.getSessionData(CK.Q_FINISH_MESSAGE) != null ? context.getSessionData(CK.Q_FINISH_MESSAGE) : null); - section.set("npc-giver-id", context.getSessionData(CK.Q_START_NPC) != null + section.set("npc-giver-uuid", context.getSessionData(CK.Q_START_NPC) != null ? context.getSessionData(CK.Q_START_NPC) : null); section.set("block-start", context.getSessionData(CK.Q_START_BLOCK) != null ? ConfigUtil.getLocationInfo((Location) Objects.requireNonNull(context @@ -710,13 +723,13 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi ? context.getSessionData(pref + CK.S_PLAYER_KILL) : null); stage.set("items-to-deliver", context.getSessionData(pref + CK.S_DELIVERY_ITEMS) != null ? context.getSessionData(pref + CK.S_DELIVERY_ITEMS) : null); - stage.set("npc-delivery-ids", context.getSessionData(pref + CK.S_DELIVERY_NPCS) != null + stage.set("npc-delivery-uuids", context.getSessionData(pref + CK.S_DELIVERY_NPCS) != null ? context.getSessionData(pref + CK.S_DELIVERY_NPCS) : null); stage.set("delivery-messages", context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) != null ? context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) : null); - stage.set("npc-ids-to-talk-to", context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) != null + stage.set("npc-uuids-to-talk-to", context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) != null ? context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) : null); - stage.set("npc-ids-to-kill", context.getSessionData(pref + CK.S_NPCS_TO_KILL) != null + stage.set("npc-uuids-to-kill", context.getSessionData(pref + CK.S_NPCS_TO_KILL) != null ? context.getSessionData(pref + CK.S_NPCS_TO_KILL) : null); stage.set("npc-kill-amounts", context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS) != null ? context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS) : null); diff --git a/core/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java b/core/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java index 5517a8309..96450f487 100644 --- a/core/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java +++ b/core/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java @@ -314,14 +314,24 @@ public class SeparatedYamlStorage implements StorageImplementation { } if (questSec.contains("has-talked-to")) { final List talkAmount = questSec.getBooleanList("has-talked-to"); - quester.getQuestData(quest).setCitizensInteracted(new LinkedList<>(talkAmount)); + quester.getQuestData(quest).setNpcsInteracted(new LinkedList<>(talkAmount)); } - if (questSec.contains("citizen-amounts-killed")) { - final List citizensAmounts = questSec.getIntegerList("citizen-amounts-killed"); + if (questSec.contains("npc-killed-amounts")) { + final List npcAmounts = questSec.getIntegerList("npc-killed-amounts"); int index = 0; - for (final int amt : citizensAmounts) { - if (quester.getQuestData(quest).getCitizensNumKilled().size() > 0) { - quester.getQuestData(quest).citizensNumKilled.set(index, amt); + for (final int amt : npcAmounts) { + if (quester.getQuestData(quest).getNpcsNumKilled().size() > 0) { + quester.getQuestData(quest).npcsNumKilled.set(index, amt); + } + index++; + } + } else if (questSec.contains("citizen-amounts-killed")) { + // Legacy + final List npcAmounts = questSec.getIntegerList("citizen-amounts-killed"); + int index = 0; + for (final int amt : npcAmounts) { + if (quester.getQuestData(quest).getNpcsNumKilled().size() > 0) { + quester.getQuestData(quest).npcsNumKilled.set(index, amt); } index++; } diff --git a/core/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java b/core/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java index b798d36ee..760de8a8c 100644 --- a/core/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java +++ b/core/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java @@ -371,8 +371,8 @@ public class SqlStorage implements StorageImplementation { ps.setString(11, serializeItemStackProgress(entry.getValue().getItemsBrewed())); ps.setString(12, serializeItemStackProgress(entry.getValue().getItemsConsumed())); ps.setString(13, serializeItemStackProgress(entry.getValue().getItemsDelivered())); - ps.setString(14, serializeProgress(entry.getValue().getCitizensInteracted())); - ps.setString(15, serializeProgress(entry.getValue().getCitizensNumKilled())); + ps.setString(14, serializeProgress(entry.getValue().getNpcsInteracted())); + ps.setString(15, serializeProgress(entry.getValue().getNpcsNumKilled())); ps.setString(16, serializeProgress(entry.getValue().getMobNumKilled())); ps.setString(17, serializeProgress(entry.getValue().getMobsTamed())); ps.setInt(18, entry.getValue().getFishCaught()); @@ -483,8 +483,8 @@ public class SqlStorage implements StorageImplementation { quester.getCurrentStage(quest).getItemsToConsume())); data.itemsDelivered.addAll(deserializeItemStackProgress(rs.getString("items_delivered"), quester.getCurrentStage(quest).getItemsToDeliver())); - data.citizensInteracted.addAll(deserializeBooleanProgress(rs.getString("npcs_interacted"))); - data.citizensNumKilled.addAll(deserializeIntProgress(rs.getString("npcs_killed"))); + data.npcsInteracted.addAll(deserializeBooleanProgress(rs.getString("npcs_interacted"))); + data.npcsNumKilled.addAll(deserializeIntProgress(rs.getString("npcs_killed"))); data.mobNumKilled.addAll(deserializeIntProgress(rs.getString("mobs_killed"))); data.mobsTamed.addAll(deserializeIntProgress(rs.getString("mobs_tamed"))); data.setFishCaught(rs.getInt("fish_caught")); diff --git a/core/src/main/resources/strings.yml b/core/src/main/resources/strings.yml index 8b22de6b3..1d5a33055 100644 --- a/core/src/main/resources/strings.yml +++ b/core/src/main/resources/strings.yml @@ -69,7 +69,8 @@ questEditorDefaultFinishMessage: "Well done!" questEditorEnterQuestName: "Enter quest name, " questEditorEnterAskMessage: "Enter ask message, " questEditorEnterFinishMessage: "Enter finish message, " -questEditorEnterNPCStart: "Enter NPC ID, , " +questEditorEnterNPCStart: "Enter NPC UUID, , " +questEditorClickNPCStart: "Click on a NPC, , " questEditorEnterBlockStart: "Right-click on a block to use as a start point, , , " questDungeonsCreate: "Players added to this group may perform quests together!" questDungeonsDisband: "The quest group was disbanded." @@ -167,7 +168,6 @@ stageEditorSetEnchantAmounts: "Set enchant amounts" stageEditorSetMobAmounts: "Set mob amounts" stageEditorSetEnchantments: "Set enchantments" stageEditorSetItemNames: "Set item names" -stageEditorSetKillIds: "Set NPC IDs" stageEditorSetMobTypes: "Set mob types" stageEditorSetKillLocations: "Set kill locations" stageEditorSetKillLocationRadii: "Set kill location radii" @@ -199,8 +199,6 @@ stageEditorKillPlayerPrompt: "Enter number of players to kill, , stageEditorEnchantTypePrompt: "Enter enchantment names, , " stageEditorEnchantAmountsPrompt: "Enter enchant amounts (numbers), , " stageEditorItemNamesPrompt: "Enter item names, , " -stageEditorNPCPrompt: "Enter NPC IDs, , " -stageEditorNPCToTalkToPrompt: "Enter NPC IDs, , , " stageEditorDeliveryMessagesPrompt: "Enter delivery messages, , " stageEditorKillNPCsPrompt: "Enter kill amounts (numbers), , " stageEditorMobsPrompt: "Enter mob names, , " @@ -227,12 +225,12 @@ stageEditorCompleteMessagePrompt: "Enter complete message, , " stageEditorPasswordDisplayPrompt: "Enter password hints, , " stageEditorPasswordPhrasePrompt: "Enter password phrases, , " stageEditorDeliveryAddItem: "Add item" -stageEditorDeliveryNPCs: "Set NPC IDs" +stageEditorNPCUniqueIds: "Add NPC UUIDs" stageEditorDeliveryMessages: "Set partial delivery messages" stageEditorNotSolid: "is not a solid block!" stageEditorInvalidBlockName: "is not a valid block name!" stageEditorInvalidEnchantment: "is not a valid enchantment name!" -stageEditorInvalidNPC: "is not a valid NPC ID!" +stageEditorInvalidNPC: "is not a valid NPC UUID!" stageEditorInvalidMob: "is not a valid mob name!" stageEditorInvalidItemName: "is not a valid item name!" stageEditorInvalidDye: "is not a valid dye color!" @@ -243,7 +241,8 @@ stageEditorInvalidScript: "Denizen script not found!" stageEditorNoCitizens: "Citizens is not installed!" stageEditorNoDenizen: "Denizen is not installed!" stageEditorPositiveAmount: "You must enter a positive number!" -stageEditorNotListofNumbers: "is not a list of numbers!" +stageEditorNotListOfNumbers: " is not a list of numbers!" +stageEditorNotListOfUniqueIds: " is not a list of valid UUIDs!" stageEditorNoDelaySet: "You must set a delay first!" stageEditorNoItems: "You must add items first!" stageEditorNoDeliveryMessage: "You must set at least one delivery message!" @@ -404,7 +403,6 @@ conditionEditorRideNPC: "Ride NPC" conditionEditorEntitiesTitle: "- Entities -" conditionEditorEntitiesPrompt: "Enter entity names, , " conditionEditorNpcsTitle: "- NPCs -" -conditionEditorNpcsPrompt: "Enter NPC IDs, , " conditionEditorPermissions: "Own permission" conditionEditorPermissionsPrompt: "Enter permission nodes, , " conditionEditorItemsInMainHand: "Hold in main hand" @@ -467,6 +465,7 @@ reqHeroesNotSecondary: "The class is not secondary!" reqHeroesSecondaryCleared: "Heroes Secondary Class requirement cleared." reqHeroesClassNotFound: "Class not found!" reqNotANumber: " is not a number!" +reqNotAUniqueId: " is not a valid UUID!" reqMustAddItem: "You must add at least one item first!" reqNoMessage: "You must set a fail requirements message!" plnStart: "Set start date" @@ -774,7 +773,8 @@ noIdsSet: "No IDs set" noNamesSet: "No names set" worlds: "Worlds" points: "points" -npcHint: "Note: You can click on NPCs to get their ID." +enterNpcUniqueIds: "Enter NPC UUIDs, , " +enterOrClearNpcUniqueIds: "Enter NPC UUIDs, , , " listsNotSameSize: "All required lists must have the same number of entries!" listDuplicate: "List contains duplicates!" id: "ID" diff --git a/dist/pom.xml b/dist/pom.xml index 68d9c63b2..5053e0a7b 100644 --- a/dist/pom.xml +++ b/dist/pom.xml @@ -5,7 +5,7 @@ me.blackvein.quests quests-parent - 4.3.1 + 4.4.0 quests-dist pom diff --git a/pom.xml b/pom.xml index e10f69c30..9dd6a36e1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,12 +6,12 @@ me.blackvein.quests quests-parent - 4.3.1 + 4.4.0 quests https://github.com/PikaMug/Quests/ - 4.3.1 + 4.4.0 UTF-8 1.8 1.8 diff --git a/v1_8_R1/pom.xml b/v1_8_R1/pom.xml index 42b0a7137..40fada9bf 100644 --- a/v1_8_R1/pom.xml +++ b/v1_8_R1/pom.xml @@ -6,7 +6,7 @@ me.blackvein.quests quests-parent - 4.3.1 + 4.4.0 diff --git a/v1_8_R2/pom.xml b/v1_8_R2/pom.xml index aab145e89..e322fd6ae 100644 --- a/v1_8_R2/pom.xml +++ b/v1_8_R2/pom.xml @@ -6,7 +6,7 @@ me.blackvein.quests quests-parent - 4.3.1 + 4.4.0 diff --git a/v1_8_R3/pom.xml b/v1_8_R3/pom.xml index f3dd421f5..dd6a886ea 100644 --- a/v1_8_R3/pom.xml +++ b/v1_8_R3/pom.xml @@ -6,7 +6,7 @@ me.blackvein.quests quests-parent - 4.3.1 + 4.4.0