From 6af64c7eed7ad45425e00123106245dbd4bf684a Mon Sep 17 00:00:00 2001 From: PikaMug Date: Tue, 5 Nov 2019 17:38:04 -0500 Subject: [PATCH] Move related utility methods to dependency class, part 2 --- .../java/me/blackvein/quests/Dependencies.java | 9 +++++++++ .../src/main/java/me/blackvein/quests/Quest.java | 4 ++-- .../main/java/me/blackvein/quests/Quests.java | 16 ++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Dependencies.java b/main/src/main/java/me/blackvein/quests/Dependencies.java index 12d3d15e5..57ee3c731 100644 --- a/main/src/main/java/me/blackvein/quests/Dependencies.java +++ b/main/src/main/java/me/blackvein/quests/Dependencies.java @@ -14,6 +14,7 @@ package me.blackvein.quests; import java.util.UUID; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.RegisteredServiceProvider; @@ -226,6 +227,14 @@ public class Dependencies { return plugin.getDenizenTrigger().runDenizenScript(scriptName, quester); } + public Location getNPCLocation(int id) { + return citizens.getNPCRegistry().getById(id).getStoredLocation(); + } + + public String getNPCName(int id) { + return citizens.getNPCRegistry().getById(id).getName(); + } + public int getMcmmoSkillLevel(SkillType st, String player) { McMMOPlayer mPlayer = UserManager.getPlayer(player); if (mPlayer == null) { diff --git a/main/src/main/java/me/blackvein/quests/Quest.java b/main/src/main/java/me/blackvein/quests/Quest.java index ad0120b0d..3e039696f 100644 --- a/main/src/main/java/me/blackvein/quests/Quest.java +++ b/main/src/main/java/me/blackvein/quests/Quest.java @@ -289,9 +289,9 @@ public class Quest { } Location targetLocation = null; if (nextStage.citizensToInteract != null && nextStage.citizensToInteract.size() > 0) { - targetLocation = plugin.getNPCLocation(nextStage.citizensToInteract.getFirst()); + targetLocation = plugin.getDependencies().getNPCLocation(nextStage.citizensToInteract.getFirst()); } else if (nextStage.citizensToKill != null && nextStage.citizensToKill.size() > 0) { - targetLocation = plugin.getNPCLocation(nextStage.citizensToKill.getFirst()); + targetLocation = plugin.getDependencies().getNPCLocation(nextStage.citizensToKill.getFirst()); } else if (nextStage.locationsToReach != null && nextStage.locationsToReach.size() > 0) { targetLocation = nextStage.locationsToReach.getFirst(); } else if (nextStage.itemDeliveryTargets != null && nextStage.itemDeliveryTargets.size() > 0) { diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index d0aa0e560..6abd223b5 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -3706,12 +3706,18 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener return getAction(name); } + /** + * @deprecated Use Dependencies.getNPCLocation(int) + */ public Location getNPCLocation(int id) { - return depends.getCitizens().getNPCRegistry().getById(id).getStoredLocation(); + return depends.getNPCLocation(id); } + /** + * @deprecated Use Dependencies.getNPCName(int) + */ public String getNPCName(int id) { - return depends.getCitizens().getNPCRegistry().getById(id).getName(); + return depends.getNPCName(id); } public static int countInv(Inventory inv, Material m, int subtract) { @@ -3728,15 +3734,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener /** * Checks whether an NPC has a quest that the player may accept + * * @param npc The giver NPC to check * @param quester The player to check - * @return true if at least one quest is available + * @return true if at least one quest is available and not yet completed */ public boolean hasQuest(NPC npc, Quester quester) { for (Quest q : quests) { - // Return false for expired quests - - // Return true if not yet completed if (q.npcStart != null && quester.completedQuests.contains(q.getName()) == false) { if (q.npcStart.getId() == npc.getId()) { boolean ignoreLockedQuests = settings.canIgnoreLockedQuests();