Package org.bukkit.configuration.file

Examples of org.bukkit.configuration.file.FileConfiguration


   throw new FileNotFoundException("\"" + directory.getPath() + "\" is not a directory");
  for (File file : directory.listFiles()) {
   String filename = file.getName();
   if (filename.endsWith(".yml")) {
    String sectionName = filename.replaceAll("\\.yml$", "");
    FileConfiguration sectionConfig = new YamlConfiguration();
    sectionConfig.options().pathSeparator(this.options().pathSeparator());
    sectionConfig.load(file);
    this.putSection(sectionName, sectionConfig);
   }
  }
}
View Full Code Here


   throw new FileNotFoundException("\"" + directory.getPath() + "\" is not a directory");
  for (String sectionName : this.getKeys(false)) {
   if (section != null && !sectionName.equals(section))
    continue;
   if (this.isConfigurationSection(sectionName)) {
    FileConfiguration sectionConfig = new YamlConfiguration();
    sectionConfig.addDefaults(this.getConfigurationSection(sectionName).getValues(true));
    sectionConfig.options().copyDefaults(true);
    sectionConfig.save(new File(directory, sectionName + ".yml"));
   }
  }
}
View Full Code Here

    def.put("overrideWorldEditCommands", false);
    def.put("tools", Arrays.asList(270, 274, 278, 285));
    def.put("dontBreak", Arrays.asList(7));
    def.put("disableDrops", false);
    def.put("disableToolWear", false);
    final FileConfiguration config = getConfig();
    for (final Entry<String, Object> e : def.entrySet())
      if (!config.contains(e.getKey()))
        config.set(e.getKey(), e.getValue());
    saveConfig();
    final ConfigurationSection cfg = getConfig();
    tools = new HashSet<Integer>(cfg.getIntegerList("tools"));
    dontBreak = new HashSet<Integer>(cfg.getIntegerList("dontBreak"));
    disableDrops = cfg.getBoolean("disableDrops", false);
View Full Code Here

            log.severe("PermissionsEx not found, disabling");
            this.getPluginLoader().disablePlugin(this);
            return;
        }

        FileConfiguration config = this.getConfig();

        if (config.get("enable") == null) { // Migrate
            this.initializeConfiguration(config);
        }

        this.listener = new ChatListener(config);

        if (config.getBoolean("enable", false)) {
            this.getServer().getPluginManager().registerEvents(listener, this);
            log.info("ChatManager enabled!");
            // Make sure MV didn't load before we did.
            this.listener.checkForMultiverse(this.getServer().getPluginManager().getPlugin("Multiverse-Core"));
        } else {
View Full Code Here

    protected void initializeConfiguration(FileConfiguration config) {
        // At migrate and setup defaults
        PermissionsEx pex = (PermissionsEx) this.getServer().getPluginManager().getPlugin("PermissionsEx");

        FileConfiguration pexConfig = pex.getConfig();

        // Flags
        config.set("enable", pexConfig.getBoolean("permissions.chat.enable", false));
        config.set("message-format", pexConfig.getString("permissions.chat.format", ChatListener.MESSAGE_FORMAT));
        config.set("global-message-format", pexConfig.getString("permissions.chat.global-format", ChatListener.GLOBAL_MESSAGE_FORMAT));
        config.set("ranged-mode", pexConfig.getBoolean("permissions.chat.force-ranged", ChatListener.RANGED_MODE));
        config.set("chat-range", pexConfig.getDouble("permissions.chat.chat-range", ChatListener.CHAT_RANGE));
       
        pex.saveConfig();
    }
View Full Code Here

    }

    @Override
    protected void loadFile() {
        super.loadFile();
        FileConfiguration internalConfig = YamlConfiguration.loadConfiguration(plugin.getResource(fileName));

        Set<String> configKeys = config.getKeys(true);
        Set<String> internalConfigKeys = internalConfig.getKeys(true);

        boolean needSave = false;

        Set<String> oldKeys = new HashSet<String>(configKeys);
        oldKeys.removeAll(internalConfigKeys);

        Set<String> newKeys = new HashSet<String>(internalConfigKeys);
        newKeys.removeAll(configKeys);

        // Don't need a re-save if we have old keys sticking around?
        // Would be less saving, but less... correct?
        if (!newKeys.isEmpty() || !oldKeys.isEmpty()) {
            needSave = true;
        }

        for (String key : oldKeys) {
            plugin.debug("Removing unused key: " + key);
            config.set(key, null);
        }

        for (String key : newKeys) {
            plugin.debug("Adding new key: " + key + " = " + internalConfig.get(key));
            config.set(key, internalConfig.get(key));
        }

        if (needSave) {
            // Get Bukkit's version of an acceptable config with new keys, and no old keys
            String output = config.saveToString();

            // Convert to the superior 4 space indentation
            output = output.replace("  ", "    ");

            // Rip out Bukkit's attempt to save comments at the top of the file
            while (output.replaceAll("[//s]", "").startsWith("#")) {
                output = output.substring(output.indexOf('\n', output.indexOf('#')) + 1);
            }

            // Read the internal config to get comments, then put them in the new one
            try {
                // Read internal
                BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(fileName)));
                HashMap<String, String> comments = new HashMap<String, String>();
                String temp = "";

                String line;
                while ((line = reader.readLine()) != null) {
                    if (line.contains("#")) {
                        temp += line + "\n";
                    }
                    else if (line.contains(":")) {
                        line = line.substring(0, line.indexOf(":") + 1);
                        if (!temp.isEmpty()) {
                            comments.put(line, temp);
                            temp = "";
                        }
                    }
                }

                // Dump to the new one
                for (String key : comments.keySet()) {
                    if (output.contains(key)) {
                        output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key));
                    }
                }
            }
            catch (Exception e) {
                e.printStackTrace();
            }

            // Save it
            try {
                String saveName = fileName;
                // At this stage we cannot guarantee that Config has been loaded, so we do the check directly here
                if (!plugin.getConfig().getBoolean("General.Config_Update_Overwrite", true)) {
                    saveName += ".new";
                }

                BufferedWriter writer = new BufferedWriter(new FileWriter(new File(plugin.getDataFolder(), saveName)));
                writer.write(output);
                writer.flush();
                writer.close();
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        else {
            for (String key : configKeys) {
                if (!config.isConfigurationSection(key) && !config.get(key).equals(internalConfig.get(key))) {
                    MetricsManager.customConfig();
                    break;
                }
            }
        }
View Full Code Here

    public static boolean getWorldChangeCheck() {
        return Settings.worldChangeCheck;
    }

    static void freshStart(VanishPlugin plugin) {
        final FileConfiguration config = plugin.getConfig();
        config.options().copyDefaults(true);
        final int ver = config.getInt("configVersionDoNotTouch.SeriouslyThisWillEraseYourConfig", 0);
        if (ver != Settings.confVersion) {
            plugin.getLogger().info("Attempting to update your configuration. Check to make sure it's ok");
            if (ver < 1) {
                config.set("hooks.spoutcraft", config.getBoolean("spoutcraft.enable", true));
                config.set("spoutcraft.enable", null);
                config.set("spoutcraft", null);
            }
            if ((ver <= 1) || config.contains("permtest.enable")) {
                final boolean permtest = config.getBoolean("permtest.enable", false);
                config.set("permtest.enable", null);
                config.set("permtest", permtest);
                config.set("enableColoration", null);
                config.set("enableTabControl", null);
                final boolean updates = config.getBoolean("updates.check", true);
                config.set("updates.check", null);
                config.set("checkupdates", updates);
            }
            if ((ver <= 3)) {
                config.set("effects.lightning.count", 30);
            }
            if ((ver <= 4)) {
                config.set("colornametags", true);
            }
            config.set("configVersionDoNotTouch.SeriouslyThisWillEraseYourConfig", Settings.confVersion);
            plugin.saveConfig();
        }
        Settings.enablePermTest = config.getBoolean("permtest", false);
        Settings.fakeJoin = config.getString("fakeannounce.join", "%p joined the game.").replace("&&", String.valueOf(ChatColor.COLOR_CHAR));
        Settings.fakeQuit = config.getString("fakeannounce.quit", "%p left the game.").replace("&&", String.valueOf(ChatColor.COLOR_CHAR));
        Settings.autoFakeJoinSilent = config.getBoolean("fakeannounce.automaticforsilentjoin", false);
        Settings.worldChangeCheck = config.getBoolean("permissionsupdates.checkonworldchange", false);
        Settings.lightningEffectCount = config.getInt("effects.lightning.count", 30);
        if (Settings.lightningEffectCount < 1) {
            Settings.lightningEffectCount = 1;
        }
        if (config.getBoolean("debug", false)) {
            Debuggle.itsGoTime(plugin);
        } else {
            Debuggle.nah();
        }
    }
View Full Code Here

        this.skins = new HashMap<String, String>();
        this.titles = new HashMap<String, String>();
        this.bars = new HashMap<String, StatusBar>();
        this.playerDataMap = new HashMap<String, PlayerData>();
        final File confFile = new File(this.plugin.getDataFolder(), "spoutcraft.yml");
        final FileConfiguration config = YamlConfiguration.loadConfiguration(confFile);
        config.options().copyDefaults(true);
        final InputStream stream = this.plugin.getResource("spoutcraft.yml");
        if (stream == null) {
            this.plugin.getLogger().info("Defaults for spoutcraft.yml not loaded");
            this.plugin.getLogger().info("The /reload command is not fully supported by this plugin or Spout");
            this.enabled = false;
            return;
        }
        config.setDefaults(YamlConfiguration.loadConfiguration(stream));
        try {
            config.save(confFile);
        } catch (final IOException e) {
            this.plugin.getServer().getLogger().log(Level.SEVERE, "Could not save spoutcraft.yml", e);
        }
        for (final String skinGroup : config.getConfigurationSection("skins").getKeys(false)) {
            this.skins.put(skinGroup, config.getString("skins." + skinGroup));
        }
        for (final String cloakGroup : config.getConfigurationSection("cloaks").getKeys(false)) {
            this.cloaks.put(cloakGroup, config.getString("cloaks." + cloakGroup));
        }
        for (final String titleGroup : config.getConfigurationSection("titles").getKeys(false)) {
            this.titles.put(titleGroup, config.getString("titles." + titleGroup).replace("%r", "\n").replace("&&", String.valueOf(ChatColor.COLOR_CHAR)));
        }
    }
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

TOP

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

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.