Search in sources :

Example 6 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project Minigames by AddstarMC.

the class PresetLoader method loadPreset.

public static String loadPreset(String preset, Minigame minigame) {
    preset = preset.toLowerCase();
    File file = new File(Minigames.plugin.getDataFolder() + "/presets/" + preset + ".yml");
    if (file.exists()) {
        MinigameSave save = new MinigameSave("presets/" + preset);
        FileConfiguration config = save.getConfig();
        for (String opt : config.getConfigurationSection(preset).getKeys(false)) {
            Flag<?> flag = minigame.getConfigFlag(opt);
            if (flag != null) {
                flag.loadValue(preset, config);
            }
        }
        return ChatColor.GRAY + "Loaded the " + MinigameUtils.capitalize(preset) + " preset to " + minigame.getName(false);
    } else {
        return ChatColor.RED + "Failed to load preset: " + ChatColor.GRAY + preset + ".yml was not found in the presets folder!";
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) File(java.io.File) MinigameSave(au.com.mineauz.minigames.MinigameSave)

Example 7 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project Minigames by AddstarMC.

the class Minigame method loadMinigame.

public void loadMinigame() {
    MinigameSave minigame = new MinigameSave(name, "config");
    FileConfiguration cfg = minigame.getConfig();
    //TODO: Remove me after 1.7
    if (cfg.contains(name + ".type")) {
        //Minigames.plugin.getLogger().warning("Your configuration files ("+cfg.getCurrentPath()+") are of an old version. They will not be supported past ver1.11");
        if (cfg.getString(name + ".type").equals("TEAMS")) {
            cfg.set(name + ".type", "MULTIPLAYER");
            TeamsModule.getMinigameModule(this).addTeam(TeamColor.RED);
            TeamsModule.getMinigameModule(this).addTeam(TeamColor.BLUE);
        } else if (cfg.getString(name + ".type").equals("FREE_FOR_ALL")) {
            cfg.set(name + ".type", "MULTIPLAYER");
        } else if (cfg.getString(name + ".type").equals("TREASURE_HUNT")) {
            cfg.set(name + ".type", "GLOBAL");
            cfg.set(name + ".scoretype", "treasure_hunt");
            cfg.set(name + ".timer", Minigames.plugin.getConfig().getInt("treasurehunt.findtime") * 60);
        }
    }
    for (MinigameModule module : getModules()) {
        if (!module.useSeparateConfig()) {
            module.load(cfg);
            if (module.getFlags() != null) {
                for (String flag : module.getFlags().keySet()) {
                    if (cfg.contains(name + "." + flag))
                        module.getFlags().get(flag).loadValue(name, cfg);
                }
            }
        } else {
            MinigameSave modsave = new MinigameSave("minigames/" + name + "/" + module.getName().toLowerCase());
            module.load(modsave.getConfig());
            if (module.getFlags() != null) {
                for (String flag : module.getFlags().keySet()) {
                    if (modsave.getConfig().contains(name + "." + flag))
                        module.getFlags().get(flag).loadValue(name, modsave.getConfig());
                }
            }
        }
    }
    for (String flag : configFlags.keySet()) {
        if (cfg.contains(name + "." + flag))
            configFlags.get(flag).loadValue(name, cfg);
    }
    if (minigame.getConfig().contains(name + ".whitelistmode")) {
        getBlockRecorder().setWhitelistMode(minigame.getConfig().getBoolean(name + ".whitelistmode"));
    }
    if (minigame.getConfig().contains(name + ".whitelistblocks")) {
        List<String> blocklist = minigame.getConfig().getStringList(name + ".whitelistblocks");
        for (String block : blocklist) {
            getBlockRecorder().addWBBlock(Material.matchMaterial(block));
        }
    }
    //		Bukkit.getLogger().info("------- Minigame Load -------");
    //		Bukkit.getLogger().info("Name: " + getName());
    //		Bukkit.getLogger().info("Type: " + getType());
    //		Bukkit.getLogger().info("Enabled: " + isEnabled());
    //		Bukkit.getLogger().info("-----------------------------");
    final Minigame mgm = this;
    if (getType() == MinigameType.GLOBAL && isEnabled()) {
        Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.plugin, new Runnable() {

            @Override
            public void run() {
                Minigames.plugin.mdata.startGlobalMinigame(mgm, null);
            }
        });
    }
    getScoreboardData().loadDisplays(minigame, this);
    ListenableFuture<Map<MinigameStat, StatSettings>> settingsFuture = Minigames.plugin.getBackend().loadStatSettings(this);
    Minigames.plugin.getBackend().addServerThreadCallback(settingsFuture, new FutureCallback<Map<MinigameStat, StatSettings>>() {

        @Override
        public void onSuccess(Map<MinigameStat, StatSettings> result) {
            statSettings.clear();
            statSettings.putAll(result);
            getScoreboardData().reload();
        }

        @Override
        public void onFailure(Throwable t) {
            t.printStackTrace();
        }
    });
    saveMinigame();
}
Also used : MinigameModule(au.com.mineauz.minigames.minigame.modules.MinigameModule) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString) MinigameSave(au.com.mineauz.minigames.MinigameSave) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) MinigameStat(au.com.mineauz.minigames.stats.MinigameStat) StatSettings(au.com.mineauz.minigames.stats.StatSettings) MenuItemSaveMinigame(au.com.mineauz.minigames.menu.MenuItemSaveMinigame) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project Minigames by AddstarMC.

the class Minigame method saveMinigame.

public void saveMinigame() {
    MinigameSave minigame = new MinigameSave(name, "config");
    FileConfiguration cfg = minigame.getConfig();
    cfg.set(name, null);
    cfg.createSection(name);
    for (MinigameModule module : getModules()) {
        if (!module.useSeparateConfig()) {
            module.save(cfg);
            if (module.getFlags() != null) {
                for (Flag<?> flag : module.getFlags().values()) {
                    if (flag.getFlag() != null && (flag.getDefaultFlag() == null || !flag.getDefaultFlag().equals(flag.getFlag())))
                        flag.saveValue(name, cfg);
                }
            }
        } else {
            MinigameSave modsave = new MinigameSave("minigames/" + name + "/" + module.getName().toLowerCase());
            modsave.getConfig().set(name, null);
            modsave.getConfig().createSection(name);
            module.save(modsave.getConfig());
            if (module.getFlags() != null) {
                for (Flag<?> flag : module.getFlags().values()) {
                    if (flag.getFlag() != null && (flag.getDefaultFlag() == null || !flag.getDefaultFlag().equals(flag.getFlag())))
                        flag.saveValue(name, modsave.getConfig());
                }
            }
            modsave.saveConfig();
        }
    }
    for (String configOpt : configFlags.keySet()) {
        if (configFlags.get(configOpt).getFlag() != null && (configFlags.get(configOpt).getDefaultFlag() == null || !configFlags.get(configOpt).getDefaultFlag().equals(configFlags.get(configOpt).getFlag())))
            configFlags.get(configOpt).saveValue(name, cfg);
    }
    if (!getBlockRecorder().getWBBlocks().isEmpty()) {
        List<String> blocklist = new ArrayList<String>();
        for (Material mat : getBlockRecorder().getWBBlocks()) {
            blocklist.add(mat.toString());
        }
        minigame.getConfig().set(name + ".whitelistblocks", blocklist);
    }
    if (getBlockRecorder().getWhitelistMode()) {
        minigame.getConfig().set(name + ".whitelistmode", getBlockRecorder().getWhitelistMode());
    }
    getScoreboardData().saveDisplays(minigame, name);
    getScoreboardData().refreshDisplays();
    Minigames.plugin.getBackend().saveStatSettings(this, statSettings.values());
    minigame.saveConfig();
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) MinigameModule(au.com.mineauz.minigames.minigame.modules.MinigameModule) ArrayList(java.util.ArrayList) Material(org.bukkit.Material) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString) MinigameSave(au.com.mineauz.minigames.MinigameSave)

Example 9 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project Minigames by AddstarMC.

the class ScoreboardData method saveDisplays.

public void saveDisplays(MinigameSave save, String name) {
    FileConfiguration root = save.getConfig();
    ConfigurationSection section = root.createSection(name + ".scoreboards");
    int index = 0;
    for (ScoreboardDisplay display : displays.values()) {
        ConfigurationSection displaySection = section.createSection(String.valueOf(index++));
        display.save(displaySection);
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 10 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project Minigames by AddstarMC.

the class OfflineMinigamePlayer method savePlayerData.

public void savePlayerData() {
    MinigameSave save = new MinigameSave("playerdata/inventories/" + uuid.toString());
    FileConfiguration con = save.getConfig();
    if (storedItems != null) {
        int num = 0;
        for (ItemStack item : storedItems) {
            if (item != null) {
                con.set("items." + num, item);
            }
            num++;
        }
    }
    if (storedArmour != null) {
        int num = 0;
        for (ItemStack item : storedArmour) {
            if (item != null) {
                con.set("armour." + num, item);
            }
            num++;
        }
    }
    con.set("food", food);
    con.set("saturation", saturation);
    con.set("health", health);
    con.set("gamemode", lastGM.toString());
    con.set("exp", exp);
    con.set("level", level);
    if (loginLocation != null) {
        con.set("location.x", loginLocation.getBlockX());
        con.set("location.y", loginLocation.getBlockY());
        con.set("location.z", loginLocation.getBlockZ());
        con.set("location.yaw", loginLocation.getYaw());
        con.set("location.pitch", loginLocation.getPitch());
        con.set("location.world", loginLocation.getWorld().getName());
    }
    save.saveConfig();
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

FileConfiguration (org.bukkit.configuration.file.FileConfiguration)36 File (java.io.File)11 IOException (java.io.IOException)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)5 MinigameSave (au.com.mineauz.minigames.MinigameSave)4 HashMap (java.util.HashMap)4 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)4 Map (java.util.Map)3 MemorySection (org.bukkit.configuration.MemorySection)3 Player (org.bukkit.entity.Player)3 RewardsFlag (au.com.mineauz.minigames.config.RewardsFlag)2 MenuItemString (au.com.mineauz.minigames.menu.MenuItemString)2 MinigameModule (au.com.mineauz.minigames.minigame.modules.MinigameModule)2 DefaultInfo (de.Keyle.MyPet.api.entity.DefaultInfo)2 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)2 ConfigurationYAML (de.Keyle.MyPet.api.util.configuration.ConfigurationYAML)2 InputStreamReader (java.io.InputStreamReader)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2