#411 Migrate settings to new structure (work in progress)

- Work in progress: config.yml cannot be loaded after migration
This commit is contained in:
ljacqu
2016-11-22 21:16:56 +01:00
parent 4214c6dc80
commit 254655abdb
9 changed files with 206 additions and 45 deletions
@@ -2,9 +2,11 @@ package fr.xephi.authme.settings.commandconfig;
import com.github.authme.configme.SettingsManager;
import com.github.authme.configme.resource.YamlFileResource;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.FileUtils;
import org.bukkit.entity.Player;
@@ -27,6 +29,12 @@ public class CommandManager implements Reloadable {
@Inject
private BukkitService bukkitService;
@Inject
private CommandsMigrater commandsMigrater;
@Inject
private Settings settings;
CommandManager() {
}
@@ -39,6 +47,10 @@ public class CommandManager implements Reloadable {
executeCommands(player, commandConfig.getOnRegister());
}
public void runCommandsOnLogin(Player player) {
executeCommands(player, commandConfig.getOnLogin());
}
private void executeCommands(Player player, Map<String, Command> commands) {
for (Command command : commands.values()) {
final String execution = command.getCommand().replace("%p", player.getName());
@@ -58,7 +70,20 @@ public class CommandManager implements Reloadable {
SettingsManager settingsManager = new SettingsManager(
new YamlFileResource(file), null, CommandSettingsHolder.class);
commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
CommandConfig commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
if (commandsMigrater.transformOldCommands(commandConfig)) {
ConsoleLogger.warning("Old setting properties (such as settings.forceCommands) were found. "
+ "They have been moved to commands.yml");
settingsManager.setProperty(CommandSettingsHolder.COMMANDS, commandConfig);
settingsManager.save();
settingsManager.reload();
settings.save();
settings.reload();
commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
}
this.commandConfig = commandConfig;
}