use of org.bukkit.configuration.ConfigurationSection in project Minigames by AddstarMC.
the class BackendManager method initialize.
/**
* Initializes the backend.
* @param config The configuration to load settings from
*/
public boolean initialize(ConfigurationSection config) {
ConfigurationSection backendSection = config.getConfigurationSection("backend");
if (config.isSet("use-sql")) {
// Load in values from previous system
if (config.getBoolean("use-sql")) {
backendSection.set("type", "mysql");
} else {
backendSection.set("type", "sqlite");
}
backendSection.set("database", config.getString("sql-database"));
backendSection.set("host", config.getString("sql-host") + ":" + config.getInt("sql-port"));
backendSection.set("username", config.getString("sql-username"));
backendSection.set("password", config.getString("sql-password"));
backendSection.set("convert", true);
// Clear the existing value
config.set("use-sql", null);
config.set("sql-database", null);
config.set("sql-port", null);
config.set("sql-host", null);
config.set("sql-username", null);
config.set("sql-password", null);
}
// Create the backend
String type = backendSection.getString("type", "sqlite").toLowerCase();
backend = makeBackend(type);
if (backend == null) {
// Default to this
logger.warning("Invalid backend type " + type + ". Falling back to SQLite");
backend = new SQLiteBackend(logger);
}
// Init
if (!backend.initialize(backendSection)) {
return false;
}
// Handle conversion
if (backendSection.getBoolean("convert", false)) {
ExportNotifier notifier = new ExportNotifier() {
@Override
public void onProgress(String state, int count) {
logger.info("Conversion: " + state + " " + count);
}
@Override
public void onError(Throwable e, String state, int count) {
logger.log(Level.SEVERE, "Conversion error: " + state + " " + count, e);
}
@Override
public void onComplete() {
logger.info("Conversion complete");
}
};
if (backend.doConversion(notifier)) {
backendSection.set("convert", false);
} else {
return false;
}
}
// Start the cleaning task to remove old connections
Bukkit.getScheduler().runTaskTimer(Minigames.plugin, new Runnable() {
@Override
public void run() {
backend.clean();
}
}, 300, 300);
return true;
}
use of org.bukkit.configuration.ConfigurationSection in project Minigames by AddstarMC.
the class RewardsModule method load.
@Override
public void load(FileConfiguration config) {
ConfigurationSection root = config.getConfigurationSection(getMinigame().getName(false));
String name = root.getString("reward-scheme", "standard");
scheme = RewardSchemes.createScheme(name);
if (scheme == null) {
scheme = new StandardRewardScheme();
}
ConfigurationSection rewards = root.getConfigurationSection("rewards");
scheme.load(rewards);
}
use of org.bukkit.configuration.ConfigurationSection in project Minigames by AddstarMC.
the class RewardsModule method save.
@Override
public void save(FileConfiguration config) {
String name = RewardSchemes.getName(scheme.getClass());
ConfigurationSection root = config.getConfigurationSection(getMinigame().getName(false));
root.set("reward-scheme", name);
ConfigurationSection rewards = root.createSection("rewards");
scheme.save(rewards);
}
use of org.bukkit.configuration.ConfigurationSection in project Minigames by AddstarMC.
the class HierarchyRewardScheme method save.
private void save(TreeMap<T, Rewards> map, ConfigurationSection section) {
for (Entry<T, Rewards> entry : map.entrySet()) {
ConfigurationSection scoreSection = section.createSection(String.valueOf(entry.getKey()));
entry.getValue().save(scoreSection);
}
}
use of org.bukkit.configuration.ConfigurationSection in project Minigames by AddstarMC.
the class HierarchyRewardScheme method save.
@Override
public void save(ConfigurationSection config) {
ConfigurationSection primary = config.createSection("score-primary");
ConfigurationSection secondary = config.createSection("score-secondary");
save(primaryRewards, primary);
save(secondaryRewards, secondary);
}
Aggregations