Class QuestsManager

java.lang.Object
com.storytimeproductions.stweaks.util.QuestsManager

public class QuestsManager extends Object
Manages the lifecycle of quests, including loading from YAML, tracking completed quests per player, and querying quest availability.
  • Constructor Details

    • QuestsManager

      public QuestsManager(DbManager dbManager, org.bukkit.plugin.java.JavaPlugin plugin)
      Constructs a new QuestsManager with the given database manager and plugin instance.
      Parameters:
      dbManager - the database manager for loading/saving completed quests
      plugin - the plugin instance for logging and file access
  • Method Details

    • reloadQuests

      public void reloadQuests()
      Reloads all quests from the YAML file and refreshes the completed quests mapping from the database.
    • getQuestByName

      public String getQuestByName(String name)
      Retrieves a quest by its name.
      Parameters:
      name - the name of the quest
      Returns:
      the Quest object corresponding to the given name, or null if not found
    • hasRequiredItems

      public boolean hasRequiredItems(org.bukkit.entity.Player player, Quest quest)
      Checks if the player has the required items for a specific quest.
      Parameters:
      player - the player to check
      quest - the quest to check against
      Returns:
      true if the player has all required items, false otherwise
    • hasRequiredStats

      public boolean hasRequiredStats(org.bukkit.entity.Player player, Quest quest)
      Checks if the player has met all required statistics for a specific quest.
      Parameters:
      player - the player to check
      quest - the quest to check against
      Returns:
      true if the player meets all stat requirements, false otherwise
    • giveRewards

      public void giveRewards(org.bukkit.entity.Player player, Quest quest)
      Gives the rewards to the player for completing a specific quest.
      Parameters:
      player - the player to whom to give rewards
      quest - the quest for which to give rewards
    • unsetQuestCompletion

      public void unsetQuestCompletion(UUID playerUuid, String questId)
      Unsets the completion status of a quest for a specific player, both in memory and in the database.
      Parameters:
      playerUuid - the UUID of the player
      questId - the ID of the quest to unset completion for
    • getCompletedPlayers

      public List<UUID> getCompletedPlayers(Quest quest)
      Retrieves a list of players who have completed a specific quest.
      Parameters:
      quest - the quest for which to find completed players
      Returns:
      a list of UUIDs representing players who have completed the quest
    • getOpenQuestCount

      public int getOpenQuestCount(UUID playerUuid)
      Returns the number of open quests available to the specified player by username.
      Parameters:
      playerUuid - the UUID of the player
      Returns:
      the number of quests the player has not yet completed
    • getCompletedQuestCount

      public int getCompletedQuestCount(UUID playerUuid)
      Returns the number of quests the player has completed.
      Parameters:
      playerUuid - the UUID of the player
      Returns:
      the number of completed quests
    • getDisplayableQuestIdsFor

      public List<String> getDisplayableQuestIdsFor(UUID playerUuid)
      Returns a list of quest IDs that are visible to the given player. Only quests that are either open to all or explicitly include the player are returned.
      Parameters:
      playerUuid - the UUID of the player
      Returns:
      a list of quest IDs available for display
    • getQuestById

      public Quest getQuestById(String questId)
      Retrieves a quest by its unique identifier.
      Parameters:
      questId - the unique identifier of the quest
      Returns:
      the Quest object corresponding to the given ID, or null if not found
    • isQuestCompleted

      public boolean isQuestCompleted(UUID playerId, String questId)
      Checks if a quest is completed for a specific player. If the quest has required players, it is only considered completed when all required players have completed it.
      Parameters:
      playerId - the UUID of the player
      questId - the ID of the quest
      Returns:
      true if the quest is completed (globally or individually), false otherwise
    • loadQuestsFromYaml

      public void loadQuestsFromYaml()
      Loads all quest definitions from the quests.yml configuration file. Existing quest definitions are cleared before loading.
    • loadCompletedQuestsFromDb

      public void loadCompletedQuestsFromDb()
      Loads the mapping of players to completed quests from the database. This populates the completedQuests map.
    • getAvailableQuestsFor

      public List<Quest> getAvailableQuestsFor(UUID playerUuid)
      Returns a list of quests available to a specific player. These are quests the player has not yet completed and that are either open or explicitly assigned.
      Parameters:
      playerUuid - the UUID of the player
      Returns:
      a list of quests available for the player to complete
    • markQuestCompleted

      public void markQuestCompleted(UUID playerUuid, String questId)
      Marks a quest as completed for a given player and persists the change in the database.
      Parameters:
      playerUuid - the UUID of the player
      questId - the ID of the completed quest