use of io.github.wysohn.triggerreactor.sponge.tools.migration.VariableMigrationHelper in project TriggerReactor by wysohn.
the class TriggerReactor method migrateOldConfig.
private void migrateOldConfig() {
new ContinuingTasks.Builder().append(() -> {
// if (getPluginConfigManager().isMigrationNeeded()) {
// File file = new File(getDataFolder(), "config.yml");
// ConfigurationLoader<CommentedConfigurationNode> varFileConfigLoader
// = HoconConfigurationLoader.builder().setPath(file.toPath()).build();
// ConfigurationNode confFileConfig = null;
// try {
// confFileConfig = varFileConfigLoader.load();
// } catch (IOException e) {
// e.printStackTrace();
// return;
// }
// getPluginConfigManager().migrate(new SpongeMigrationHelper(confFileConfig, file));
// }
}).append(() -> {
if (getVariableManager().isMigrationNeeded()) {
File file = new File(getDataFolder(), "var.yml");
ConfigurationLoader<CommentedConfigurationNode> varFileConfigLoader = HoconConfigurationLoader.builder().setPath(file.toPath()).build();
ConfigurationNode varFileConfig = null;
try {
varFileConfig = varFileConfigLoader.load();
} catch (IOException e) {
e.printStackTrace();
return;
}
getVariableManager().migrate(new VariableMigrationHelper(varFileConfig, file));
}
}).append(() -> Optional.of(getInvManager()).map(AbstractTriggerManager::getTriggerInfos).ifPresent(triggerInfos -> Arrays.stream(triggerInfos).filter(TriggerInfo::isMigrationNeeded).forEach(triggerInfo -> {
File folder = triggerInfo.getSourceCodeFile().getParentFile();
File oldFile = new File(folder, triggerInfo.getTriggerName() + ".yml");
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(oldFile.toPath()).build();
ConfigurationNode oldConfig = null;
try {
oldConfig = loader.load();
} catch (IOException e) {
e.printStackTrace();
return;
}
triggerInfo.migrate(new InvTriggerMigrationHelper(oldFile, oldConfig));
}))).append(() -> Manager.getManagers().stream().filter(AbstractTriggerManager.class::isInstance).map(AbstractTriggerManager.class::cast).map(AbstractTriggerManager::getTriggerInfos).forEach(triggerInfos -> Arrays.stream(triggerInfos).filter(TriggerInfo::isMigrationNeeded).forEach(triggerInfo -> {
File folder = triggerInfo.getSourceCodeFile().getParentFile();
File oldFile = new File(folder, triggerInfo.getTriggerName() + ".yml");
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(oldFile.toPath()).build();
ConfigurationNode oldConfig = null;
try {
oldConfig = loader.load();
} catch (IOException e) {
e.printStackTrace();
return;
}
triggerInfo.migrate(new NaiveMigrationHelper(oldConfig, oldFile));
}))).run();
}
Aggregations