Skip to content

Commit

Permalink
Storage rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Krakenied committed Nov 16, 2024
1 parent 6e53537 commit e8328ba
Show file tree
Hide file tree
Showing 20 changed files with 1,857 additions and 1,129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
import com.leonardobishop.quests.bukkit.scheduler.WrappedTask;
import com.leonardobishop.quests.bukkit.scheduler.bukkit.BukkitServerSchedulerAdapter;
import com.leonardobishop.quests.bukkit.scheduler.folia.FoliaServerScheduler;
import com.leonardobishop.quests.bukkit.storage.MySqlStorageProvider;
import com.leonardobishop.quests.bukkit.storage.YamlStorageProvider;
import com.leonardobishop.quests.bukkit.storage.ModernMySQLStorageProvider;
import com.leonardobishop.quests.bukkit.storage.ModernYAMLStorageProvider;
import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskTypeManager;
import com.leonardobishop.quests.bukkit.tasktype.type.BarteringTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.BlockItemdroppingTaskType;
Expand Down Expand Up @@ -291,14 +291,14 @@ public void onEnable() {
default:
questsLogger.warning("No valid storage provider is configured - Quests will use YAML storage as a default");
case "yaml":
this.storageProvider = new YamlStorageProvider(this);
this.storageProvider = new ModernYAMLStorageProvider(this);
break;
case "mysql":
ConfigurationSection section = this.getConfig().getConfigurationSection("options.storage.database-settings");
if (section == null) {
questsLogger.warning("No database settings are configured - default values will be used");
}
this.storageProvider = new MySqlStorageProvider(this, section);
this.storageProvider = new ModernMySQLStorageProvider(this, section);
}

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.leonardobishop.quests.bukkit.command;

import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
import com.leonardobishop.quests.bukkit.storage.MySqlStorageProvider;
import com.leonardobishop.quests.bukkit.storage.YamlStorageProvider;
import com.leonardobishop.quests.bukkit.storage.ModernMySQLStorageProvider;
import com.leonardobishop.quests.bukkit.storage.ModernYAMLStorageProvider;
import com.leonardobishop.quests.common.player.QPlayerData;
import com.leonardobishop.quests.common.player.questprogressfile.QuestProgressFile;
import com.leonardobishop.quests.common.storage.StorageProvider;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -87,15 +88,15 @@ public void handle(CommandSender sender, String[] args) {
}

sender.sendMessage(ChatColor.GRAY + "Loading quest progress files from '" + fromProvider.getName() + "'...");
List<QuestProgressFile> files = fromProvider.loadAllProgressFiles();
List<QPlayerData> files = fromProvider.loadAllPlayerData();
sender.sendMessage(ChatColor.GRAY.toString() + files.size() + " files loaded.");

for (QuestProgressFile file : files) {
for (QPlayerData file : files) {
file.setModified(true);
}

sender.sendMessage(ChatColor.GRAY + "Writing quest progress files to '" + toProvider.getName() + "'...");
toProvider.saveAllProgressFiles(files);
toProvider.saveAllPlayerData(files);
sender.sendMessage(ChatColor.GRAY + "Done.");

shutdownProvider(sender, fromProvider);
Expand Down Expand Up @@ -151,11 +152,11 @@ private StorageProvider getStorageProvider(ConfigurationSection configurationSec
switch (configuredProvider.toLowerCase()) {
default:
case "yaml":
storageProvider = new YamlStorageProvider(plugin);
storageProvider = new ModernYAMLStorageProvider(plugin);
break;
case "mysql":
ConfigurationSection section = configurationSection.getConfigurationSection("database-settings");
storageProvider = new MySqlStorageProvider(plugin, section);
storageProvider = new ModernMySQLStorageProvider(plugin, section);
}
return storageProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void handle(CommandSender sender, String[] args) {
qPlayer.completeQuest(quest);
Messages.COMMAND_QUEST_ADMIN_COMPLETE_SUCCESS.send(sender, "{player}", args[3], "{quest}", quest.getId());

CommandUtils.doSafeSave(qPlayer, questProgressFile, plugin);
CommandUtils.doSafeSave(this.plugin, qPlayer);
});
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void handle(CommandSender sender, String[] args) {
questProgressFile.reset();
Messages.COMMAND_QUEST_ADMIN_FULLRESET.send(sender, "{player}", args[3]);

CommandUtils.doSafeSave(qPlayer, questProgressFile, plugin);
CommandUtils.doSafeSave(this.plugin, qPlayer);
});

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void handle(CommandSender sender, String[] args) {
"{quest}", quest.getId());
}

CommandUtils.doSafeSave(qPlayer, questProgressFile, plugin);
CommandUtils.doSafeSave(this.plugin, qPlayer);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void handle(CommandSender sender, String[] args) {
questProgressFile.generateBlankQuestProgress(quest, true);
Messages.COMMAND_QUEST_ADMIN_RESET_SUCCESS.send(sender, "{player}", args[3], "{quest}", quest.getId());

CommandUtils.doSafeSave(qPlayer, questProgressFile, plugin);
CommandUtils.doSafeSave(this.plugin, qPlayer);
});
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void handle(CommandSender sender, String[] args) {

Messages.COMMAND_QUEST_ADMIN_START_SUCCESS.send(sender, "{player}", args[3], "{quest}", quest.getId());

CommandUtils.doSafeSave(qPlayer, questProgressFile, plugin);
CommandUtils.doSafeSave(this.plugin, qPlayer);
});
return;
}
Expand Down
Loading

0 comments on commit e8328ba

Please sign in to comment.