Search in sources :

Example 26 with ConfigurationSection

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;
}
Also used : SQLiteBackend(au.com.mineauz.minigames.backend.sqlite.SQLiteBackend) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 27 with ConfigurationSection

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);
}
Also used : StandardRewardScheme(au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 28 with ConfigurationSection

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);
}
Also used : ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 29 with ConfigurationSection

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);
    }
}
Also used : Rewards(au.com.mineauz.minigames.minigame.reward.Rewards) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 30 with ConfigurationSection

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);
}
Also used : ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ConfigurationSection (org.bukkit.configuration.ConfigurationSection)42 IOException (java.io.IOException)4 ItemStack (org.bukkit.inventory.ItemStack)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)3 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)3 Rewards (au.com.mineauz.minigames.minigame.reward.Rewards)2 ChatColor (com.gamingmesh.jobs.util.ChatColor)2 BigDecimal (java.math.BigDecimal)2 Material (org.bukkit.Material)2 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 SQLiteBackend (au.com.mineauz.minigames.backend.sqlite.SQLiteBackend)1 MenuItemRewardGroup (au.com.mineauz.minigames.menu.MenuItemRewardGroup)1 LoadoutAddon (au.com.mineauz.minigames.minigame.modules.LoadoutModule.LoadoutAddon)1 StandardRewardScheme (au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)1 NoChargeException (com.earth2me.essentials.commands.NoChargeException)1 ActionType (com.gamingmesh.jobs.container.ActionType)1 DisplayMethod (com.gamingmesh.jobs.container.DisplayMethod)1 Job (com.gamingmesh.jobs.container.Job)1