Move related utility methods to dependency class, part 2

This commit is contained in:
PikaMug 2019-11-05 17:38:04 -05:00
parent 88f00621c1
commit 6af64c7eed
3 changed files with 21 additions and 8 deletions

View File

@ -14,6 +14,7 @@ package me.blackvein.quests;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
@ -226,6 +227,14 @@ public class Dependencies {
return plugin.getDenizenTrigger().runDenizenScript(scriptName, quester); 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) { public int getMcmmoSkillLevel(SkillType st, String player) {
McMMOPlayer mPlayer = UserManager.getPlayer(player); McMMOPlayer mPlayer = UserManager.getPlayer(player);
if (mPlayer == null) { if (mPlayer == null) {

View File

@ -289,9 +289,9 @@ public class Quest {
} }
Location targetLocation = null; Location targetLocation = null;
if (nextStage.citizensToInteract != null && nextStage.citizensToInteract.size() > 0) { 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) { } 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) { } else if (nextStage.locationsToReach != null && nextStage.locationsToReach.size() > 0) {
targetLocation = nextStage.locationsToReach.getFirst(); targetLocation = nextStage.locationsToReach.getFirst();
} else if (nextStage.itemDeliveryTargets != null && nextStage.itemDeliveryTargets.size() > 0) { } else if (nextStage.itemDeliveryTargets != null && nextStage.itemDeliveryTargets.size() > 0) {

View File

@ -3706,12 +3706,18 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return getAction(name); return getAction(name);
} }
/**
* @deprecated Use Dependencies.getNPCLocation(int)
*/
public Location getNPCLocation(int id) { 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) { 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) { 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 * Checks whether an NPC has a quest that the player may accept
*
* @param npc The giver NPC to check * @param npc The giver NPC to check
* @param quester The player 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) { public boolean hasQuest(NPC npc, Quester quester) {
for (Quest q : quests) { 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 != null && quester.completedQuests.contains(q.getName()) == false) {
if (q.npcStart.getId() == npc.getId()) { if (q.npcStart.getId() == npc.getId()) {
boolean ignoreLockedQuests = settings.canIgnoreLockedQuests(); boolean ignoreLockedQuests = settings.canIgnoreLockedQuests();