Class QuestsManager
java.lang.Object
com.storytimeproductions.stweaks.util.QuestsManager
Manages the lifecycle of quests, including loading from YAML, tracking completed quests per
player, and querying quest availability.
-
Constructor Summary
ConstructorsConstructorDescriptionQuestsManager
(DbManager dbManager, org.bukkit.plugin.java.JavaPlugin plugin) Constructs a new QuestsManager with the given database manager and plugin instance. -
Method Summary
Modifier and TypeMethodDescriptiongetAvailableQuestsFor
(UUID playerUuid) Returns a list of quests available to a specific player.getCompletedPlayers
(Quest quest) Retrieves a list of players who have completed a specific quest.int
getCompletedQuestCount
(UUID playerUuid) Returns the number of quests the player has completed.getDisplayableQuestIdsFor
(UUID playerUuid) Returns a list of quest IDs that are visible to the given player.int
getOpenQuestCount
(UUID playerUuid) Returns the number of open quests available to the specified player by username.getQuestById
(String questId) Retrieves a quest by its unique identifier.getQuestByName
(String name) Retrieves a quest by its name.void
giveRewards
(org.bukkit.entity.Player player, Quest quest) Gives the rewards to the player for completing a specific quest.boolean
hasRequiredItems
(org.bukkit.entity.Player player, Quest quest) Checks if the player has the required items for a specific quest.boolean
hasRequiredStats
(org.bukkit.entity.Player player, Quest quest) Checks if the player has met all required statistics for a specific quest.boolean
isQuestCompleted
(UUID playerId, String questId) Checks if a quest is completed for a specific player.void
Loads the mapping of players to completed quests from the database.void
Loads all quest definitions from the quests.yml configuration file.void
markQuestCompleted
(UUID playerUuid, String questId) Marks a quest as completed for a given player and persists the change in the database.void
Reloads all quests from the YAML file and refreshes the completed quests mapping from the database.void
unsetQuestCompletion
(UUID playerUuid, String questId) Unsets the completion status of a quest for a specific player, both in memory and in the database.
-
Constructor Details
-
QuestsManager
Constructs a new QuestsManager with the given database manager and plugin instance.- Parameters:
dbManager
- the database manager for loading/saving completed questsplugin
- 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
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
Checks if the player has the required items for a specific quest.- Parameters:
player
- the player to checkquest
- the quest to check against- Returns:
- true if the player has all required items, false otherwise
-
hasRequiredStats
Checks if the player has met all required statistics for a specific quest.- Parameters:
player
- the player to checkquest
- the quest to check against- Returns:
- true if the player meets all stat requirements, false otherwise
-
giveRewards
Gives the rewards to the player for completing a specific quest.- Parameters:
player
- the player to whom to give rewardsquest
- the quest for which to give rewards
-
unsetQuestCompletion
Unsets the completion status of a quest for a specific player, both in memory and in the database.- Parameters:
playerUuid
- the UUID of the playerquestId
- the ID of the quest to unset completion for
-
getCompletedPlayers
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
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
Returns the number of quests the player has completed.- Parameters:
playerUuid
- the UUID of the player- Returns:
- the number of completed quests
-
getDisplayableQuestIdsFor
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
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
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 playerquestId
- 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 thecompletedQuests
map. -
getAvailableQuestsFor
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
Marks a quest as completed for a given player and persists the change in the database.- Parameters:
playerUuid
- the UUID of the playerquestId
- the ID of the completed quest
-