Search in sources :

Example 1 with SettingsManager

use of ch.jalu.configme.SettingsManager in project AuthMeReloaded by AuthMe.

the class GenerateCommandsYml method executeDefault.

@Override
public void executeDefault() {
    File file = new File(COMMANDS_YML_FILE);
    // Get the default
    CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.getDefaultValue();
    // Export the value to the file
    SettingsManager settingsManager = SettingsManagerBuilder.withYamlFile(file).configurationData(CommandSettingsHolder.class).create();
    settingsManager.setProperty(CommandSettingsHolder.COMMANDS, commandConfig);
    settingsManager.save();
    System.out.println("Updated " + COMMANDS_YML_FILE);
}
Also used : CommandConfig(fr.xephi.authme.settings.commandconfig.CommandConfig) SettingsManager(ch.jalu.configme.SettingsManager) CommandSettingsHolder(fr.xephi.authme.settings.commandconfig.CommandSettingsHolder) File(java.io.File)

Example 2 with SettingsManager

use of ch.jalu.configme.SettingsManager in project AuthMeReloaded by AuthMe.

the class CommandManager method reload.

@Override
public void reload() {
    File file = new File(dataFolder, "commands.yml");
    FileUtils.copyFileFromResource(file, "commands.yml");
    SettingsManager settingsManager = SettingsManagerBuilder.withResource(YamlFileResourceProvider.loadFromFile(file)).configurationData(CommandSettingsHolder.class).migrationService(commandMigrationService).create();
    CommandConfig commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
    onJoinCommands = newReplacer(commandConfig.getOnJoin());
    onLoginCommands = newOnLoginCmdReplacer(commandConfig.getOnLogin());
    onFirstLoginCommands = newOnLoginCmdReplacer(commandConfig.getOnFirstLogin());
    onSessionLoginCommands = newReplacer(commandConfig.getOnSessionLogin());
    onRegisterCommands = newReplacer(commandConfig.getOnRegister());
    onUnregisterCommands = newReplacer(commandConfig.getOnUnregister());
    onLogoutCommands = newReplacer(commandConfig.getOnLogout());
}
Also used : SettingsManager(ch.jalu.configme.SettingsManager) File(java.io.File)

Example 3 with SettingsManager

use of ch.jalu.configme.SettingsManager in project AuthMeReloaded by AuthMe.

the class UpdateConfigPageTask method executeDefault.

@Override
public void executeDefault() {
    File config = null;
    try {
        // Create empty temporary .yml file and save the config to it
        config = File.createTempFile("authme-config-", ".yml");
        SettingsManager settingsManager = SettingsManagerBuilder.withYamlFile(config).configurationData(AuthMeSettingsRetriever.buildConfigurationData()).create();
        settingsManager.save();
        // Get the contents and generate template file
        TagValueHolder tagValueHolder = TagValueHolder.create().put("config", FileIoUtils.readFromFile(config.toPath()));
        FileIoUtils.generateFileFromTemplate(TEMPLATE_FILE, OUTPUT_FILE, tagValueHolder);
        System.out.println("Wrote to '" + OUTPUT_FILE + "'");
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } finally {
        FileUtils.delete(config);
    }
}
Also used : SettingsManager(ch.jalu.configme.SettingsManager) TagValueHolder(tools.utils.TagValueHolder) IOException(java.io.IOException) File(java.io.File)

Aggregations

SettingsManager (ch.jalu.configme.SettingsManager)3 File (java.io.File)3 CommandConfig (fr.xephi.authme.settings.commandconfig.CommandConfig)1 CommandSettingsHolder (fr.xephi.authme.settings.commandconfig.CommandSettingsHolder)1 IOException (java.io.IOException)1 TagValueHolder (tools.utils.TagValueHolder)1