aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java')
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/enums/PluginMessagingChannels.java7
-rw-r--r--common/src/main/java/com/leonardobishop/quests/common/player/QPlayerManager.java40
2 files changed, 39 insertions, 8 deletions
diff --git a/common/src/main/java/com/leonardobishop/quests/common/enums/PluginMessagingChannels.java b/common/src/main/java/com/leonardobishop/quests/common/enums/PluginMessagingChannels.java
new file mode 100644
index 00000000..99622900
--- /dev/null
+++ b/common/src/main/java/com/leonardobishop/quests/common/enums/PluginMessagingChannels.java
@@ -0,0 +1,7 @@
+package com.leonardobishop.quests.common.enums;
+
+public class PluginMessagingChannels {
+
+ public static final String QUESTS_LOCKS_CHANNEL = "quests:locks";
+
+}
diff --git a/common/src/main/java/com/leonardobishop/quests/common/player/QPlayerManager.java b/common/src/main/java/com/leonardobishop/quests/common/player/QPlayerManager.java
index 28a46ae1..43b6fa20 100644
--- a/common/src/main/java/com/leonardobishop/quests/common/player/QPlayerManager.java
+++ b/common/src/main/java/com/leonardobishop/quests/common/player/QPlayerManager.java
@@ -49,7 +49,7 @@ public class QPlayerManager {
public void removePlayer(UUID uuid) {
plugin.getQuestsLogger().debug("Unloading and saving player " + uuid + ".");
qPlayers.computeIfPresent(uuid, (mapUUID, qPlayer) -> {
- savePlayer(uuid);
+ savePlayer(uuid, qPlayer.getQuestProgressFile());
return null;
});
}
@@ -104,7 +104,12 @@ public class QPlayerManager {
private void save(UUID uuid, QuestProgressFile questProgressFile) {
plugin.getQuestsLogger().debug("Saving player " + uuid + ".");
- storageProvider.saveProgressFile(uuid, questProgressFile);
+ try {
+ storageProvider.saveProgressFile(uuid, questProgressFile);
+ } catch (Exception e) {
+ plugin.getQuestsLogger().debug("Failed to save player: " + uuid + "!");
+ e.printStackTrace();
+ }
}
/**
@@ -126,14 +131,22 @@ public class QPlayerManager {
* This will have no effect if player is already loaded. Can be invoked asynchronously.
*
* @param uuid the uuid of the player
+ * @return {@link LoadResult} - if the player was successfully loaded
*/
- public void loadPlayer(UUID uuid) {
+ public LoadResult loadPlayer(UUID uuid) {
plugin.getQuestsLogger().debug("Loading player " + uuid + ".");
- qPlayers.computeIfAbsent(uuid, s -> {
- QuestProgressFile questProgressFile = storageProvider.loadProgressFile(uuid);
- if (questProgressFile == null) return null;
- return new QPlayer(plugin, uuid, new QPlayerPreferences(null), questProgressFile, activeQuestController);
- });
+ try {
+ QPlayer qPlayer = qPlayers.computeIfAbsent(uuid, s -> {
+ QuestProgressFile questProgressFile = storageProvider.loadProgressFile(uuid);
+ if (questProgressFile == null) return null;
+ return new QPlayer(plugin, uuid, new QPlayerPreferences(null), questProgressFile, activeQuestController);
+ });
+ return (qPlayer != null) ? LoadResult.LOADED : LoadResult.UNAVAILABLE;
+ } catch (Exception e) {
+ plugin.getQuestsLogger().severe("Failed to load player: " + uuid + "!");
+ e.printStackTrace();
+ }
+ return LoadResult.FAILED;
}
/**
@@ -155,4 +168,15 @@ public class QPlayerManager {
qPlayer.setQuestController(activeQuestController);
}
}
+
+ public enum LoadResult {
+
+ /** A successful load into the QPlayerManager */
+ LOADED,
+ /** An unsuccessful load, however not due to an error (e.g deferred) */
+ UNAVAILABLE,
+ /** An unsuccessful load */
+ FAILED;
+
+ }
}