diff --git a/api/src/main/java/me/blackvein/quests/player/IQuester.java b/api/src/main/java/me/blackvein/quests/player/IQuester.java index ab48a6197..0a1df8fc1 100644 --- a/api/src/main/java/me/blackvein/quests/player/IQuester.java +++ b/api/src/main/java/me/blackvein/quests/player/IQuester.java @@ -52,8 +52,9 @@ public interface IQuester extends Comparable { * Get compass target quest. Returns null if not set * * @return Quest or null + * @deprecated Do not use */ - IQuest getCompassTarget(); + IQuest getCompassTargetTemp(); /** * Set compass target quest. Does not update in-game @@ -75,7 +76,10 @@ public interface IQuester extends Comparable { void setCurrentQuests(final ConcurrentHashMap currentQuests); - ConcurrentSkipListSet getCompletedQuests(); + /** + * @deprecated Do not use + */ + ConcurrentSkipListSet getCompletedQuestsTemp(); void setCompletedQuests(final ConcurrentSkipListSet completedQuests); 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 ccd4867c9..39ca0bdc5 100644 --- a/api/src/main/java/me/blackvein/quests/quests/IStage.java +++ b/api/src/main/java/me/blackvein/quests/quests/IStage.java @@ -305,6 +305,13 @@ public interface IStage { */ boolean hasObjective(); + /** + * Check if stage has at least one objective of which the target can be located easily

+ * + * @return true if stage contains a locatable objective + */ + boolean hasLocatableObjective(); + /** * Check if stage has the specified type of objective

* diff --git a/core/src/main/java/me/blackvein/quests/Quest.java b/core/src/main/java/me/blackvein/quests/Quest.java index 4d8df69c3..63ed18745 100644 --- a/core/src/main/java/me/blackvein/quests/Quest.java +++ b/core/src/main/java/me/blackvein/quests/Quest.java @@ -420,13 +420,13 @@ public class Quest implements IQuest { } /** - * Set location-objective target for compass.

+ * Attempt to set location-objective target for compass.

* * Method may be called as often as needed. * * @param quester The online quester to have their compass updated * @param stage The stage to process for targets - * @return true if an attempt was made successfully + * @return true if quester is online and has permission */ public boolean updateCompass(final IQuester quester, final IStage stage) { if (quester == null) { @@ -551,6 +551,7 @@ public class Quest implements IQuest { if (event.isCancelled()) { return; } + quester.setCompassTarget(this); quester.getPlayer().setCompassTarget(lockedTarget); } } @@ -588,11 +589,11 @@ public class Quest implements IQuest { if (quester.getQuestPoints() < requirements.getQuestPoints()) { return false; } - if (!quester.getCompletedQuests().containsAll(requirements.getNeededQuests())) { + if (!quester.getCompletedQuestsTemp().containsAll(requirements.getNeededQuests())) { return false; } for (final IQuest q : requirements.getBlockQuests()) { - if (quester.getCompletedQuests().contains(q) || quester.getCurrentQuestsTemp().containsKey(q)) { + if (quester.getCompletedQuestsTemp().contains(q) || quester.getCurrentQuestsTemp().containsKey(q)) { return false; } } @@ -697,7 +698,7 @@ public class Quest implements IQuest { return; } quester.hardQuit(this); - quester.getCompletedQuests().add(this); + quester.getCompletedQuestsTemp().add(this); for (final Map.Entry entry : quester.getTimers().entrySet()) { if (entry.getValue().getName().equals(getName())) { plugin.getServer().getScheduler().cancelTask(entry.getKey()); diff --git a/core/src/main/java/me/blackvein/quests/Quester.java b/core/src/main/java/me/blackvein/quests/Quester.java index 1405efa37..4896fe841 100644 --- a/core/src/main/java/me/blackvein/quests/Quester.java +++ b/core/src/main/java/me/blackvein/quests/Quester.java @@ -303,25 +303,37 @@ public class Quester implements IQuester { public void setQuestPoints(final int questPoints) { this.questPoints = questPoints; } - + /** * Get compass target quest. Returns null if not set - * + * * @return Quest or null */ - @Override - public IQuest getCompassTarget() { + public Quest getCompassTarget() { return compassTargetQuestId != null ? plugin.getQuestById(compassTargetQuestId) : null; } - + + /** + * Get compass target quest. Returns null if not set + * + * @return Quest or null + * @deprecated Do not use + */ + @Override + public IQuest getCompassTargetTemp() { + return compassTargetQuestId != null ? plugin.getQuestByIdTemp(compassTargetQuestId) : null; + } + /** * Set compass target quest. Does not update in-game - * + * * @param quest The target quest */ @Override public void setCompassTarget(final IQuest quest) { - compassTargetQuestId = quest.getId(); + if (quest != null) { + compassTargetQuestId = quest.getId(); + } } @Override @@ -361,8 +373,20 @@ public class Quester implements IQuester { this.currentQuests = currentQuests; } + public ConcurrentSkipListSet getCompletedQuests() { + final ConcurrentSkipListSet set = new ConcurrentSkipListSet<>(); + for (IQuest iq : completedQuests) { + final Quest q = (Quest) iq; + set.add(q); + } + return set; + } + + /** + * @deprecated Do not use + */ @Override - public ConcurrentSkipListSet getCompletedQuests() { + public ConcurrentSkipListSet getCompletedQuestsTemp() { return completedQuests; } @@ -554,7 +578,7 @@ public class Quester implements IQuester { sendMessage(ChatColor.YELLOW + msg); } return false; - } else if (getCompletedQuests().contains(quest) && quest.getPlanner().getCooldown() < 0) { + } else if (getCompletedQuestsTemp().contains(quest) && quest.getPlanner().getCooldown() < 0) { if (giveReason) { final String msg = Lang.get(getPlayer(), "questAlreadyCompleted") .replace("", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.YELLOW); @@ -582,7 +606,7 @@ public class Quester implements IQuester { sendMessage(ChatColor.YELLOW + msg); } return false; - } else if (getCompletedQuests().contains(quest) && getRemainingCooldown(quest) > 0 + } else if (getCompletedQuestsTemp().contains(quest) && getRemainingCooldown(quest) > 0 && !quest.getPlanner().getOverride()) { if (giveReason) { final String msg = Lang.get(getPlayer(), "questTooEarly").replace("", ChatColor.AQUA @@ -833,8 +857,9 @@ public class Quester implements IQuester { if (stage.getStartAction() != null) { stage.getStartAction().fire(this, quest); } - quest.updateCompass(this, stage); saveData(); + setCompassTarget(quest); + quest.updateCompass(this, stage); } else { if (offlinePlayer.isOnline()) { sendMessage(ChatColor.DARK_AQUA + Lang.get("requirements")); @@ -972,7 +997,7 @@ public class Quester implements IQuester { } for (final IQuest q : requirements.getNeededQuests()) { if (q != null) { - if (getCompletedQuests().contains(q)) { + if (getCompletedQuestsTemp().contains(q)) { finishedRequirements.add(ChatColor.GREEN + q.getName()); } else { unfinishedRequirements.add(ChatColor.GRAY + q.getName()); @@ -4149,7 +4174,13 @@ public class Quester implements IQuester { } for (final IQuest quest : currentQuests.keySet()) { final IStage stage = getCurrentStage(quest); - if (stage != null && quest.updateCompass(this, stage)) { + if (stage != null) { + if (stage.hasLocatableObjective()) { + quest.updateCompass(this, stage); + } else { + resetCompass(); + setCompassTarget(quest); + } break; } } @@ -4179,14 +4210,23 @@ public class Quester implements IQuester { } } if (list.size() > 0) { - final IQuest quest = plugin.getQuestById(list.get(index)); + final IQuest quest = plugin.getQuestByIdTemp(list.get(index)); compassTargetQuestId = quest.getId(); final IStage stage = getCurrentStage(quest); if (stage != null) { - quest.updateCompass(Quester.this, stage); - if (notify) { - sendMessage(ChatColor.YELLOW + Lang.get(getPlayer(), "compassSet") - .replace("", ChatColor.GOLD + quest.getName() + ChatColor.YELLOW)); + if (stage.hasLocatableObjective()) { + quest.updateCompass(Quester.this, stage); + if (notify) { + sendMessage(ChatColor.YELLOW + Lang.get(getPlayer(), "compassSet") + .replace("", ChatColor.GOLD + quest.getName() + ChatColor.YELLOW)); + } + } else { + resetCompass(); + setCompassTarget(quest); + if (notify) { + sendMessage(ChatColor.RED + Lang.get(getPlayer(), "compassNone") + .replace("", ChatColor.GRAY + quest.getName() + ChatColor.RED)); + } } } } else { diff --git a/core/src/main/java/me/blackvein/quests/Quests.java b/core/src/main/java/me/blackvein/quests/Quests.java index 3b7a12fbc..837c25cac 100644 --- a/core/src/main/java/me/blackvein/quests/Quests.java +++ b/core/src/main/java/me/blackvein/quests/Quests.java @@ -693,13 +693,13 @@ public class Quests extends JavaPlugin implements QuestsAPI { } final String questIdToTake = quester.getQuestIdToTake(); try { - if (getQuestById(questIdToTake) == null) { + if (getQuestByIdTemp(questIdToTake) == null) { getLogger().info(player.getName() + " attempted to take quest ID \"" + questIdToTake + "\" but something went wrong"); player.sendMessage(ChatColor.RED + "Something went wrong! Please report issue to an administrator."); } else { - getQuester(player.getUniqueId()).takeQuest(getQuestById(questIdToTake), false); + getQuester(player.getUniqueId()).takeQuest(getQuestByIdTemp(questIdToTake), false); } } catch (final Exception e) { e.printStackTrace(); @@ -934,7 +934,7 @@ public class Quests extends JavaPlugin implements QuestsAPI { for (final String questKey : questsSection.getKeys(false)) { try { if (config.contains("quests." + questKey)) { - loadCustomSections(getQuestById(questKey), config, questKey); + loadCustomSections(getQuestByIdTemp(questKey), config, questKey); } else { throw new QuestFormatException("Unable to load custom sections", questKey); } @@ -1596,7 +1596,7 @@ public class Quests extends JavaPlugin implements QuestsAPI { if (getSettings().canIgnoreLockedQuests()) { final LinkedList available = new LinkedList<>(); for (final IQuest q : quests) { - if (!quester.getCompletedQuests().contains(q)) { + if (!quester.getCompletedQuestsTemp().contains(q)) { if (q.testRequirements(player)) { available.add(q); } @@ -2167,10 +2167,10 @@ public class Quests extends JavaPlugin implements QuestsAPI { final String node2 = config.getString("quests." + id + ".name"); if (node2 != null && (id.equals(node) || node2.equalsIgnoreCase(node) || ChatColor.stripColor(node2).equalsIgnoreCase(ChatColor.stripColor(node)))) { - if (getQuest(node) != null) { - temp.add(getQuest(node)); - } else if (getQuestById(node) != null) { - temp.add(getQuestById(node)); + if (getQuestTemp(node) != null) { + temp.add(getQuestTemp(node)); + } else if (getQuestByIdTemp(node) != null) { + temp.add(getQuestByIdTemp(node)); } else { throw new QuestFormatException("Requirement quest-blocks has unknown quest name/id " + node + ", place it earlier in file so it loads first", questKey); @@ -2206,10 +2206,10 @@ public class Quests extends JavaPlugin implements QuestsAPI { final String node2 = config.getString("quests." + id + ".name"); if (node2 != null && (id.equals(node) || node2.equalsIgnoreCase(node) || ChatColor.stripColor(node2).equalsIgnoreCase(ChatColor.stripColor(node)))) { - if (getQuest(node) != null) { - temp.add(getQuest(node)); - } else if (getQuestById(node) != null) { - temp.add(getQuestById(node)); + if (getQuestTemp(node) != null) { + temp.add(getQuestTemp(node)); + } else if (getQuestByIdTemp(node) != null) { + temp.add(getQuestByIdTemp(node)); } else { throw new QuestFormatException("Requirement quests has unknown quest name " + node + ", place it earlier in file so it loads first", questKey); @@ -4225,15 +4225,36 @@ public class Quests extends JavaPlugin implements QuestsAPI { } return player.hasPermission("quests.mode.trial"); } - + + /** + * Get a Quest by ID + * + * @param id ID of the quest + * @return Exact match or null if not found + * @since 3.8.6 + */ + public Quest getQuestById(final String id) { + if (id == null) { + return null; + } + for (final IQuest iq : quests) { + final Quest q = (Quest) iq; + if (q.getId().equals(id)) { + return q; + } + } + return null; + } + /** * Get a Quest by ID * * @param id ID of the quest * @return Exact match or null if not found * @since 3.8.6 + * @deprecated Do not use */ - public IQuest getQuestById(final String id) { + public IQuest getQuestByIdTemp(final String id) { if (id == null) { return null; } @@ -4244,6 +4265,37 @@ public class Quests extends JavaPlugin implements QuestsAPI { } return null; } + + /** + * Get a Quest by name + * + * @param name Name of the quest + * @return Closest match or null if not found + */ + public Quest getQuest(final String name) { + if (name == null) { + return null; + } + for (final IQuest iq : quests) { + final Quest q = (Quest) iq; + if (q.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) { + return q; + } + } + for (final IQuest iq : quests) { + final Quest q = (Quest) iq; + if (q.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { + return q; + } + } + for (final IQuest iq : quests) { + final Quest q = (Quest) iq; + if (q.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { + return q; + } + } + return null; + } /** * Get a Quest by name @@ -4251,7 +4303,7 @@ public class Quests extends JavaPlugin implements QuestsAPI { * @param name Name of the quest * @return Closest match or null if not found */ - public IQuest getQuest(final String name) { + public IQuest getQuestTemp(final String name) { if (name == null) { return null; } @@ -4338,7 +4390,7 @@ public class Quests extends JavaPlugin implements QuestsAPI { */ public boolean hasQuest(final NPC npc, final IQuester quester) { for (final IQuest q : quests) { - if (q.getNpcStart() != null && !quester.getCompletedQuests().contains(q)) { + if (q.getNpcStart() != null && !quester.getCompletedQuestsTemp().contains(q)) { if (q.getNpcStart().getId() == npc.getId()) { final boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); if (!ignoreLockedQuests || q.testRequirements(quester)) { @@ -4360,7 +4412,7 @@ public class Quests extends JavaPlugin implements QuestsAPI { */ public boolean hasCompletedQuest(final NPC npc, final IQuester quester) { for (final IQuest q : quests) { - if (q.getNpcStart() != null && quester.getCompletedQuests().contains(q)) { + if (q.getNpcStart() != null && quester.getCompletedQuestsTemp().contains(q)) { if (q.getNpcStart().getId() == npc.getId()) { final boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); if (!ignoreLockedQuests || q.testRequirements(quester)) { @@ -4381,7 +4433,7 @@ public class Quests extends JavaPlugin implements QuestsAPI { */ public boolean hasCompletedRedoableQuest(final NPC npc, final IQuester quester) { for (final IQuest q : quests) { - if (q.getNpcStart() != null && quester.getCompletedQuests().contains(q) + if (q.getNpcStart() != null && quester.getCompletedQuestsTemp().contains(q) && q.getPlanner().getCooldown() > -1) { if (q.getNpcStart().getId() == npc.getId()) { final boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); diff --git a/core/src/main/java/me/blackvein/quests/Stage.java b/core/src/main/java/me/blackvein/quests/Stage.java index 5e6ecd488..6cd0caa64 100644 --- a/core/src/main/java/me/blackvein/quests/Stage.java +++ b/core/src/main/java/me/blackvein/quests/Stage.java @@ -763,11 +763,29 @@ public class Stage implements IStage { if (!citizensToInteract.isEmpty()) { return true; } if (!citizensToKill.isEmpty()) { return true; } if (!locationsToReach.isEmpty()) { return true; } + if (!mobsToKill.isEmpty()) {return true; } if (!mobsToTame.isEmpty()) { return true; } if (!sheepToShear.isEmpty()) { return true; } if (!passwordDisplays.isEmpty()) { return true; } return !customObjectives.isEmpty(); } + + /** + * Check if stage has at least one objective of which the target can be easily located

+ * + * @return true if stage contains a locatable objective + */ + public boolean hasLocatableObjective() { + if (!citizensToInteract.isEmpty()) { return true; } + if (!citizensToKill.isEmpty()) { return true; } + if (!locationsToReach.isEmpty()) { return true; } + if (!itemDeliveryTargets.isEmpty()) { return true; } + if (playersToKill != null) { return true; } + if (!mobsToKill.isEmpty()) {return true; } + if (!mobsToTame.isEmpty()) { return true; } + if (!sheepToShear.isEmpty()) { return true; } + return false; + } /** * Check if stage has the specified type of objective

diff --git a/core/src/main/java/me/blackvein/quests/convo/misc/NpcOfferQuestPrompt.java b/core/src/main/java/me/blackvein/quests/convo/misc/NpcOfferQuestPrompt.java index 70af0c193..5cff1205a 100644 --- a/core/src/main/java/me/blackvein/quests/convo/misc/NpcOfferQuestPrompt.java +++ b/core/src/main/java/me/blackvein/quests/convo/misc/NpcOfferQuestPrompt.java @@ -71,7 +71,7 @@ public class NpcOfferQuestPrompt extends MiscStringPrompt { if (quests != null && number > 0) { if (number < (quests.size() + 1)) { final IQuest quest = quests.get(number - 1); - if (quester.getCompletedQuests().contains(quest)) { + if (quester.getCompletedQuestsTemp().contains(quest)) { return ChatColor.GREEN; } else { return ChatColor.GOLD; @@ -94,7 +94,7 @@ public class NpcOfferQuestPrompt extends MiscStringPrompt { if (quests != null && number > 0) { if (number < (quests.size() + 1)) { final IQuest quest = quests.get(number - 1); - if (quester.getCompletedQuests().contains(quest)) { + if (quester.getCompletedQuestsTemp().contains(quest)) { return ChatColor.GREEN + "" + ChatColor.ITALIC + quest.getName(); } else { return ChatColor.YELLOW + "" + ChatColor.ITALIC + quest.getName(); @@ -116,7 +116,7 @@ public class NpcOfferQuestPrompt extends MiscStringPrompt { if (quests != null && number > 0) { if (number < (quests.size() + 1)) { final IQuest quest = quests.get(number - 1); - if (quester.getCompletedQuests().contains(quest)) { + if (quester.getCompletedQuestsTemp().contains(quest)) { return ChatColor.GREEN + "" + Lang.get("redoCompleted"); } } @@ -240,7 +240,7 @@ public class NpcOfferQuestPrompt extends MiscStringPrompt { } private String extracted(final Quests plugin, final IQuester quester) { - final IQuest quest = plugin.getQuestById(quester.getQuestIdToTake()); + final IQuest quest = plugin.getQuestByIdTemp(quester.getQuestIdToTake()); return MessageFormat.format("{0}- {1}{2}{3} -\n\n{4}{5}\n", ChatColor.GOLD, ChatColor.DARK_PURPLE, quest.getName(), ChatColor.GOLD, ChatColor.RESET, quest.getDescription()); } diff --git a/core/src/main/java/me/blackvein/quests/convo/misc/QuestAbandonPrompt.java b/core/src/main/java/me/blackvein/quests/convo/misc/QuestAbandonPrompt.java index f8500824b..9e08e17f9 100644 --- a/core/src/main/java/me/blackvein/quests/convo/misc/QuestAbandonPrompt.java +++ b/core/src/main/java/me/blackvein/quests/convo/misc/QuestAbandonPrompt.java @@ -107,7 +107,7 @@ public class QuestAbandonPrompt extends MiscStringPrompt { } final String questIdToQuit = quester.getQuestIdToQuit(); try { - IQuest quest = plugin.getQuestById(questIdToQuit); + IQuest quest = plugin.getQuestByIdTemp(questIdToQuit); if (quest == null) { plugin.getLogger().info(player.getName() + " attempted to quit quest ID \"" + questIdToQuit + "\" but something went wrong"); @@ -116,7 +116,7 @@ public class QuestAbandonPrompt extends MiscStringPrompt { } else { final String msg = ChatColor.YELLOW + Lang.get("questQuit").replace("", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.YELLOW); - quester.quitQuest(plugin.getQuestById(questIdToQuit), msg); + quester.quitQuest(plugin.getQuestByIdTemp(questIdToQuit), msg); } } catch (final Exception e) { e.printStackTrace(); diff --git a/core/src/main/java/me/blackvein/quests/convo/quests/menu/QuestMenuPrompt.java b/core/src/main/java/me/blackvein/quests/convo/quests/menu/QuestMenuPrompt.java index 969c280d0..fd52f2c38 100644 --- a/core/src/main/java/me/blackvein/quests/convo/quests/menu/QuestMenuPrompt.java +++ b/core/src/main/java/me/blackvein/quests/convo/quests/menu/QuestMenuPrompt.java @@ -231,7 +231,7 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt { return null; } if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) { - final IQuest q = plugin.getQuest(input); + final IQuest q = plugin.getQuestTemp(input); if (q != null) { plugin.getQuestFactory().loadQuest(context, q); return new QuestMainPrompt(context); @@ -275,7 +275,7 @@ public class QuestMenuPrompt extends QuestsEditorNumericPrompt { } if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) { final LinkedList used = new LinkedList<>(); - final IQuest found = plugin.getQuest(input); + final IQuest found = plugin.getQuestTemp(input); if (found != null) { for (final IQuest q : plugin.getLoadedQuests()) { if (q.getRequirements().getNeededQuests().contains(q) diff --git a/core/src/main/java/me/blackvein/quests/convo/quests/requirements/RequirementsPrompt.java b/core/src/main/java/me/blackvein/quests/convo/quests/requirements/RequirementsPrompt.java index ed4e7ce0f..7583da192 100644 --- a/core/src/main/java/me/blackvein/quests/convo/quests/requirements/RequirementsPrompt.java +++ b/core/src/main/java/me/blackvein/quests/convo/quests/requirements/RequirementsPrompt.java @@ -222,8 +222,8 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt { final List questReq = (List) context.getSessionData(CK.REQ_QUEST); if (questReq != null) { for (String s : questReq) { - if (plugin.getQuestById(s) != null) { - s = plugin.getQuestById(s).getName(); + if (plugin.getQuestByIdTemp(s) != null) { + s = plugin.getQuestByIdTemp(s).getName(); } text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s); } @@ -238,8 +238,8 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt { final List questBlockReq = (List) context.getSessionData(CK.REQ_QUEST_BLOCK); if (questBlockReq != null) { for (String s : questBlockReq) { - if (plugin.getQuestById(s) != null) { - s = plugin.getQuestById(s).getName(); + if (plugin.getQuestByIdTemp(s) != null) { + s = plugin.getQuestByIdTemp(s).getName(); } text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s); } @@ -877,17 +877,17 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt { final String[] args = input.split(Lang.get("charSemi")); final LinkedList questIds = new LinkedList<>(); for (final String s : args) { - if (plugin.getQuest(s) == null) { + if (plugin.getQuestTemp(s) == null) { String text = Lang.get("reqNotAQuestName"); text = text.replace("", ChatColor.LIGHT_PURPLE + s + ChatColor.RED); context.getForWhom().sendRawMessage(text); return new RequirementsQuestListPrompt(context, isRequiredQuest); } - if (questIds.contains(plugin.getQuest(s).getId())) { + if (questIds.contains(plugin.getQuestTemp(s).getId())) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listDuplicate")); return new RequirementsQuestListPrompt(context, isRequiredQuest); } - questIds.add(plugin.getQuest(s).getId()); + questIds.add(plugin.getQuestTemp(s).getId()); } if (isRequiredQuest) { context.setSessionData(CK.REQ_QUEST, questIds); diff --git a/core/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java b/core/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java index 91cacc14e..24eda1b54 100644 --- a/core/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/core/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -344,7 +344,7 @@ public class CmdExecutor implements CommandExecutor { index++; } } - final IQuest q = plugin.getQuest(name.toString()); + final IQuest q = plugin.getQuestTemp(name.toString()); if (q != null) { final Player player = (Player) cs; final IQuester quester = plugin.getQuester(player.getUniqueId()); @@ -437,7 +437,7 @@ public class CmdExecutor implements CommandExecutor { } if (!reqs.getNeededQuests().isEmpty()) { for (final IQuest quest : reqs.getNeededQuests()) { - if (quester.getCompletedQuests().contains(quest)) { + if (quester.getCompletedQuestsTemp().contains(quest)) { cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + Lang.get("complete") + " " + ChatColor.ITALIC + quest.getName()); } else { @@ -448,7 +448,7 @@ public class CmdExecutor implements CommandExecutor { } if (!reqs.getBlockQuests().isEmpty()) { for (final IQuest quest : reqs.getBlockQuests()) { - if (quester.getCompletedQuests().contains(quest)) { + if (quester.getCompletedQuestsTemp().contains(quest)) { String msg = Lang.get("haveCompleted"); msg = msg.replace("", ChatColor.ITALIC + "" + ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED); @@ -630,18 +630,18 @@ public class CmdExecutor implements CommandExecutor { } cs.sendMessage(ChatColor.YELLOW + Lang.get("completedQuest")); - if (quester.getCompletedQuests().isEmpty()) { + if (quester.getCompletedQuestsTemp().isEmpty()) { cs.sendMessage(ChatColor.DARK_PURPLE + Lang.get("none")); } else { final StringBuilder completed = new StringBuilder(" "); int index = 1; - for (final IQuest q : quester.getCompletedQuests()) { + for (final IQuest q : quester.getCompletedQuestsTemp()) { completed.append(ChatColor.DARK_PURPLE).append(q.getName()); if (quester.getAmountsCompleted().containsKey(q) && quester.getAmountsCompleted().get(q) > 1) { completed.append(ChatColor.LIGHT_PURPLE).append(" (x").append(quester.getAmountsCompleted() .get(q)).append(")"); } - if (index < (quester.getCompletedQuests().size())) { + if (index < (quester.getCompletedQuestsTemp().size())) { completed.append(", "); } index++; @@ -698,7 +698,7 @@ public class CmdExecutor implements CommandExecutor { } final IQuester quester = plugin.getQuester(player.getUniqueId()); if (!quester.getCurrentQuestsTemp().isEmpty()) { - final IQuest quest = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' ')); + final IQuest quest = plugin.getQuestTemp(concatArgArray(args, 1, args.length - 1, ' ')); if (quest != null) { if (quest.getOptions().canAllowQuitting()) { final String msg = ChatColor.YELLOW + Lang.get("questQuit").replace("", @@ -724,7 +724,7 @@ public class CmdExecutor implements CommandExecutor { if (args.length == 1) { Lang.send(player, ChatColor.YELLOW + Lang.get(player, "COMMAND_TAKE_USAGE")); } else { - final IQuest questToFind = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' ')); + final IQuest questToFind = plugin.getQuestTemp(concatArgArray(args, 1, args.length - 1, ' ')); final IQuester quester = plugin.getQuester(player.getUniqueId()); if (questToFind != null) { for (final IQuest q : quester.getCurrentQuestsTemp().keySet()) { @@ -1049,7 +1049,7 @@ public class CmdExecutor implements CommandExecutor { } } } - questToGive = plugin.getQuest(name.toString()); + questToGive = plugin.getQuestTemp(name.toString()); if (questToGive == null) { cs.sendMessage(ChatColor.YELLOW + Lang.get("questNotFound")); } else { @@ -1160,7 +1160,7 @@ public class CmdExecutor implements CommandExecutor { msg = msg.replace("", target.getName()); cs.sendMessage(ChatColor.YELLOW + msg); } else { - final IQuest quest = plugin.getQuest(concatArgArray(args, 2, args.length - 1, ' ')); + final IQuest quest = plugin.getQuestTemp(concatArgArray(args, 2, args.length - 1, ' ')); if (quest == null) { cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); return; @@ -1212,7 +1212,7 @@ public class CmdExecutor implements CommandExecutor { msg = msg.replace("", target.getName()); cs.sendMessage(ChatColor.YELLOW + msg); } else { - final IQuest quest = plugin.getQuest(concatArgArray(args, 2, args.length - 2, ' ')); + final IQuest quest = plugin.getQuestTemp(concatArgArray(args, 2, args.length - 2, ' ')); if (quest == null) { cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); return; @@ -1248,7 +1248,7 @@ public class CmdExecutor implements CommandExecutor { msg = msg.replace("", target.getName()); cs.sendMessage(ChatColor.YELLOW + msg); } else { - final IQuest quest = plugin.getQuest(concatArgArray(args, 2, args.length - 1, ' ')); + final IQuest quest = plugin.getQuestTemp(concatArgArray(args, 2, args.length - 1, ' ')); if (quest == null) { cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); return; @@ -1289,7 +1289,7 @@ public class CmdExecutor implements CommandExecutor { msg = msg.replace("", target.getName()); cs.sendMessage(ChatColor.YELLOW + msg); } else { - final IQuest quest = plugin.getQuest(concatArgArray(args, 2, args.length - 1, ' ')); + final IQuest quest = plugin.getQuestTemp(concatArgArray(args, 2, args.length - 1, ' ')); if (quest == null) { cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); return; @@ -1325,6 +1325,7 @@ public class CmdExecutor implements CommandExecutor { plugin.setOfflineQuesters(temp); IQuester quester = plugin.getQuester(id); try { + quester.resetCompass(); quester.hardClear(); quester.saveData(); quester.updateJournal(); @@ -1370,7 +1371,7 @@ public class CmdExecutor implements CommandExecutor { return; } } - final IQuest toRemove = plugin.getQuest(concatArgArray(args, 2, args.length - 1, ' ')); + final IQuest toRemove = plugin.getQuestTemp(concatArgArray(args, 2, args.length - 1, ' ')); if (toRemove == null) { cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); return; 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 0c0de107f..bd90e3dd4 100644 --- a/core/src/main/java/me/blackvein/quests/listeners/NpcListener.java +++ b/core/src/main/java/me/blackvein/quests/listeners/NpcListener.java @@ -202,7 +202,7 @@ public class NpcListener implements Listener { continue; if (q.getNpcStart() != null && q.getNpcStart().getId() == evt.getNPC().getId()) { if (plugin.getSettings().canIgnoreLockedQuests() - && (!quester.getCompletedQuests().contains(q) + && (!quester.getCompletedQuestsTemp().contains(q) || q.getPlanner().getCooldown() > -1)) { if (q.testRequirements(quester)) { npcQuests.add(q); @@ -210,7 +210,7 @@ public class NpcListener implements Listener { hasAtLeastOneGUI = true; } } - } else if (!quester.getCompletedQuests().contains(q) || q.getPlanner().getCooldown() > -1) { + } else if (!quester.getCompletedQuestsTemp().contains(q) || q.getPlanner().getCooldown() > -1) { npcQuests.add(q); if (q.getGUIDisplay() != null) { hasAtLeastOneGUI = true; @@ -313,7 +313,7 @@ public class NpcListener implements Listener { } private String extracted(final IQuester quester) { - final IQuest quest = plugin.getQuestById(quester.getQuestIdToTake()); + final IQuest quest = plugin.getQuestByIdTemp(quester.getQuestIdToTake()); return MessageFormat.format("{0}- {1}{2}{3} -\n\n{4}{5}\n", ChatColor.GOLD, ChatColor.DARK_PURPLE, quest.getName(), ChatColor.GOLD, ChatColor.RESET, quest.getDescription()); } diff --git a/core/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/core/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index faba956d2..c3327d51d 100644 --- a/core/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/core/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -374,7 +374,7 @@ public class PlayerListener implements Listener { .valueOf(plugin.getSettings().getMaxQuests())); Lang.send(player, ChatColor.YELLOW + msg); } else { - if (quester.getCompletedQuests().contains(q)) { + if (quester.getCompletedQuestsTemp().contains(q)) { if (q.getPlanner().getCooldown() > -1 && (quester.getRemainingCooldown(q)) > 0) { String early = Lang.get(player, "questTooEarly"); @@ -385,7 +385,7 @@ public class PlayerListener implements Listener { + ChatColor.YELLOW); Lang.send(player, ChatColor.YELLOW + early); continue; - } else if (quester.getCompletedQuests().contains(q) + } else if (quester.getCompletedQuestsTemp().contains(q) && q.getPlanner().getCooldown() < 0) { String completed = Lang.get(player, "questAlreadyCompleted"); completed = completed.replace("", ChatColor.AQUA @@ -398,7 +398,7 @@ public class PlayerListener implements Listener { if (!plugin.getSettings().canAskConfirmation()) { quester.takeQuest(q, false); } else { - final IQuest quest = plugin.getQuestById(quester.getQuestIdToTake()); + final IQuest quest = plugin.getQuestByIdTemp(quester.getQuestIdToTake()); final String s = ChatColor.GOLD + "- " + ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GOLD + " -\n" + "\n" + ChatColor.RESET + quest.getDescription() + "\n"; @@ -878,7 +878,7 @@ public class PlayerListener implements Listener { if (quester == null) { return; } - for (final IQuest q : quester.getCompletedQuests()) { + for (final IQuest q : quester.getCompletedQuestsTemp()) { if (q != null) { if (!quester.getCompletedTimes().containsKey(q) && q.getPlanner().getCooldown() > -1) { quester.getCompletedTimes().put(q, System.currentTimeMillis()); @@ -898,7 +898,7 @@ public class PlayerListener implements Listener { quester.updateJournal(); } if (quester.canUseCompass()) { - quester.resetCompass(); + quester.findCompassTarget(); } }, 40L); } catch (final Exception e) { 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 b843f04ae..02bbc3660 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 @@ -90,11 +90,11 @@ public class SeparatedYamlStorage implements StorageImplementation { final List questTimes = data.getLongList("completedQuestTimes"); final ConcurrentHashMap completedTimes = quester.getCompletedTimes(); for (int i = 0; i < questIds.size(); i++) { - if (plugin.getQuestById(questIds.get(i)) != null) { - completedTimes.put(plugin.getQuestById(questIds.get(i)), questTimes.get(i)); - } else if (plugin.getQuest(questIds.get(i)) != null) { + if (plugin.getQuestByIdTemp(questIds.get(i)) != null) { + completedTimes.put(plugin.getQuestByIdTemp(questIds.get(i)), questTimes.get(i)); + } else if (plugin.getQuestTemp(questIds.get(i)) != null) { // Legacy - completedTimes.put(plugin.getQuest(questIds.get(i)), questTimes.get(i)); + completedTimes.put(plugin.getQuestTemp(questIds.get(i)), questTimes.get(i)); } } quester.setCompletedTimes(completedTimes); @@ -104,29 +104,29 @@ public class SeparatedYamlStorage implements StorageImplementation { final List questAmounts = data.getIntegerList("amountsCompleted"); final ConcurrentHashMap amountsCompleted = quester.getAmountsCompleted(); for (int i = 0; i < questIds.size(); i++) { - if (plugin.getQuestById(questIds.get(i)) != null) { - amountsCompleted.put(plugin.getQuestById(questIds.get(i)), questAmounts.get(i)); - } else if (plugin.getQuest(questIds.get(i)) != null) { + if (plugin.getQuestByIdTemp(questIds.get(i)) != null) { + amountsCompleted.put(plugin.getQuestByIdTemp(questIds.get(i)), questAmounts.get(i)); + } else if (plugin.getQuestTemp(questIds.get(i)) != null) { // Legacy - amountsCompleted.put(plugin.getQuest(questIds.get(i)), questAmounts.get(i)); + amountsCompleted.put(plugin.getQuestTemp(questIds.get(i)), questAmounts.get(i)); } } quester.setAmountsCompleted(amountsCompleted); } quester.setLastKnownName(data.getString("lastKnownName")); quester.setQuestPoints(data.getInt("quest-points")); - final ConcurrentSkipListSet completedQuests = quester.getCompletedQuests(); + final ConcurrentSkipListSet completedQuests = quester.getCompletedQuestsTemp(); if (data.isList("completed-Quests")) { for (final String s : data.getStringList("completed-Quests")) { for (final IQuest q : plugin.getLoadedQuests()) { if (q.getId().equals(s)) { - if (!quester.getCompletedQuests().contains(q)) { + if (!quester.getCompletedQuestsTemp().contains(q)) { completedQuests.add(q); } break; } else if (q.getName().equalsIgnoreCase(s)) { // Legacy - if (!quester.getCompletedQuests().contains(q)) { + if (!quester.getCompletedQuestsTemp().contains(q)) { completedQuests.add(q); } break; @@ -141,11 +141,11 @@ public class SeparatedYamlStorage implements StorageImplementation { final int maxSize = Math.min(questIds.size(), questStages.size()); final ConcurrentHashMap currentQuests = quester.getCurrentQuestsTemp(); for (int i = 0; i < maxSize; i++) { - if (plugin.getQuestById(questIds.get(i)) != null) { - currentQuests.put(plugin.getQuestById(questIds.get(i)), questStages.get(i)); - } else if (plugin.getQuest(questIds.get(i)) != null) { + if (plugin.getQuestByIdTemp(questIds.get(i)) != null) { + currentQuests.put(plugin.getQuestByIdTemp(questIds.get(i)), questStages.get(i)); + } else if (plugin.getQuestTemp(questIds.get(i)) != null) { // Legacy - currentQuests.put(plugin.getQuest(questIds.get(i)), questStages.get(i)); + currentQuests.put(plugin.getQuestTemp(questIds.get(i)), questStages.get(i)); } } quester.setCurrentQuests(currentQuests); @@ -155,7 +155,7 @@ public class SeparatedYamlStorage implements StorageImplementation { } for (final String key : dataSec.getKeys(false)) { final ConfigurationSection questSec = dataSec.getConfigurationSection(key); - final IQuest quest = plugin.getQuestById(key) != null ? plugin.getQuestById(key) : plugin.getQuest(key); + final IQuest quest = plugin.getQuestByIdTemp(key) != null ? plugin.getQuestByIdTemp(key) : plugin.getQuestTemp(key); if (quest == null || !quester.getCurrentQuestsTemp().containsKey(quest)) { continue; } 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 4f8d148c8..ba7b8c0c5 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 @@ -255,7 +255,7 @@ public class SqlStorage implements StorageImplementation { final Set currentQuests = quester.getCurrentQuestsTemp().keySet().stream().map(IQuest::getId).collect(Collectors.toSet()); final Set oldCurrentQuests = getQuesterCurrentQuests(uniqueId).keySet().stream().map(IQuest::getId).collect(Collectors.toSet()); oldCurrentQuests.removeAll(currentQuests); - final Set completedQuests = quester.getCompletedQuests().stream().map(IQuest::getId).collect(Collectors.toSet()); + final Set completedQuests = quester.getCompletedQuestsTemp().stream().map(IQuest::getId).collect(Collectors.toSet()); final Set oldCompletedQuests = getQuesterCompletedQuests(uniqueId).stream().map(IQuest::getId).collect(Collectors.toSet()); oldCompletedQuests.removeAll(completedQuests); final Set redoableQuests = quester.getCompletedTimes().keySet().stream().map(IQuest::getId).collect(Collectors.toSet()); @@ -309,7 +309,7 @@ public class SqlStorage implements StorageImplementation { } } } else { - for (final IQuest quest : quester.getCompletedQuests()) { + for (final IQuest quest : quester.getCompletedQuestsTemp()) { try (final PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_COMPLETED_QUESTS_INSERT))) { ps.setString(1, uniqueId.toString()); ps.setString(2, quest.getId()); @@ -439,7 +439,7 @@ public class SqlStorage implements StorageImplementation { ps.setString(1, uniqueId.toString()); try (final ResultSet rs = ps.executeQuery()) { while (rs.next()) { - final IQuest quest = plugin.getQuestById(rs.getString("questid")); + final IQuest quest = plugin.getQuestByIdTemp(rs.getString("questid")); if (quest != null) { currentQuests.put(quest, rs.getInt("stageNum")); } @@ -458,7 +458,7 @@ public class SqlStorage implements StorageImplementation { ps.setString(1, uniqueId.toString()); try (final ResultSet rs = ps.executeQuery()) { while (rs.next()) { - final IQuest quest = plugin.getQuestById(rs.getString("quest_id")); + final IQuest quest = plugin.getQuestByIdTemp(rs.getString("quest_id")); final QuestData data = new QuestData(quester); if (quest != null && quester.getCurrentStage(quest) != null) { data.blocksBroken.addAll(deserializeItemStackProgress(rs.getString("blocks_broken"), @@ -512,7 +512,7 @@ public class SqlStorage implements StorageImplementation { ps.setString(1, uniqueId.toString()); try (final ResultSet rs = ps.executeQuery()) { while (rs.next()) { - final IQuest quest = plugin.getQuestById(rs.getString("questid")); + final IQuest quest = plugin.getQuestByIdTemp(rs.getString("questid")); if (quest != null) { completedQuests.add(quest); } @@ -530,7 +530,7 @@ public class SqlStorage implements StorageImplementation { ps.setString(1, uniqueId.toString()); try (final ResultSet rs = ps.executeQuery()) { while (rs.next()) { - final IQuest quest = plugin.getQuestById(rs.getString("questid")); + final IQuest quest = plugin.getQuestByIdTemp(rs.getString("questid")); if (quest != null) { completedTimes.put(quest, rs.getLong("lasttime")); } @@ -548,7 +548,7 @@ public class SqlStorage implements StorageImplementation { ps.setString(1, uniqueId.toString()); try (final ResultSet rs = ps.executeQuery()) { while (rs.next()) { - final IQuest quest = plugin.getQuestById(rs.getString("questid")); + final IQuest quest = plugin.getQuestByIdTemp(rs.getString("questid")); if (quest != null) { amountsCompleted.put(quest, rs.getInt("amount")); } diff --git a/core/src/main/resources/strings.yml b/core/src/main/resources/strings.yml index 54d16c616..d9aca6981 100644 --- a/core/src/main/resources/strings.yml +++ b/core/src/main/resources/strings.yml @@ -737,6 +737,7 @@ journalNoRoom: "You have no room in your inventory for your !" journalNoQuests: "You have no accepted quests!" journalDenied: "You cannot do that with your ." compassSet: "Set compass target to quest ." +compassNone: "No compass target for quest ." compassReset: "Reset compass target." timeZone: "Time zone" timeDay: "Day"