Search in sources :

Example 6 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project Minigames by AddstarMC.

the class RewardGroup method load.

public static RewardGroup load(ConfigurationSection section, Rewards container) {
    RewardRarity rarity = RewardRarity.valueOf(section.getString("rarity"));
    RewardGroup group = new RewardGroup(section.getName(), rarity);
    // Load contents
    for (String key : section.getKeys(false)) {
        if (key.equals("rarity")) {
            continue;
        }
        ConfigurationSection itemSection = section.getConfigurationSection(key);
        // TODO: Remove after 1.7 release
        if (!itemSection.contains("data")) {
            ItemStack item = itemSection.getItemStack("item");
            if (item != null) {
                RewardType it = RewardTypes.getRewardType("ITEM", container);
                it.loadReward("item", itemSection);
                group.addItem(it);
            } else {
                RewardType it = RewardTypes.getRewardType("MONEY", container);
                it.loadReward("money", itemSection);
                group.addItem(it);
            }
        } else {
            RewardType rew = RewardTypes.getRewardType(itemSection.getString("type"), container);
            rew.loadReward("data", itemSection);
            group.addItem(rew);
        }
    }
    return group;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 7 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project Denizen-For-Bukkit by DenizenScript.

the class Denizen method updateSaves.

public void updateSaves() {
    int saves_version = 1;
    if (savesConfig.contains("a_saves.version")) {
        saves_version = savesConfig.getInt("a_saves.version");
    }
    if (saves_version == 1) {
        dB.log("Updating saves from v1 to v2...");
        ConfigurationSection section = savesConfig.getConfigurationSection("Players");
        if (section != null) {
            ArrayList<String> keyList = new ArrayList<String>(section.getKeys(false));
            // Remove UPPERCASE cooldown saves from the list - handled manually
            for (int i = 0; i < keyList.size(); i++) {
                String key = keyList.get(i);
                if (!key.equals(key.toUpperCase()) && keyList.contains(key.toUpperCase())) {
                    keyList.remove(key.toUpperCase());
                }
            }
            // Handle all actual player saves
            for (int i = 0; i < keyList.size(); i++) {
                String key = keyList.get(i);
                try {
                    // Flags
                    ConfigurationSection playerSection = savesConfig.getConfigurationSection("Players." + key);
                    if (playerSection == null) {
                        dB.echoError("Can't update saves for player '" + key + "' - broken YAML section!");
                        continue;
                    }
                    Map<String, Object> keys = playerSection.getValues(true);
                    if (!key.equals(key.toUpperCase()) && savesConfig.contains("Players." + key.toUpperCase())) {
                        // Cooldowns
                        keys.putAll(savesConfig.getConfigurationSection("Players." + key.toUpperCase()).getValues(true));
                        savesConfig.set("Players." + key.toUpperCase(), null);
                    }
                    dPlayer player = dPlayer.valueOf(key);
                    if (player == null) {
                        dB.echoError("Can't update saves for player '" + key + "' - invalid name!");
                        savesConfig.createSection("PlayersBACKUP." + key, keys);
                    // TODO: READ FROM BACKUP AT LOG IN
                    } else {
                        savesConfig.createSection("Players." + player.getSaveName(), keys);
                    }
                    savesConfig.set("Players." + key, null);
                } catch (Exception ex) {
                    dB.echoError(ex);
                }
            }
        }
        section = savesConfig.getConfigurationSection("Listeners");
        if (section != null) {
            for (String key : section.getKeys(false)) {
                try {
                    dPlayer player = dPlayer.valueOf(key);
                    if (player == null) {
                        dB.log("Warning: can't update listeners for player '" + key + "' - invalid name!");
                    } else // Listeners
                    {
                        savesConfig.createSection("Listeners." + player.getSaveName(), savesConfig.getConfigurationSection("Listeners." + key).getValues(true));
                    }
                    savesConfig.set("Listeners." + key, null);
                } catch (Exception ex) {
                    dB.echoError(ex);
                }
            }
        }
        savesConfig.set("a_saves.version", "2");
        dB.log("Done!");
    }
}
Also used : ArrayList(java.util.ArrayList) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) IOException(java.io.IOException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 8 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project Glowstone by GlowstoneMC.

the class GlowServer method getGenerator.

/**
     * Gets the default ChunkGenerator for the given environment and type.
     *
     * @return The ChunkGenerator.
     */
private ChunkGenerator getGenerator(String name, Environment environment, WorldType type) {
    // find generator based on configuration
    ConfigurationSection worlds = config.getWorlds();
    if (worlds != null) {
        String genName = worlds.getString(name + ".generator", null);
        ChunkGenerator generator = WorldCreator.getGeneratorForName(name, genName, getConsoleSender());
        if (generator != null) {
            return generator;
        }
    }
    // find generator based on environment and world type
    if (environment == Environment.NETHER) {
        return new NetherGenerator();
    } else if (environment == Environment.THE_END) {
        return new TheEndGenerator();
    } else {
        if (type == WorldType.FLAT) {
            return new SuperflatGenerator();
        } else {
            return new OverworldGenerator();
        }
    }
}
Also used : ChunkGenerator(org.bukkit.generator.ChunkGenerator) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 9 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project Glowstone by GlowstoneMC.

the class GlowServer method enablePlugins.

/**
     * Enable all plugins of the given load order type.
     *
     * @param type The type of plugin to enable.
     */
private void enablePlugins(PluginLoadOrder type) {
    if (type == PluginLoadOrder.STARTUP) {
        helpMap.clear();
        helpMap.loadConfig(config.getConfigFile(Key.HELP_FILE));
    }
    // load all the plugins
    Plugin[] plugins = pluginManager.getPlugins();
    for (Plugin plugin : plugins) {
        if (!plugin.isEnabled() && plugin.getDescription().getLoad() == type) {
            List<Permission> perms = plugin.getDescription().getPermissions();
            for (Permission perm : perms) {
                try {
                    pluginManager.addPermission(perm);
                } catch (IllegalArgumentException ex) {
                    getLogger().log(Level.WARNING, "Plugin " + plugin.getDescription().getFullName() + " tried to register permission '" + perm.getName() + "' but it's already registered", ex);
                }
            }
            try {
                pluginManager.enablePlugin(plugin);
            } catch (Throwable ex) {
                logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex);
            }
        }
    }
    if (type == PluginLoadOrder.POSTWORLD) {
        commandMap.setFallbackCommands();
        commandMap.registerServerAliases();
        DefaultPermissions.registerCorePermissions();
        helpMap.initializeCommands();
        helpMap.amendTopics(config.getConfigFile(Key.HELP_FILE));
        // load permissions.yml
        ConfigurationSection permConfig = config.getConfigFile(Key.PERMISSIONS_FILE);
        Map<String, Map<String, Object>> data = new HashMap<>();
        permConfig.getValues(false).forEach((key, value) -> data.put(key, ((MemorySection) value).getValues(false)));
        List<Permission> perms = Permission.loadPermissions(data, "Permission node '%s' in permissions config is invalid", PermissionDefault.OP);
        for (Permission perm : perms) {
            try {
                pluginManager.addPermission(perm);
            } catch (IllegalArgumentException ex) {
                getLogger().log(Level.WARNING, "Permission config tried to register '" + perm.getName() + "' but it's already registered", ex);
            }
        }
    }
}
Also used : MemorySection(org.bukkit.configuration.MemorySection) Permission(org.bukkit.permissions.Permission) HelpMap(org.bukkit.help.HelpMap) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 10 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project Glowstone by GlowstoneMC.

the class GlowHelpMap method amendTopics.

/**
     * Process topic amendments from help.yml.
     *
     * @param config The configuration to read from.
     */
public void amendTopics(ConfigurationSection config) {
    ConfigurationSection amendedTopics = config.getConfigurationSection("amended-topics");
    if (amendedTopics != null) {
        for (String key : amendedTopics.getKeys(false)) {
            HelpTopic target = getHelpTopic(key);
            if (target == null) {
                continue;
            }
            ConfigurationSection amend = amendedTopics.getConfigurationSection(key);
            if (amend == null) {
                continue;
            }
            target.amendTopic(color(amend.getString("shortText")), color(amend.getString("fullText")));
            String perm = amend.getString("permission", null);
            if (perm != null) {
                // empty string can be specified to remove permission
                target.amendCanSee(perm.isEmpty() ? null : perm);
            }
        }
    }
}
Also used : ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ConfigurationSection (org.bukkit.configuration.ConfigurationSection)49 ItemStack (org.bukkit.inventory.ItemStack)7 IOException (java.io.IOException)6 Material (org.bukkit.Material)6 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)6 File (java.io.File)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)3 EntityType (org.bukkit.entity.EntityType)3 Rewards (au.com.mineauz.minigames.minigame.reward.Rewards)2 ChatColor (com.gamingmesh.jobs.util.ChatColor)2 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)2 BigDecimal (java.math.BigDecimal)2 Enchantment (org.bukkit.enchantments.Enchantment)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