Package org.bukkit.configuration

Examples of org.bukkit.configuration.ConfigurationSection


    /**
     * Load the global settings.
     */
    public void loadSettings() {
        ConfigurationSection section = plugin.getConfig().getConfigurationSection("global-settings");
        ConfigUtils.addMissingRemoveObsolete(plugin, "global-settings.yml", section);

        // Grab the commands string
        String cmds = section.getString("allowed-commands", "");

        // Split by commas
        String[] parts = cmds.split(",");

        // Add in the /ma command.
View Full Code Here


    /**
     * Load all class-related stuff.
     */
    public void loadClasses() {
        ConfigurationSection section = makeSection(plugin.getConfig(), "classes");
        ConfigUtils.addIfEmpty(plugin, "classes.yml", section);


        // Establish the map.
        classes = new HashMap<String, ArenaClass>();
        Set<String> classNames = section.getKeys(false);

        // Load each individual class.
        for (String className : classNames) {
            loadClass(className);
        }
View Full Code Here

    /**
     * Helper method for loading a single class.
     */
    private ArenaClass loadClass(String classname) {
        ConfigurationSection section = config.getConfigurationSection("classes." + classname);
        String lowercase = classname.toLowerCase();

        // If the section doesn't exist, the class doesn't either.
        if (section == null) {
            Messenger.severe("Failed to load class '" + classname + "'.");
            return null;
        }
       
        // Check if weapons and armor for this class should be unbreakable
        boolean weps = section.getBoolean("unbreakable-weapons", true);
        boolean arms = section.getBoolean("unbreakable-armor", true);

        // Grab the class price, if any
        double price = -1D;
        String priceString = section.getString("price", null);
        if (priceString != null) {
            ItemStack priceItem = ItemParser.parseItem(priceString);
            if (priceItem != null && priceItem.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
                price = (priceItem.getAmount() + (priceItem.getDurability() / 100D));
            } else {
                Messenger.warning("The price for class '" + classname + "' could not be parsed!");
                Messenger.warning("- expected e.g. '$10',  found '" + priceString + "'");
            }
        }

        // Create an ArenaClass with the config-file name.
        ArenaClass arenaClass = new ArenaClass(classname, price, weps, arms);

        // Parse the items-node
        List<String> items = section.getStringList("items");
        if (items == null || items.isEmpty()) {
            String str = section.getString("items", "");
            List<ItemStack> stacks = ItemParser.parseItems(str);
            arenaClass.setItems(stacks);
        } else {
            List<ItemStack> stacks = new ArrayList<ItemStack>();
            for (String item : items) {
                ItemStack stack = ItemParser.parseItem(item);
                if (stack != null) {
                    stacks.add(stack);
                }
            }
            arenaClass.setItems(stacks);
        }

        // And the legacy armor-node
        String armor = section.getString("armor", "");
        if (!armor.equals("")) {
            List<ItemStack> stacks = ItemParser.parseItems(armor);
            arenaClass.setArmor(stacks);
        }

        // Get armor strings
        String head  = section.getString("helmet", null);
        String chest = section.getString("chestplate", null);
        String legs  = section.getString("leggings", null);
        String feet  = section.getString("boots", null);

        // Parse to ItemStacks
        ItemStack helmet     = ItemParser.parseItem(head);
        ItemStack chestplate = ItemParser.parseItem(chest);
        ItemStack leggings   = ItemParser.parseItem(legs);
View Full Code Here

        // Create the node.
        config.set(path, "");

        // Grab the section, create if missing
        ConfigurationSection section = config.getConfigurationSection(path);
        if (section == null) section = config.createSection(path);

        // Take the current items and armor.
        section.set("items", ItemParser.parseString(inv.getContents()));
        section.set("armor", ItemParser.parseString(inv.getArmorContents()));

        // If the helmet isn't a real helmet, set it explicitly.
        ItemStack helmet = inv.getHelmet();
        if (helmet != null && ArmorType.getType(helmet) != ArmorType.HELMET) {
            section.set("helmet", ItemParser.parseString(helmet));
        }

        // Save changes.
        plugin.saveConfig();
View Full Code Here

        String path = "classes." + classname;
        if (config.getConfigurationSection(path) == null)
            return false;

        // Grab the class section
        ConfigurationSection section = config.getConfigurationSection(path);

        // Get any previous nodes
        List<String> nodes = section.getStringList("permissions");
        if (nodes.contains(perm) && add) {
            return false;
        }
        else if (nodes.contains(perm) && !add) {
            nodes.remove(perm);
        }
        else if (!nodes.contains(perm) && add) {
            removeContradictions(nodes, perm);
            nodes.add(perm);
        }
        else if (!nodes.contains(perm) && !add) {
            return false;
        }

        // Replace the set.
        section.set("permissions", nodes);
        plugin.saveConfig();

        // Reload the class.
        loadClass(classname);
        return true;
View Full Code Here

    /**
     * Load all arena-related stuff.
     */
    public void loadArenas() {
        ConfigurationSection section = makeSection(config, "arenas");
        Set<String> arenanames = section.getKeys(false);

        // If no arenas were found, create a default node.
        if (arenanames == null || arenanames.isEmpty()) {
            createArenaNode(section, "default", plugin.getServer().getWorlds().get(0), false);
        }
View Full Code Here

        }
    }

    // Load an already existing arena node
    private Arena loadArena(String arenaname) {
        ConfigurationSection section  = makeSection(config, "arenas." + arenaname);
        ConfigurationSection settings = makeSection(section, "settings");
        String worldName = settings.getString("world", "");
        World world;

        if (!worldName.equals("")) {
            world = plugin.getServer().getWorld(worldName);
            if (world == null) {
View Full Code Here

    }

    // Create and load a new arena node
    @Override
    public Arena createArenaNode(String arenaName, World world) {
        ConfigurationSection section = makeSection(config, "arenas");
        return createArenaNode(section, arenaName, world, true);
    }
View Full Code Here

    // Create a new arena node, and (optionally) load it
    private Arena createArenaNode(ConfigurationSection arenas, String arenaName, World world, boolean load) {
        if (arenas.contains(arenaName)) {
            throw new IllegalArgumentException("Arena already exists!");
        }
        ConfigurationSection section = makeSection(arenas, arenaName);

        // Add missing settings and remove obsolete ones
        ConfigUtils.addMissingRemoveObsolete(plugin, "settings.yml", makeSection(section, "settings"));
        section.set("settings.world", world.getName());
        ConfigUtils.addIfEmpty(plugin, "waves.yml",   makeSection(section, "waves"));
        ConfigUtils.addIfEmpty(plugin, "rewards.yml", makeSection(section, "rewards"));
        plugin.saveConfig();

        // Load the arena
View Full Code Here

            return result;
        }
       
        // Otherwise, parse each wave in the branch.
        for (String wave : waves) {
            ConfigurationSection waveSection = config.getConfigurationSection(wave);
            Wave w = parseWave(arena, wave, waveSection, branch);
           
            // Only add properly parsed waves.
            if (w == null) {
                continue;
View Full Code Here

TOP

Related Classes of org.bukkit.configuration.ConfigurationSection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.