From 77aa3763412ce2ee1da814bba7d8e26ea85240fb Mon Sep 17 00:00:00 2001 From: LMBishop <13875753+LMBishop@users.noreply.github.com> Date: Wed, 3 Mar 2021 13:29:42 +0000 Subject: Add documentation --- .../quests/player/QPlayerManager.java | 5 +- .../questprogressfile/QuestProgressFile.java | 104 +++++++++++++++++---- 2 files changed, 88 insertions(+), 21 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java b/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java index ac7504fe..ba942978 100644 --- a/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java +++ b/src/main/java/com/leonardobishop/quests/player/QPlayerManager.java @@ -45,7 +45,7 @@ public class QPlayerManager { } /** - * Unloads and saves the player to disk. + * Unloads and saves the player to disk. Must be invoked from the main thread. * * @param uuid the uuid of the player */ @@ -76,7 +76,7 @@ public class QPlayerManager { /** * Load the player from disk if they exist, otherwise create a new {@link QuestProgressFile}. - * Will have no effect if player is already loaded. + * This will have no effect if player is already loaded. Can be invoked asynchronously. * * @param uuid the uuid of the player */ @@ -91,6 +91,7 @@ public class QPlayerManager { File file = new File(plugin.getDataFolder() + File.separator + "playerdata" + File.separator + uuid.toString() + ".yml"); if (file.exists()) { YamlConfiguration data = YamlConfiguration.loadConfiguration(file); + plugin.getQuestsLogger().debug("Player " + uuid + " has a valid quest progress file."); if (data.isConfigurationSection("quest-progress")) { //Same job as "isSet" + it checks if is CfgSection for (String id : data.getConfigurationSection("quest-progress").getKeys(false)) { boolean started = data.getBoolean("quest-progress." + id + ".started"); diff --git a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java index 16ccd020..b2596079 100644 --- a/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java +++ b/src/main/java/com/leonardobishop/quests/player/questprogressfile/QuestProgressFile.java @@ -42,6 +42,16 @@ public class QuestProgressFile { this.plugin = plugin; } + /** + * Attempt to complete a quest for the player. This will also play all effects (such as titles, messages etc.) + * and also dispatches all rewards for the player. + * + * Warning: rewards will not be sent and the {@link PlayerFinishQuestEvent} will not be fired if the + * player is not online + * + * @param quest the quest to complete + * @return true (always) + */ public boolean completeQuest(Quest quest) { QuestProgress questProgress = getQuestProgress(quest); questProgress.setStarted(false); @@ -82,7 +92,15 @@ public class QuestProgressFile { return true; } + /** + * Attempt to track a quest for the player. This will also play all effects (such as titles, messages etc.) + * + * Warning: will fail if the player is not online. + * + * @param quest the quest to track + */ public void trackQuest(Quest quest) { + //TODO change how this works Player player = Bukkit.getPlayer(playerUUID); if (quest == null) { playerPreferences.setTrackedQuestId(null); @@ -99,7 +117,7 @@ public class QuestProgressFile { /** * Check if the player can start a quest. - *
+ * * Warning: will fail if the player is not online. * * @param quest the quest to check @@ -150,12 +168,12 @@ public class QuestProgressFile { } /** - * Start a quest for the player. - *
+ * Attempt to start a quest for the player. This will also play all effects (such as titles, messages etc.)
+ *
* Warning: will fail if the player is not online.
*
- * @param quest the quest to check
- * @return the quest start result
+ * @param quest the quest to start
+ * @return the quest start result -- {@code QuestStartResult.QUEST_SUCCESS} indicates success
*/
// TODO PlaceholderAPI support
public QuestStartResult startQuest(Quest quest) {
@@ -239,6 +257,12 @@ public class QuestProgressFile {
return code;
}
+ /**
+ * Attempt to cancel a quest for the player. This will also play all effects (such as titles, messages etc.)
+ *
+ * @param quest the quest to start
+ * @return true if the quest was cancelled, false otherwise
+ */
public boolean cancelQuest(Quest quest) {
QuestProgress questProgress = getQuestProgress(quest);
Player player = Bukkit.getPlayer(this.playerUUID);
@@ -269,6 +293,13 @@ public class QuestProgressFile {
this.questProgress.put(questProgress.getQuestId(), questProgress);
}
+ /**
+ * Gets all 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 #hasStartedQuest(Quest)} instead.
+ *
+ * @return
+ */
public List
- * Returns all {@code Quest}s a player has encountered
- * (not to be confused with a collection of quest progress)
- */
- @Deprecated
- public List