Search in sources :

Example 1 with MinigameSave

use of au.com.mineauz.minigames.MinigameSave in project Minigames by AddstarMC.

the class PresetLoader method getPresetInfo.

public static String getPresetInfo(String preset) {
    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();
        if (config.contains(preset + ".info"))
            return config.getString(preset + ".info");
        else
            return "No information given on this preset.";
    }
    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 2 with MinigameSave

use of au.com.mineauz.minigames.MinigameSave 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 3 with MinigameSave

use of au.com.mineauz.minigames.MinigameSave 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 4 with MinigameSave

use of au.com.mineauz.minigames.MinigameSave 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)

Aggregations

MinigameSave (au.com.mineauz.minigames.MinigameSave)4 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)4 MenuItemString (au.com.mineauz.minigames.menu.MenuItemString)2 MinigameModule (au.com.mineauz.minigames.minigame.modules.MinigameModule)2 File (java.io.File)2 MenuItemSaveMinigame (au.com.mineauz.minigames.menu.MenuItemSaveMinigame)1 MinigameStat (au.com.mineauz.minigames.stats.MinigameStat)1 StatSettings (au.com.mineauz.minigames.stats.StatSettings)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Material (org.bukkit.Material)1