From e0a16aac979aa129227440a05929d89940f632e9 Mon Sep 17 00:00:00 2001 From: LMBishop <13875753+LMBishop@users.noreply.github.com> Date: Tue, 8 Mar 2022 19:41:37 +0000 Subject: Add QPlayer::getEffectiveStartedQuests method --- .../quests/bukkit/hook/papi/QuestsPlaceholders.java | 2 +- .../com/leonardobishop/quests/common/player/QPlayer.java | 12 ++++++++++++ .../common/player/questprogressfile/QuestProgressFile.java | 5 +++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java index 07fc5c53..c2bd60de 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java @@ -96,7 +96,7 @@ public class QuestsPlaceholders extends PlaceholderExpansion implements Cacheabl case "started": case "s": //TODO cache started quests somewhere, or make a effective started method - final List listStarted = plugin.getQuestManager().getQuests().values().stream().filter(qPlayer::hasStartedQuest).collect(Collectors.toList()); + final List listStarted = qPlayer.getEffectiveStartedQuests(); result = (args.length == 1 ? String.valueOf(listStarted.size()) : parseList(listStarted, args[1], split)); break; case "categories": diff --git a/common/src/main/java/com/leonardobishop/quests/common/player/QPlayer.java b/common/src/main/java/com/leonardobishop/quests/common/player/QPlayer.java index d8b40cce..3e775dca 100644 --- a/common/src/main/java/com/leonardobishop/quests/common/player/QPlayer.java +++ b/common/src/main/java/com/leonardobishop/quests/common/player/QPlayer.java @@ -8,8 +8,10 @@ import com.leonardobishop.quests.common.questcontroller.QuestController; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; import java.util.Objects; import java.util.UUID; +import java.util.stream.Collectors; /** * Represents a player. @@ -73,6 +75,16 @@ public class QPlayer { return questController.hasPlayerStartedQuest(this, quest); } + /** + * Gets a list of quests which the player has effectively started. This includes quests started automatically. + * + * @return list of effectively started quests + */ + public List getEffectiveStartedQuests() { + // TODO this can be better + return plugin.getQuestManager().getQuests().values().stream().filter(q -> questController.hasPlayerStartedQuest(this, q)).collect(Collectors.toList()); + } + /** * Attempt to start a quest for the player. This will also play all effects (such as titles, messages etc.) * diff --git a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java index f390c2bd..4a740ee3 100644 --- a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java +++ b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java @@ -39,9 +39,10 @@ public class QuestProgressFile { } /** - * Gets all started quests. + * Gets all manually started quests. * Note: if quest autostart is enabled then this may produce unexpected results as quests are - * not "started" by the player if autostart is true. Consider {@link QPlayer#hasStartedQuest(Quest)} instead. + * not "started" by the player if autostart is true. Consider {@link QPlayer#hasStartedQuest(Quest)} + * or {@link QPlayer#getEffectiveStartedQuests()} instead. * * @return list of started quests */ -- cgit v1.2.3-70-g09d2