Search in sources :

Example 1 with MinigameSave

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

the class Minigames method setupLoadOuts.

private void setupLoadOuts() {
    final MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
    final Set<String> keys = globalLoadouts.getConfig().getKeys(false);
    for (final String loadout : keys) {
        this.minigameManager.addLoadout(loadout);
        ConfigurationSection loadOutSection = globalLoadouts.getConfig().getConfigurationSection(loadout);
        if (loadOutSection != null) {
            final Set<String> items = loadOutSection.getKeys(false);
            for (final String slot : items) {
                if (COMPILE.matcher(slot).matches()) {
                    this.minigameManager.getLoadout(loadout).addItem(globalLoadouts.getConfig().getItemStack(loadout + '.' + slot), Integer.parseInt(slot));
                }
            }
        }
        if (globalLoadouts.getConfig().contains(loadout + ".potions")) {
            ConfigurationSection potionLoadOutSection = globalLoadouts.getConfig().getConfigurationSection(loadout + ".potions");
            if (potionLoadOutSection != null) {
                final Set<String> pots = potionLoadOutSection.getKeys(false);
                for (final String eff : pots) {
                    PotionEffectType type = PotionEffectType.getByName(eff);
                    if (type != null) {
                        final PotionEffect effect = new PotionEffect(type, globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".dur"), globalLoadouts.getConfig().getInt(loadout + ".potions." + eff + ".amp"));
                        this.minigameManager.getLoadout(loadout).addPotionEffect(effect);
                    }
                }
            }
        }
        if (globalLoadouts.getConfig().contains(loadout + ".usepermissions")) {
            this.minigameManager.getLoadout(loadout).setUsePermissions(globalLoadouts.getConfig().getBoolean(loadout + ".usepermissions"));
        }
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) MinigameSave(au.com.mineauz.minigames.config.MinigameSave) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 2 with MinigameSave

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

the class Minigames method onDisable.

public void onDisable() {
    if (getPlugin() == null) {
        log().info("Minigames is disabled");
        return;
    }
    final PluginDescriptionFile desc = this.getDescription();
    for (final Player p : this.getServer().getOnlinePlayers()) {
        if (this.playerManager.getMinigamePlayer(p).isInMinigame()) {
            this.playerManager.quitMinigame(this.playerManager.getMinigamePlayer(p), true);
        }
    }
    for (final Minigame minigame : this.minigameManager.getAllMinigames().values()) {
        if (minigame.getType() == MinigameType.GLOBAL && "treasure_hunt".equals(minigame.getMechanicName()) && minigame.isEnabled()) {
            if (minigame.getMinigameTimer() != null) {
                minigame.getMinigameTimer().stopTimer();
            }
            TreasureHuntMechanic.removeTreasure(minigame);
        }
    }
    for (final Minigame mg : this.minigameManager.getAllMinigames().values()) {
        mg.saveMinigame();
    }
    this.backend.shutdown();
    this.playerManager.saveDeniedCommands();
    final MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
    if (this.minigameManager.hasLoadouts()) {
        for (final String loadout : this.minigameManager.getLoadouts()) {
            for (final Integer slot : this.minigameManager.getLoadout(loadout).getItems()) {
                globalLoadouts.getConfig().set(loadout + '.' + slot, this.minigameManager.getLoadout(loadout).getItem(slot));
            }
            if (!this.minigameManager.getLoadout(loadout).getAllPotionEffects().isEmpty()) {
                for (final PotionEffect eff : this.minigameManager.getLoadout(loadout).getAllPotionEffects()) {
                    globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".amp", eff.getAmplifier());
                    globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".dur", eff.getDuration());
                }
            } else {
                globalLoadouts.getConfig().set(loadout + ".potions", null);
            }
            if (this.minigameManager.getLoadout(loadout).getUsePermissions()) {
                globalLoadouts.getConfig().set(loadout + ".usepermissions", true);
            } else {
                globalLoadouts.getConfig().set(loadout + ".usepermissions", null);
            }
        }
    } else {
        globalLoadouts.getConfig().set("globalloadouts", null);
    }
    globalLoadouts.saveConfig();
    this.minigameManager.saveRewardSigns();
    resourceManager.saveResources();
    log().info(desc.getName() + " successfully disabled.");
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) PotionEffect(org.bukkit.potion.PotionEffect) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) Minigame(au.com.mineauz.minigames.minigame.Minigame) MinigameSave(au.com.mineauz.minigames.config.MinigameSave)

Example 3 with MinigameSave

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

the class Minigame method loadMinigame.

public void loadMinigame() {
    MinigameSave minigame = new MinigameSave(name, "config");
    FileConfiguration cfg = minigame.getConfig();
    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) {
            Material material = Material.matchMaterial(block);
            if (material == null) {
                material = Material.matchMaterial(block, true);
                if (material == null) {
                    Minigames.log().info(" Failed to match config material.");
                    Minigames.log().info(block + " did not match a material please update config: " + this.name);
                } else {
                    Minigames.log().info(block + " is a legacy material please review the config we will attempt to auto update..but you may want to add newer materials GAME: " + this.name);
                    getBlockRecorder().addWBBlock(material);
                }
            } else {
                getBlockRecorder().addWBBlock(material);
            }
        }
    }
    // 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.getPlugin(), () -> Minigames.getPlugin().getMinigameManager().startGlobalMinigame(mgm, null));
    }
    getScoreboardData().loadDisplays(minigame, this);
    ListenableFuture<Map<MinigameStat, StatSettings>> settingsFuture = Minigames.getPlugin().getBackend().loadStatSettings(this);
    Minigames.getPlugin().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) Material(org.bukkit.Material) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString) MinigameSave(au.com.mineauz.minigames.config.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)

Example 4 with MinigameSave

use of au.com.mineauz.minigames.config.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<>();
        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.getPlugin().getBackend().saveStatSettings(this, statSettings.values());
    minigame.saveConfig();
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) MinigameModule(au.com.mineauz.minigames.minigame.modules.MinigameModule) Material(org.bukkit.Material) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString) MinigameSave(au.com.mineauz.minigames.config.MinigameSave)

Example 5 with MinigameSave

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

Aggregations

MinigameSave (au.com.mineauz.minigames.config.MinigameSave)13 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)6 File (java.io.File)3 MenuItemString (au.com.mineauz.minigames.menu.MenuItemString)2 Minigame (au.com.mineauz.minigames.minigame.Minigame)2 MinigameModule (au.com.mineauz.minigames.minigame.modules.MinigameModule)2 Material (org.bukkit.Material)2 PotionEffect (org.bukkit.potion.PotionEffect)2 BasicRecorder (au.com.mineauz.minigames.blockRecorder.BasicRecorder)1 DisplayManager (au.com.mineauz.minigames.display.DisplayManager)1 MultiplayerType (au.com.mineauz.minigames.gametypes.MultiplayerType)1 SingleplayerType (au.com.mineauz.minigames.gametypes.SingleplayerType)1 MinigameManager (au.com.mineauz.minigames.managers.MinigameManager)1 MinigamePlayerManager (au.com.mineauz.minigames.managers.MinigamePlayerManager)1 ResourcePackManager (au.com.mineauz.minigames.managers.ResourcePackManager)1 MenuItemSaveMinigame (au.com.mineauz.minigames.menu.MenuItemSaveMinigame)1 MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)1 MinigameStat (au.com.mineauz.minigames.stats.MinigameStat)1 StatSettings (au.com.mineauz.minigames.stats.StatSettings)1 Location (org.bukkit.Location)1