Search in sources :

Example 1 with RoseSetting

use of dev.rosewood.rosegarden.config.RoseSetting in project RoseGarden by Rosewood-Development.

the class AbstractConfigurationManager method getSettings.

/**
 * @return the values of the setting enum
 */
public Map<String, RoseSetting> getSettings() {
    if (this.cachedValues == null) {
        try {
            RoseSetting[] roseSettings = (RoseSetting[]) this.settingEnum.getDeclaredMethod("values").invoke(null);
            this.cachedValues = new LinkedHashMap<>();
            for (RoseSetting roseSetting : roseSettings) this.cachedValues.put(roseSetting.getKey(), roseSetting);
        } catch (ReflectiveOperationException ex) {
            ex.printStackTrace();
            this.cachedValues = Collections.emptyMap();
        }
        this.injectAdditionalSettings();
    }
    return this.cachedValues;
}
Also used : SingularRoseSetting(dev.rosewood.rosegarden.config.SingularRoseSetting) RoseSetting(dev.rosewood.rosegarden.config.RoseSetting)

Example 2 with RoseSetting

use of dev.rosewood.rosegarden.config.RoseSetting in project RoseGarden by Rosewood-Development.

the class AbstractConfigurationManager method reload.

@Override
public final void reload() {
    File configFile = new File(this.rosePlugin.getDataFolder(), "config.yml");
    boolean setHeaderFooter = !configFile.exists();
    boolean changed = setHeaderFooter;
    this.configuration = CommentedFileConfiguration.loadConfiguration(configFile);
    if (setHeaderFooter)
        this.configuration.addComments(this.getHeader());
    for (RoseSetting setting : this.getSettings().values()) {
        setting.reset();
        changed |= setting.setIfNotExists(this.configuration);
    }
    if (setHeaderFooter)
        this.configuration.addComments(FOOTER);
    if (changed)
        this.configuration.save();
}
Also used : SingularRoseSetting(dev.rosewood.rosegarden.config.SingularRoseSetting) RoseSetting(dev.rosewood.rosegarden.config.RoseSetting) File(java.io.File)

Example 3 with RoseSetting

use of dev.rosewood.rosegarden.config.RoseSetting in project RoseGarden by Rosewood-Development.

the class AbstractDataManager method reload.

@Override
public final void reload() {
    try {
        AbstractConfigurationManager configurationManager = this.rosePlugin.getManager(AbstractConfigurationManager.class);
        Map<String, RoseSetting> roseSettings = configurationManager.getSettings();
        if (roseSettings.get("mysql-settings.enabled").getBoolean()) {
            String hostname = roseSettings.get("mysql-settings.hostname").getString();
            int port = roseSettings.get("mysql-settings.port").getInt();
            String database = roseSettings.get("mysql-settings.database-name").getString();
            String username = roseSettings.get("mysql-settings.user-name").getString();
            String password = roseSettings.get("mysql-settings.user-password").getString();
            boolean useSSL = roseSettings.get("mysql-settings.use-ssl").getBoolean();
            int poolSize = roseSettings.get("mysql-settings.connection-pool-size").getInt();
            this.databaseConnector = new MySQLConnector(this.rosePlugin, hostname, port, database, username, password, useSSL, poolSize);
            this.rosePlugin.getLogger().info("Data handler connected using MySQL.");
        } else {
            this.databaseConnector = new SQLiteConnector(this.rosePlugin);
            this.databaseConnector.cleanup();
            this.rosePlugin.getLogger().info("Data handler connected using SQLite.");
        }
    } catch (Exception ex) {
        this.rosePlugin.getLogger().severe("Fatal error trying to connect to database. Please make sure all your connection settings are correct and try again. Plugin has been disabled.");
        ex.printStackTrace();
        Bukkit.getPluginManager().disablePlugin(this.rosePlugin);
    }
}
Also used : RoseSetting(dev.rosewood.rosegarden.config.RoseSetting) SQLiteConnector(dev.rosewood.rosegarden.database.SQLiteConnector) MySQLConnector(dev.rosewood.rosegarden.database.MySQLConnector)

Aggregations

RoseSetting (dev.rosewood.rosegarden.config.RoseSetting)3 SingularRoseSetting (dev.rosewood.rosegarden.config.SingularRoseSetting)2 MySQLConnector (dev.rosewood.rosegarden.database.MySQLConnector)1 SQLiteConnector (dev.rosewood.rosegarden.database.SQLiteConnector)1 File (java.io.File)1