diff --git a/core/src/main/java/me/blackvein/quests/Quester.java b/core/src/main/java/me/blackvein/quests/Quester.java index d679750aa..1ffb00b44 100644 --- a/core/src/main/java/me/blackvein/quests/Quester.java +++ b/core/src/main/java/me/blackvein/quests/Quester.java @@ -41,7 +41,6 @@ import me.blackvein.quests.quests.IStage; import me.blackvein.quests.quests.Objective; import me.blackvein.quests.quests.Planner; import me.blackvein.quests.quests.Requirements; -import me.blackvein.quests.storage.Storage; import me.blackvein.quests.tasks.StageTimer; import me.blackvein.quests.util.ConfigUtil; import me.blackvein.quests.util.InventoryUtil; @@ -69,10 +68,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.material.Crops; import org.jetbrains.annotations.NotNull; @@ -4221,8 +4218,7 @@ public class Quester implements IQuester { */ public boolean saveData() { try { - final Storage storage = plugin.getStorage(); - storage.saveQuester(this); + plugin.getStorage().saveQuester(this).get(); } catch (final Exception e) { return false; } diff --git a/core/src/main/java/me/blackvein/quests/Quests.java b/core/src/main/java/me/blackvein/quests/Quests.java index 76cfc2960..2e74aabbe 100644 --- a/core/src/main/java/me/blackvein/quests/Quests.java +++ b/core/src/main/java/me/blackvein/quests/Quests.java @@ -131,9 +131,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentSkipListSet; -import java.util.concurrent.ExecutionException; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.logging.Level; @@ -293,8 +291,7 @@ public class Quests extends JavaPlugin implements QuestsAPI { public void onDisable() { getLogger().info("Saving Quester data..."); for (final Player p : getServer().getOnlinePlayers()) { - final IQuester quester = getQuester(p.getUniqueId()); - quester.saveData(); + getQuester(p.getUniqueId()).saveData(); } Bukkit.getScheduler().cancelTasks(this); getLogger().info("Closing storage..."); @@ -1716,9 +1713,9 @@ public class Quests extends JavaPlugin implements QuestsAPI { } loading = true; reloadConfig(); - final CompletableFuture saveFuture = getStorage().saveOfflineQuesters(); Bukkit.getScheduler().runTaskAsynchronously(this, () -> { try { + getStorage().saveOfflineQuesters().get(); Lang.clear(); settings.init(); Lang.init(Quests.this, settings.getLanguage()); @@ -1728,24 +1725,15 @@ public class Quests extends JavaPlugin implements QuestsAPI { loadQuests(); loadActions(); loadConditions(); - final CompletableFuture loadFuture = saveFuture.thenRunAsync(() -> { - try { - for (final IQuester quester : questers) { - final CompletableFuture cf = getStorage().loadQuester(quester.getUUID()); - final IQuester loaded = cf.get(); - for (final IQuest q : loaded.getCurrentQuestsTemp().keySet()) { - loaded.checkQuest(q); - } - } - } catch (InterruptedException | ExecutionException e) { - finishLoading(callback, false, e); + for (final IQuester quester : questers) { + final IQuester loaded = getStorage().loadQuester(quester.getUUID()).get(); + for (final IQuest quest : loaded.getCurrentQuestsTemp().keySet()) { + loaded.checkQuest(quest); } - }); - loadFuture.thenRunAsync(() -> { - loadModules(); - importQuests(); - finishLoading(callback, true, null); - }); + } + loadModules(); + importQuests(); + finishLoading(callback, true, null); } catch (final Exception e) { finishLoading(callback, false, e); } diff --git a/core/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java b/core/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java index 96450f487..9b0fc2ee2 100644 --- a/core/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java +++ b/core/src/main/java/me/blackvein/quests/storage/implementation/file/SeparatedYamlStorage.java @@ -63,7 +63,7 @@ public class SeparatedYamlStorage implements StorageImplementation { @SuppressWarnings("deprecation") @Override - public IQuester loadQuester(final UUID uniqueId) throws Exception { + public IQuester loadQuester(final UUID uniqueId) throws IOException, InvalidConfigurationException { final FileConfiguration data = new YamlConfiguration(); IQuester quester = plugin.getQuester(uniqueId); if (quester != null) { @@ -71,15 +71,10 @@ public class SeparatedYamlStorage implements StorageImplementation { } else { quester = new Quester(plugin, uniqueId); } - try { - final File dataFile = getDataFile(quester); - if (dataFile != null) { - data.load(dataFile); - } else { - return null; - } - } catch (final IOException | InvalidConfigurationException e) { - e.printStackTrace(); + final File dataFile = getDataFile(quester); + if (dataFile != null) { + data.load(dataFile); + } else { return null; } if (data.contains("completedRedoableQuests")) { @@ -384,13 +379,9 @@ public class SeparatedYamlStorage implements StorageImplementation { } @Override - public void saveQuester(final IQuester quester) { + public void saveQuester(final IQuester quester) throws IOException { final FileConfiguration data = quester.getBaseData(); - try { - data.save(new File(directoryPath + File.separator + quester.getUUID() + ".yml")); - } catch (final IOException e) { - e.printStackTrace(); - } + data.save(new File(directoryPath + File.separator + quester.getUUID() + ".yml")); } @Override diff --git a/core/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java b/core/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java index 760de8a8c..4875522ae 100644 --- a/core/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java +++ b/core/src/main/java/me/blackvein/quests/storage/implementation/sql/SqlStorage.java @@ -248,7 +248,7 @@ public class SqlStorage implements StorageImplementation { } @Override - public void saveQuester(final IQuester quester) throws Exception { + public void saveQuester(final IQuester quester) throws SQLException { final UUID uniqueId = quester.getUUID(); final String lastKnownName = quester.getLastKnownName(); final String oldLastKnownName = getQuesterLastKnownName(uniqueId); @@ -418,7 +418,7 @@ public class SqlStorage implements StorageImplementation { } @Override - public String getQuesterLastKnownName(final UUID uniqueId) throws Exception { + public String getQuesterLastKnownName(final UUID uniqueId) throws SQLException { try (final Connection c = connectionFactory.getConnection()) { try (final PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_SELECT_USERNAME))) { ps.setString(1, uniqueId.toString()); @@ -432,7 +432,7 @@ public class SqlStorage implements StorageImplementation { return null; } - public ConcurrentHashMap getQuesterCurrentQuests(final UUID uniqueId) throws Exception { + public ConcurrentHashMap getQuesterCurrentQuests(final UUID uniqueId) throws SQLException { final ConcurrentHashMap currentQuests = new ConcurrentHashMap<>(); try (final Connection c = connectionFactory.getConnection()) { try (final PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_CURRENT_QUESTS_SELECT_BY_UUID))) { @@ -450,7 +450,7 @@ public class SqlStorage implements StorageImplementation { return currentQuests; } - public ConcurrentHashMap getQuesterQuestData(final UUID uniqueId) throws Exception { + public ConcurrentHashMap getQuesterQuestData(final UUID uniqueId) throws SQLException { final IQuester quester = plugin.getQuester(uniqueId); final ConcurrentHashMap questData = new ConcurrentHashMap<>(); try (final Connection c = connectionFactory.getConnection()) { @@ -505,7 +505,7 @@ public class SqlStorage implements StorageImplementation { return questData; } - public ConcurrentSkipListSet getQuesterCompletedQuests(final UUID uniqueId) throws Exception { + public ConcurrentSkipListSet getQuesterCompletedQuests(final UUID uniqueId) throws SQLException { final ConcurrentSkipListSet completedQuests = new ConcurrentSkipListSet<>(); try (final Connection c = connectionFactory.getConnection()) { try (final PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_COMPLETED_QUESTS_SELECT_BY_UUID))) { @@ -523,7 +523,7 @@ public class SqlStorage implements StorageImplementation { return completedQuests; } - public ConcurrentHashMap getQuesterCompletedTimes(final UUID uniqueId) throws Exception { + public ConcurrentHashMap getQuesterCompletedTimes(final UUID uniqueId) throws SQLException { final ConcurrentHashMap completedTimes = new ConcurrentHashMap<>(); try (final Connection c = connectionFactory.getConnection()) { try (final PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_REDOABLE_QUESTS_SELECT_BY_UUID))) { @@ -541,7 +541,7 @@ public class SqlStorage implements StorageImplementation { return completedTimes; } - public ConcurrentHashMap getQuesterAmountsCompleted(final UUID uniqueId) throws Exception { + public ConcurrentHashMap getQuesterAmountsCompleted(final UUID uniqueId) throws SQLException { final ConcurrentHashMap amountsCompleted = new ConcurrentHashMap<>(); try (final Connection c = connectionFactory.getConnection()) { try (final PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_REDOABLE_QUESTS_SELECT_BY_UUID))) { @@ -560,7 +560,7 @@ public class SqlStorage implements StorageImplementation { } @Override - public Collection getSavedUniqueIds() throws Exception { + public Collection getSavedUniqueIds() throws SQLException { final Collection ids = new ConcurrentSkipListSet<>(); try (final Connection c = connectionFactory.getConnection()) { try (final PreparedStatement ps = c.prepareStatement(statementProcessor.apply(PLAYER_SELECT_UUID))) {