Class PlayerQuests
java.lang.Object
com.ordwen.odailyquests.quests.player.PlayerQuests
Represents the player's quests and their associated data.
This class keeps track of the quests a player has completed, including the total number of completed quests, quests achieved in each category, and handles quest progression and rerolling of quests.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionPlayerQuests(Long timestamp, Map<AbstractQuest, Progression> quests) Constructs a new PlayerQuests object with the provided timestamp and a map of quests with their progress. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRecentReroll(int i) Add number of recent rolled quests.voidaddTotalAchievedQuests(int i) Add number of achieved quests.voidaddTotalCategoryAchievedQuests(String category, int amount) Add the number of achieved quests for a specific category.voidDecreases the number of achieved quests by 1.intGet number of achieved quests.Get player quests.intGet number of recently rolled quests.Gets the player's timestamp.intGet total number of achieved quests.Get total achieved quests for all categories.intgetTotalAchievedQuestsByCategory(String category) Get the number of total achieved quests for a specific category.voidincreaseCategoryAchievedQuests(String category, org.bukkit.entity.Player player) Increases the number of achieved quests for a given category.voidremoveTotalAchievedQuests(int i) Remove number of achieved quests.voidremoveTotalCategoryAchievedQuests(String category, int amount) Subtract the number of achieved quests for a specific category.booleanrerollQuest(int index, org.bukkit.entity.Player player, boolean bypassMax) Rerolls a quest for the player at the given index.voidsetAchievedQuests(int i) Set number of achieved quests.setQuestAtIndex(int index, AbstractQuest newQuest) Replaces the quest stored at the provided index with a new quest instance.voidsetRecentRerolls(int recentRerolls) Set number of recently rerolled quests.voidsetTotalAchievedQuests(int i) Set total number of achieved quests.voidsetTotalAchievedQuestsByCategory(Map<String, Integer> totals) Set total achieved quests for all categories.voidsetTotalCategoryAchievedQuests(String category, int i) Set total number of achieved quests for a specific category.
-
Constructor Details
-
PlayerQuests
Constructs a new PlayerQuests object with the provided timestamp and a map of quests with their progress.- Parameters:
timestamp- the last time the player's quests were renewed.quests- a map of quests and their respective progression.
-
-
Method Details
-
getTimestamp
Gets the player's timestamp.- Returns:
- the timestamp of the player's last quest renew.
-
increaseCategoryAchievedQuests
Increases the number of achieved quests for a given category.If all quests from the category are completed, the
AllCategoryQuestsCompletedEventis triggered. If the player has completed all quests, theAllQuestsCompletedEventis triggered.- Parameters:
category- the category of the quest completed.player- the player who achieved the quest.
-
rerollQuest
public boolean rerollQuest(int index, org.bukkit.entity.Player player, boolean bypassMax) Rerolls a quest for the player at the given index.Workflow:
- Read the quest at
indexand its progression. - Validate that a reroll is allowed according to configuration and current progression.
- Resolve the quest category and build a working set that excludes the quest being replaced.
- Pick a random replacement quest (not already assigned and permitted for the player).
- Rebuild the ordered map of quests, inserting a fresh progression for the new quest.
- If the removed quest was achieved, update category/global counters accordingly.
Side effects: Mutates this instance's
questsmap, potentially updates achievement counters, and may send feedback messages to the player.- Parameters:
index- zero-based slot of the quest to reroll (must be within bounds of the current ordered keys)player- the player for whom the reroll is performed (used for permission checks and messaging)bypassMax- boolean is true if triggered by an admin, false otherwise (used for bypassing recent reroll logic)- Returns:
trueif the reroll succeeded;falseotherwise (e.g., reroll not allowed, no available quest, or category resolution error)- Throws:
IndexOutOfBoundsException- ifindexis out of range for the current quest list
- Read the quest at
-
setQuestAtIndex
Replaces the quest stored at the provided index with a new quest instance.The newly assigned quest starts with a fresh
Progression, mirroring the behaviour of the daily quest draw. If the replaced quest was already achieved, the player's counters are adjusted accordingly.- Parameters:
index- zero-based index of the quest to replacenewQuest- the quest that should replace the current one- Returns:
- the result of the replacement attempt
-
decreaseAchievedQuests
public void decreaseAchievedQuests()Decreases the number of achieved quests by 1. -
setAchievedQuests
public void setAchievedQuests(int i) Set number of achieved quests.- Parameters:
i- number of achieved quests to set.
-
setTotalAchievedQuests
public void setTotalAchievedQuests(int i) Set total number of achieved quests.- Parameters:
i- total number of achieved quests to set.
-
setRecentRerolls
public void setRecentRerolls(int recentRerolls) Set number of recently rerolled quests.- Parameters:
recentRerolls- total number of rerolled quests to set.
-
setTotalCategoryAchievedQuests
Set total number of achieved quests for a specific category.- Parameters:
category- the category name.i- number of achieved quests to set.
-
setTotalAchievedQuestsByCategory
Set total achieved quests for all categories.- Parameters:
totals- a map of total achieved quests by category.
-
addTotalAchievedQuests
public void addTotalAchievedQuests(int i) Add number of achieved quests.- Parameters:
i- number of achieved quests to add.
-
addRecentReroll
public void addRecentReroll(int i) Add number of recent rolled quests.- Parameters:
i- number of rerolled quests to add.
-
addTotalCategoryAchievedQuests
Add the number of achieved quests for a specific category.- Parameters:
category- the category name.amount- the number of quests to add.
-
removeTotalAchievedQuests
public void removeTotalAchievedQuests(int i) Remove number of achieved quests.- Parameters:
i- number of achieved quests to remove.
-
removeTotalCategoryAchievedQuests
Subtract the number of achieved quests for a specific category.- Parameters:
category- the category name.amount- the number of quests to subtract.
-
getAchievedQuests
public int getAchievedQuests()Get number of achieved quests. -
getTotalAchievedQuests
public int getTotalAchievedQuests()Get total number of achieved quests. -
getRecentlyRolled
public int getRecentlyRolled()Get number of recently rolled quests. -
getQuests
Get player quests.- Returns:
- a LinkedHashMap of quests and their progression.
-
getTotalAchievedQuestsByCategory
Get total achieved quests for all categories.- Returns:
- a map of total achieved quests by category.
-
getTotalAchievedQuestsByCategory
Get the number of total achieved quests for a specific category.- Parameters:
category- the category name.- Returns:
- the number of total achieved quests for the specified category.
-