Class PlayerQuests

java.lang.Object
com.ordwen.odailyquests.quests.player.PlayerQuests

public class PlayerQuests extends Object
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.

  • Constructor Details

    • PlayerQuests

      public PlayerQuests(Long timestamp, Map<AbstractQuest,Progression> quests)
      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

      public Long getTimestamp()
      Gets the player's timestamp.
      Returns:
      the timestamp of the player's last quest renew.
    • increaseCategoryAchievedQuests

      public void increaseCategoryAchievedQuests(String category, org.bukkit.entity.Player player)
      Increases the number of achieved quests for a given category.

      If all quests from the category are completed, the AllCategoryQuestsCompletedEvent is triggered. If the player has completed all quests, the AllQuestsCompletedEvent is 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)
      Rerolls a quest for the player at the given index.

      Workflow:

      1. Read the quest at index and its progression.
      2. Validate that a reroll is allowed according to configuration and current progression.
      3. Resolve the quest category and build a working set that excludes the quest being replaced.
      4. Pick a random replacement quest (not already assigned and permitted for the player).
      5. Rebuild the ordered map of quests, inserting a fresh progression for the new quest.
      6. If the removed quest was achieved, update category/global counters accordingly.

      Side effects: Mutates this instance's quests map, 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)
      Returns:
      true if the reroll succeeded; false otherwise (e.g., reroll not allowed, no available quest, or category resolution error)
      Throws:
      IndexOutOfBoundsException - if index is out of range for the current quest list
    • setQuestAtIndex

      public PlayerQuests.ReplaceResult setQuestAtIndex(int index, AbstractQuest newQuest)
      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 replace
      newQuest - 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.
    • setTotalCategoryAchievedQuests

      public void setTotalCategoryAchievedQuests(String category, int i)
      Set total number of achieved quests for a specific category.
      Parameters:
      category - the category name.
      i - number of achieved quests to set.
    • setTotalAchievedQuestsByCategory

      public void setTotalAchievedQuestsByCategory(Map<String,Integer> totals)
      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.
    • addTotalCategoryAchievedQuests

      public void addTotalCategoryAchievedQuests(String category, int amount)
      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

      public void removeTotalCategoryAchievedQuests(String category, int amount)
      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.
    • getQuests

      public Map<AbstractQuest,Progression> getQuests()
      Get player quests.
      Returns:
      a LinkedHashMap of quests and their progression.
    • getTotalAchievedQuestsByCategory

      public Map<String,Integer> getTotalAchievedQuestsByCategory()
      Get total achieved quests for all categories.
      Returns:
      a map of total achieved quests by category.
    • getTotalAchievedQuestsByCategory

      public int getTotalAchievedQuestsByCategory(String category)
      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.