Package org.bukkit.configuration.file

Examples of org.bukkit.configuration.file.YamlConfiguration


            e.printStackTrace();
        }
    }

    private static void loadAndUpgradeParties() {
        YamlConfiguration partiesFile = YamlConfiguration.loadConfiguration(partyFile);

        if (!partyFile.renameTo(new File(mcMMO.getFlatFileDirectory() + "parties.yml.converted"))) {
            mcMMO.p.getLogger().severe("Could not rename parties.yml to parties.yml.converted!");
            return;
        }

        ArrayList<Party> hasAlly = new ArrayList<Party>();

        for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) {
            Party party = new Party(partyName);

            String leaderName = partiesFile.getString(partyName + ".Leader");
            PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(leaderName, false);

            if (!profile.isLoaded()) {
                mcMMO.p.getLogger().warning("Could not find UUID in database for party leader " + leaderName + " in party " + partyName);
                continue;
            }

            UUID leaderUniqueId = profile.getUniqueId();

            party.setLeader(new PartyLeader(leaderUniqueId, leaderName));
            party.setPassword(partiesFile.getString(partyName + ".Password"));
            party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
            party.setLevel(partiesFile.getInt(partyName + ".Level"));
            party.setXp(partiesFile.getInt(partyName + ".Xp"));

            if (partiesFile.getString(partyName + ".Ally") != null) {
                hasAlly.add(party);
            }

            party.setXpShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ExpShareMode", "NONE")));
            party.setItemShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ItemShareMode", "NONE")));

            for (ItemShareType itemShareType : ItemShareType.values()) {
                party.setSharingDrops(itemShareType, partiesFile.getBoolean(partyName + ".ItemShareType." + itemShareType.toString(), true));
            }

            LinkedHashMap<UUID, String> members = party.getMembers();

            for (String memberName : partiesFile.getStringList(partyName + ".Members")) {
                PlayerProfile memberProfile = mcMMO.getDatabaseManager().loadPlayerProfile(memberName, false);

                if (!memberProfile.isLoaded()) {
                    mcMMO.p.getLogger().warning("Could not find UUID in database for party member " + memberName + " in party " + partyName);
                    continue;
                }

                UUID memberUniqueId = memberProfile.getUniqueId();

                members.put(memberUniqueId, memberName);
            }

            parties.add(party);
        }

        mcMMO.p.debug("Loaded (" + parties.size() + ") Parties...");

        for (Party party : hasAlly) {
            party.setAlly(PartyManager.getParty(partiesFile.getString(party.getName() + ".Ally")));
        }

        mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS_PARTY);
    }
View Full Code Here


        if (!Config.getInstance().getEntityModsEnabled()) {
            return;
        }

        File entityFile = new File(mcMMO.p.getDataFolder(), "mods" + File.separator + "entities.default.yml");
        YamlConfiguration entitiesFile = YamlConfiguration.loadConfiguration(entityFile);

        String entityName = entity.getType().toString();
        String sanitizedEntityName = entityName.replace(".", "_");

        if (entitiesFile.getKeys(false).contains(sanitizedEntityName)) {
            return;
        }

        entitiesFile.set(sanitizedEntityName + ".XP_Multiplier", 1.0D);
        entitiesFile.set(sanitizedEntityName + ".Tameable", false);
        entitiesFile.set(sanitizedEntityName + ".Taming_XP", 0);
        entitiesFile.set(sanitizedEntityName + ".CanBeSummoned", false);
        entitiesFile.set(sanitizedEntityName + ".COTW_Material", "");
        entitiesFile.set(sanitizedEntityName + ".COTW_Material_Data", 0);
        entitiesFile.set(sanitizedEntityName + ".COTW_Material_Amount", 0);

        String className = "";

        try {
            className = ((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName();
        }
        catch (Exception e) {
            if (e instanceof NoSuchFieldException || e instanceof IllegalArgumentException || e instanceof IllegalAccessException) {
                className = entity.getClass().getName();
            }
            else {
                e.printStackTrace();
            }
        }

        CustomEntity customEntity = new CustomEntity(1.0D, false, 0, false, null, 0);
        customEntityTypeMap.put(entityName, customEntity);
        customEntityClassMap.put(className, customEntity);

        try {
            entitiesFile.save(entityFile);
            mcMMO.p.debug(entity.getType().toString() + " was added to the custom entities file!");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
View Full Code Here

    /**
     * Save formula file.
     */
    public void saveFormula() {
        mcMMO.p.debug("Saving previous XP formula type...");
        YamlConfiguration formulasFile = new YamlConfiguration();
        formulasFile.set("Previous_Formula", previousFormula.toString());

        try {
            formulasFile.save(formulaFile);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

            String apiKey = null;
            String latest = null;

            if (updaterFolder.exists()) {
                if (updaterConfigFile.exists()) {
                    final YamlConfiguration config = YamlConfiguration.loadConfiguration(updaterConfigFile);
                    apiKey = config.getString("api-key");
                }
            }

            URL url;
            try {
View Full Code Here

    @Test
    public void testSerialization() throws Throwable {
        for (TestColor testColor : examples) {
            Color base = Color.fromRGB(testColor.rgb);

            YamlConfiguration toSerialize = new YamlConfiguration();
            toSerialize.set("color", base);
            String serialized = toSerialize.saveToString();

            YamlConfiguration deserialized = new YamlConfiguration();
            deserialized.loadFromString(serialized);

            assertThat(testColor.name + " on " + serialized, base, is(deserialized.getColor("color")));
        }
    }
View Full Code Here

        final InputStream defConfigStream = getResource("config.yml");
        if (defConfigStream == null) {
            return;
        }

        final YamlConfiguration defConfig;
        if (isStrictlyUTF8() || FileConfiguration.UTF8_OVERRIDE) {
            defConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8));
        } else {
            final byte[] contents;
            defConfig = new YamlConfiguration();
            try {
                contents = ByteStreams.toByteArray(defConfigStream);
            } catch (final IOException e) {
                getLogger().log(Level.SEVERE, "Unexpected failure reading config.yml", e);
                return;
            }

            final String text = new String(contents, Charset.defaultCharset());
            if (!text.equals(new String(contents, Charsets.UTF_8))) {
                getLogger().warning("Default system encoding may have misread config.yml from plugin jar");
            }

            try {
                defConfig.loadFromString(text);
            } catch (final InvalidConfigurationException e) {
                getLogger().log(Level.SEVERE, "Cannot load configuration from jar", e);
            }
        }
View Full Code Here

                }
            }
            try {
                File langFile = new File(new File(dataFolder, "Language"), cmanager.getLanguage() + ".yml");
                if (langFile.isFile()) {
                    FileConfiguration langconfig = new YamlConfiguration();
                    langconfig.load(langFile);
                    helppages = HelpEntry.parseHelp(langconfig, "CommandHelp");
                    HelpEntry.setLinesPerPage(langconfig.getInt("HelpLinesPerPage", 7));
                    InformationPager.setLinesPerPage(langconfig.getInt("HelpLinesPerPage", 7));
                    language = Language.parseText(langconfig, "Language");
                } else {
                    System.out.println("[Residence] Language file does not exist...");
                }
            } catch (Exception ex) {
View Full Code Here

    private boolean checkNewLanguageVersion(String lang) throws IOException, FileNotFoundException, InvalidConfigurationException {
        File outFile = new File(new File(this.getDataFolder(), "Language"), lang + ".yml");
        File checkFile = new File(new File(this.getDataFolder(), "Language"), "temp-" + lang + ".yml");
        if (outFile.isFile()) {
            FileConfiguration testconfig = new YamlConfiguration();
            testconfig.load(outFile);
            int oldversion = testconfig.getInt("FieldsVersion", 0);
            if (!this.writeDefaultFileFromJar(checkFile, "languagefiles/" + lang + ".yml", false)) {
                return false;
            }
            FileConfiguration testconfig2 = new YamlConfiguration();
            testconfig2.load(checkFile);
            int newversion = testconfig2.getInt("FieldsVersion", oldversion);
            if (checkFile.isFile()) {
                checkFile.delete();
            }
            if (newversion > oldversion) {
                return true;
View Full Code Here

    private static void from4() throws FileNotFoundException, IOException,
                               InvalidConfigurationException
    {
        CreeperLog.logInfo("Importing config from version 4", 1);
        YamlConfiguration config = new YamlConfiguration();
        File configFile = new File(CreeperHeal.getCHFolder() + "/config.yml");
        config.load(configFile);
        String tmp_str;
        try
        {
            tmp_str = config.getString("replacement-method", "block-per-block").trim();
        } catch (Exception e)
        {
            CreeperLog.warning("[CreeperHeal] Wrong value for replacement method field. Defaulting to block-per-block.");
            CreeperLog.warning(e.getMessage());
            tmp_str = "block-per-block";
        }
        if (!tmp_str.equalsIgnoreCase("all-at-once")
            && !tmp_str.equalsIgnoreCase("block-per-block"))
            CreeperLog.warning("[CreeperHeal] Wrong value for replacement method field. Defaulting to block-per-block.");
        waitBeforeHeal = config.getInt("wait-before-heal-explosions", 60);
        logLevel = config.getInt("verbose-level", 1);
        blockPerBlock = (tmp_str.equalsIgnoreCase("all-at-once")) ? false : true;
        teleportOnSuffocate = config.getBoolean("teleport-when-buried", true);
        waitBeforeHealBurnt = config.getInt("wait-before-heal-fire", 45);
        dropDestroyedBlocks = config.getBoolean("drop-destroyed-blocks", true);
        dropChance = config.getInt("drop-destroyed-blocks-chance", 100);
        crackDestroyedBricks = config.getBoolean("crack-destroyed-bricks", false);
        overwriteBlocks = config.getBoolean("overwrite-blocks", true);
        preventBlockFall = config.getBoolean("prevent-block-fall", true);
        distanceNear = config.getInt("distance-near", 20);
        lightweightMode = config.getBoolean("lightweight-mode", false);
        cmdAlias = config.getString("command-alias", "ch");
        logWarnings = true;
        debug = preventChainReaction = false;
        obsidianChance = 20;
        obsidianRadius = 5;
        explodeObsidian = false;
        waitBeforeBurnAgain = 240;
        config.set("config-version", 5);
        try
        {
            tmp_str = config.getString("chest-protection", "no").trim().toLowerCase();
        } catch (Exception e)
        {
            CreeperLog.warning("[CreeperHeal] Wrong value for chest protection field. Defaulting to no.");
            CreeperLog.warning(e.getMessage());
            tmp_str = "no";
View Full Code Here

    private static void from5() throws FileNotFoundException, IOException,
                               InvalidConfigurationException
    {
        CreeperLog.logInfo("Importing config from version 5", 1);

        YamlConfiguration config = new YamlConfiguration();
        File configFile = new File(CreeperHeal.getCHFolder() + "/config.yml");
        config.load(configFile);
        File advancedFile = new File(CreeperHeal.getCHFolder() + "/advanced.yml");

        blockPerBlockInterval = config.getInt("replacement.block-per-block.interval", 20);
        waitBeforeHeal = config.getInt("replacement.wait-before-heal.explosions", 60);
        blockPerBlock = config.getBoolean("replacement.block-per-block", true);
        waitBeforeHealBurnt = config.getInt("replacement.wait-before-heal.fire", 45);
        crackDestroyedBricks = config.getBoolean("replacement.crack-destroyed-bricks", false);
        boolean replaceAllChests = config.getBoolean("replacement.ignore-chests.all", false);
        replaceProtectedChests = replaceAllChests
                                 || config.getBoolean("replacement.ignore-chests.protected", false);
        logLevel = config.getInt("advanced.verbose-level", 1);
        teleportOnSuffocate = config.getBoolean("advanced.teleport-when-buried", true);
        dropDestroyedBlocks = config.getBoolean("advanced.drop-destroyed-blocks.enabled", true);
        dropChance = config.getInt("advanced.drop-destroyed-blocks.chance", 100);
        overwriteBlocks = config.getBoolean("advanced.replacement-conflict.overwrite", true);
        preventBlockFall = config.getBoolean("advanced.prevent-block-fall", true);
        distanceNear = config.getInt("advanced.distance-near", 20);
        lightweightMode = config.getBoolean("advanced.lightweight-mode", false);
        cmdAlias = config.getString("advanced.command-alias", "ch");
        logWarnings = config.getBoolean("advanced.log-warnings", true);
        preventChainReaction = config.getBoolean("advanced.prevent-chain-reaction", false);
        explodeObsidian = config.getBoolean("advanced.obsidian.explode", false);
        obsidianRadius = config.getInt("advanced.obsidian.radius", 5);
        obsidianChance = config.getInt("advanced.obsidian.chance", 20);
        debug = config.getBoolean("advanced.debug-messages", false);
        waitBeforeBurnAgain = 240;

        configFile.delete();
        advancedFile.delete();
View Full Code Here

TOP

Related Classes of org.bukkit.configuration.file.YamlConfiguration

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.