Package org.bukkit.configuration.file

Examples of org.bukkit.configuration.file.FileConfiguration


  public void updateLanguageFiles() {
    // load language files one by one
    for (String language : ConfigHelper.languagesAvailable) {
      // load saved file from data folder
      File languageFile = new File(SimpleSpleef.getPlugin().getDataFolder(), "lang_" + language + ".yml");
      FileConfiguration languageConfig;
      try {
        languageConfig = YamlConfiguration.loadConfiguration(languageFile);
      } catch (Exception e) {
        SimpleSpleef.log.severe("[SimpleSpleef] Could not load language file " + languageFile + "! Please convert it to UTF-8.");
        continue; // ignore updating language files
      }
     
      // get default config from resource
      InputStream languageConfigStream = SimpleSpleef.getPlugin().getResource("lang_" + language + ".yml");
        if (languageConfigStream != null) {
          // read into string - this will circumvent breaks in non-UTF-8-environments
          YamlConfiguration defConfig = loadUTF8Stream(languageConfigStream, "lang_" + language + ".yml");
          // the above is the same as
            //YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(languageConfigStream);
          // only save...
          if (defConfig == null) continue; // errors have been logged already
            // update config
            languageConfig.setDefaults(defConfig);
            languageConfig.options().copyDefaults(true); // copy defaults, too
            // force update of admin.help
            languageConfig.set("admin.help", defConfig.getString("admin.help"));
            try {
              // save updated config
              languageConfig.save(languageFile);
            } catch (Exception e) {
              SimpleSpleef.log.warning("[SimpleSpleef] Warning: Could not write lang_" + language + ".yml - reason: " + e.getMessage());
            }
        }
    }
View Full Code Here


  /**
   * compile the command patterns
   */
  public void compileCommandPatterns() {
    FileConfiguration config = SimpleSpleef.getPlugin().getConfig();

    // compile command patterns, if settings are set to do so
    if (config.getBoolean("checkCommands.activateWhitelist", true) && config.isList("checkCommands.whitelist")) {
      // renew pattern list
      patterns = new LinkedList<Pattern>();

      // compile
      for (String pattern : config.getStringList("checkCommands.whitelist")) {
        patterns.add(Pattern.compile(pattern));
      }
    } else patterns = null;
  }
View Full Code Here

      log.info("[" + getDescription().getName() + "] Reloading plugin configuration files.");
      this.reloadConfig();
    }
   
   
    FileConfiguration  properties = this.getConfig();
    boolean        propChanged = true;
    //boolean      tempBoolean;
   
   
    msgUser = properties.getBoolean("enable-messages-user", true);
    properties.set("enable-messages-user", msgUser);
    msgOwner = properties.getBoolean("enable-messages-owner", false);
    properties.set("enable-messages-owner", msgOwner);
    //msgAdmin = true;
    msgAdmin = properties.getBoolean("enable-messages-admin", true);
    properties.set("enable-messages-admin", msgAdmin);
    msgError = properties.getBoolean("enable-messages-error", true);
    properties.set("enable-messages-error", msgError);
    msgHelp = properties.getBoolean("enable-messages-help", true);
    properties.set("enable-messages-help", msgHelp);
   
    explosionProtectionAll = properties.getBoolean("explosion-protection-all", false);
    properties.set("explosion-protection-all", explosionProtectionAll);
    rotateChests = properties.getBoolean("enable-chest-rotation", false);
    properties.set("enable-chest-rotation", rotateChests);
   
    usePermissions = properties.getBoolean("enable-permissions", false);
    properties.set("enable-permissions", usePermissions);
    protectDoors = properties.getBoolean("enable-protection-doors", true);
    properties.set("enable-protection-doors", protectDoors);
    protectTrapDoors = properties.getBoolean("enable-protection-trapdoors", true);
    properties.set("enable-protection-trapdoors", protectTrapDoors);
   
    adminSnoop = properties.getBoolean("allow-admin-snoop", false);
    properties.set("allow-admin-snoop", adminSnoop);
    adminBypass = properties.getBoolean("allow-admin-bypass", true);
    properties.set("allow-admin-bypass", adminBypass);
    adminBreak = properties.getBoolean("allow-admin-break", true);
    properties.set("allow-admin-break", adminBreak);
   
   
    // Start a scheduled task, for closing doors.
    if(protectDoors || protectTrapDoors){
      if(doorCloser.start()){
        log.severe("[" + getDescription().getName() + "] Failed to register door closing task!");
      }
    }
    else doorCloser.stop();
   
   

    directPlacement = properties.getBoolean("enable-quick-protect", true);
    properties.set("enable-quick-protect", directPlacement);
    colorTags = properties.getBoolean("enable-color-tags", true);
    properties.set("enable-color-tags", colorTags);

    // Don't write this option back out if it doesn't exist, and write a warning if it is enabled.
    debugMode = properties.getBoolean("enable-debug", false);
    if(debugMode) log.warning("[" + getDescription().getName() + "] Debug mode is enabled, so Lockette chests are NOT secure.");
   
    //directPlacement = true;
   
   
    // = properties.getBoolean("", true);
    //properties.set("", );
   
    //tempBoolean = properties.getBoolean("use-whitelist", false);
    //tempBoolean = properties.getBoolean("lock-all-chests", true);//rename
    //tempBoolean = properties.getBoolean("test-bool", true);
    //properties.set("test-bool", tempBoolean);
   
   
   
    defaultDoorTimer = properties.getInt("default-door-timer", -1);
    if(defaultDoorTimer == -1){
      defaultDoorTimer = 0;
      properties.set("default-door-timer", defaultDoorTimer);
      propChanged = true;
    }
   
   
   
    // Customizable protected block list.
   
    customBlockList = (List<Object>) properties.getList("custom-lockable-block-list");
    if(customBlockList == null){
      customBlockList = new ArrayList<Object>(3);
      customBlockList.add(Material.ENCHANTMENT_TABLE.getId());
      customBlockList.add(Material.JUKEBOX.getId());
      customBlockList.add(Material.DIAMOND_BLOCK.getId());
      properties.set("custom-lockable-block-list", customBlockList);
      propChanged = true;
    }
    if(!customBlockList.isEmpty()){
      log.info("[" + getDescription().getName() + "] Custom lockable block list: " + customBlockList.toString());
    }
   
   
    // Customizable disabled plugin link list.
   
    disabledPluginList = (List<Object>) properties.getList("linked-plugin-ignore-list");
    if(disabledPluginList == null){
      disabledPluginList = new ArrayList<Object>(1);
      disabledPluginList.add("mcMMO");
      properties.set("linked-plugin-ignore-list", disabledPluginList);
      propChanged = true;
    }
    if(!disabledPluginList.isEmpty()){
      log.info("[" + getDescription().getName() + "] Ignoring linked plugins: " + disabledPluginList.toString());
    }
   
   
    broadcastSnoopTarget = properties.getString("broadcast-snoop-target");
    if(broadcastSnoopTarget == null){
      broadcastSnoopTarget = "[Everyone]";
      properties.set("broadcast-snoop-target", broadcastSnoopTarget);
      propChanged = true;
    }
    broadcastBreakTarget = properties.getString("broadcast-break-target");
    if(broadcastBreakTarget == null){
      broadcastBreakTarget = "[Everyone]";
      properties.set("broadcast-break-target", broadcastBreakTarget);
      propChanged = true;
    }
    broadcastReloadTarget = properties.getString("broadcast-reload-target");
    if(broadcastReloadTarget == null){
      broadcastReloadTarget = "[Operators]";
      properties.set("broadcast-reload-target", broadcastReloadTarget);
      propChanged = true;
    }
   
   
    String stringsFileName = properties.getString("strings-file-name");
    if((stringsFileName == null) || stringsFileName.isEmpty()){
      stringsFileName = "strings-en.yml";
      properties.set("strings-file-name", stringsFileName);
      propChanged = true;
    }
   
    if(propChanged){
      this.saveConfig();
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void onEnable() {
    FileConfiguration configuration = getConfig();
    BukkitScheduler scheduler = getServer().getScheduler();

    // Copy the default configuration if it hasn't been copied already
    saveDefaultConfig();

    // Update old configurations with new key-value pairs
    configuration.options().copyDefaults(true);

    // Get configuration.
    configurationHandler = new Configuration(configuration);
    int entityUpdatePeriod = configurationHandler.getEntityUpdatePeriod();
    int listUpdatePeriod = configurationHandler.getListUpdatePeriod();
View Full Code Here

        playerLoader = InternalAccessor.Instance.newPlayerDataManager();
        inventoryAccess = InternalAccessor.Instance.newInventoryAccess();
        anySilentChest = InternalAccessor.Instance.newAnySilentChest();

        mainPlugin = this;
        FileConfiguration config = getConfig();
        config.set("CheckForUpdates", config.getBoolean("CheckForUpdates", true));
        config.set("NotifySilentChest", config.getBoolean("NotifySilentChest", true));
        config.set("NotifyAnyChest", config.getBoolean("NotifyAnyChest", true));
        config.set("ItemOpenInvItemID", config.getInt("ItemOpenInvItemID", 280));
        config.addDefault("ItemOpenInvItemID", 280);
        config.addDefault("CheckForUpdates", true);
        config.addDefault("NotifySilentChest", true);
        config.addDefault("NotifyAnyChest", true);
        config.options().copyDefaults(true);
        saveConfig();

        pm.registerEvents(new OpenInvPlayerListener(), this);
        pm.registerEvents(new OpenInvEntityListener(), this);
        pm.registerEvents(new OpenInvInventoryListener(), this);
View Full Code Here

    // *** configuration ***

    private void loadConfig() {
        // load configuration
        FileConfiguration config = getConfig();

        // set defaults
        config.options().copyDefaults(true);
        config.addDefault("runtime.ruby-version", "1.8");
        config.addDefault("runtime.jruby-path", getDataFolder() + File.separator + "jruby.jar");
        config.addDefault("settings.plugins-path", getDataFolder().getPath());
        config.addDefault("settings.debug", true);

        // Ruby version
        rubyVersion = config.getString("runtime.ruby-version");
        if (!rubyVersion.equals("1.8") && !rubyVersion.equals("1.9")) {
            log(SEVERE, "Invalid Ruby version \"" + rubyVersion + "\". Possible values are \"1.8\" and \"1.9\".");
            config.set("runtime.ruby-version", rubyVersion = "1.8");
        }

        // JRuby runtime
        jrubyJar = new File(config.getString("runtime.jruby-path"));

        // plugin search path
        pluginsFolder = new File(config.getString("settings.plugins-path"));
        debugInfo = config.getBoolean("settings.debug");
        saveConfig();
    }
View Full Code Here

    /**
     * Migrate the worlds.yml to SerializationConfig.
     */
    private void migrateWorldConfig() { // SUPPRESS CHECKSTYLE: MethodLength
        FileConfiguration wconf = new YamlConfiguration();
        wconf.options().pathSeparator(PATH_SEPARATOR);
        File worldsFile = new File(getDataFolder(), "worlds.yml");
        try {
            wconf.load(worldsFile);
        } catch (IOException e) {
            log(Level.WARNING, "Cannot load worlds.yml");
        } catch (InvalidConfigurationException e) {
            log(Level.WARNING, "Your worlds.yml is invalid!");
        }

        if (!wconf.isConfigurationSection("worlds")) { // empty config
            this.log(Level.FINE, "No worlds to migrate!");
            return;
        }

        Map<String, Object> values = wconf.getConfigurationSection("worlds").getValues(false);

        boolean wasChanged = false;
        Map<String, Object> newValues = new LinkedHashMap<String, Object>(values.size());
        for (Map.Entry<String, Object> entry : values.entrySet()) {
            if (entry.getValue() instanceof WorldProperties) {
                // fine
                newValues.put(entry.getKey(), entry.getValue());
            } else if (entry.getValue() instanceof ConfigurationSection) {
                this.log(Level.FINE, "Migrating: " + entry.getKey());
                // we have to migrate this
                WorldProperties world = new WorldProperties(Collections.EMPTY_MAP);
                ConfigurationSection section = (ConfigurationSection) entry.getValue();

                // migrate animals and monsters
                if (section.isConfigurationSection("animals")) {
                    ConfigurationSection animalSection = section.getConfigurationSection("animals");
                    if (animalSection.contains("spawn")) {
                        if (animalSection.isBoolean("spawn"))
                            world.setAllowAnimalSpawn(animalSection.getBoolean("spawn"));
                        else
                            world.setAllowAnimalSpawn(Boolean.parseBoolean(animalSection.getString("spawn")));
                    }
                    if (animalSection.isList("exceptions")) {
                        world.getAnimalList().clear();
                        world.getAnimalList().addAll(animalSection.getStringList("exceptions"));
                    }
                }
                if (section.isConfigurationSection("monsters")) {
                    ConfigurationSection monsterSection = section.getConfigurationSection("monsters");
                    if (monsterSection.contains("spawn")) {
                        if (monsterSection.isBoolean("spawn"))
                            world.setAllowMonsterSpawn(monsterSection.getBoolean("spawn"));
                        else
                            world.setAllowMonsterSpawn(Boolean.parseBoolean(monsterSection.getString("spawn")));
                    }
                    if (monsterSection.isList("exceptions")) {
                        world.getMonsterList().clear();
                        world.getMonsterList().addAll(monsterSection.getStringList("exceptions"));
                    }
                }

                // migrate entryfee
                if (section.isConfigurationSection("entryfee")) {
                    ConfigurationSection feeSection = section.getConfigurationSection("entryfee");
                    if (feeSection.isInt("currency"))
                        world.setCurrency(feeSection.getInt("currency"));

                    if (feeSection.isDouble("amount"))
                        world.setPrice(feeSection.getDouble("amount"));
                    else if (feeSection.isInt("amount"))
                        world.setPrice(feeSection.getInt("amount"));
                }

                // migrate pvp
                if (section.isBoolean("pvp")) {
                    world.setPVPMode(section.getBoolean("pvp"));
                }

                // migrate alias
                if (section.isConfigurationSection("alias")) {
                    ConfigurationSection aliasSection = section.getConfigurationSection("alias");
                    if (aliasSection.isString("color"))
                        world.setColor(aliasSection.getString("color"));
                    if (aliasSection.isString("name"))
                        world.setAlias(aliasSection.getString("name"));
                }

                // migrate worldblacklist
                if (section.isList("worldblacklist")) {
                    world.getWorldBlacklist().clear();
                    world.getWorldBlacklist().addAll(section.getStringList("worldblacklist"));
                }

                // migrate scale
                if (section.isDouble("scale")) {
                    world.setScaling(section.getDouble("scale"));
                }

                // migrate gamemode
                if (section.isString("gamemode")) {
                    final GameMode gameMode = GameMode.valueOf(section.getString("gamemode").toUpperCase());
                    if (gameMode != null) {
                        world.setGameMode(gameMode);
                    }
                }

                // migrate hunger
                if (section.isBoolean("hunger")) {
                    world.setHunger(section.getBoolean("hunger"));
                }

                // migrate hidden
                if (section.isBoolean("hidden")) {
                    world.setHidden(section.getBoolean("hidden"));
                }

                // migrate autoheal
                if (section.isBoolean("autoheal")) {
                    world.setAutoHeal(section.getBoolean("autoheal"));
                }

                // migrate portalform
                if (section.isString("portalform")) {
                    try {
                        world.setProperty("portalform", section.getString("portalform"), true);
                    } catch (NoSuchPropertyException e) {
                        throw new RuntimeException("Who forgot to update the migrator?", e);
                    }
                }

                // migrate environment
                if (section.isString("environment")) {
                    try {
                        world.setProperty("environment", section.getString("environment"), true);
                    } catch (NoSuchPropertyException e) {
                        throw new RuntimeException("Who forgot to update the migrator?", e);
                    }
                }

                // migrate generator
                if (section.isString("generator")) {
                    world.setGenerator(section.getString("generator"));
                }

                // migrate seed
                if (section.isLong("seed")) {
                    world.setSeed(section.getLong("seed"));
                }

                // migrate weather
                if (section.isBoolean("allowweather")) {
                    world.setEnableWeather(section.getBoolean("allowweather"));
                }

                // migrate adjustspawn
                if (section.isBoolean("adjustspawn")) {
                    world.setAdjustSpawn(section.getBoolean("adjustspawn"));
                }

                // migrate autoload
                if (section.isBoolean("autoload")) {
                    world.setAutoLoad(section.getBoolean("autoload"));
                }

                // migrate bedrespawn
                if (section.isBoolean("bedrespawn")) {
                    world.setBedRespawn(section.getBoolean("bedrespawn"));
                }

                // migrate spawn
                if (section.isConfigurationSection("spawn")) {
                    ConfigurationSection spawnSect = section.getConfigurationSection("spawn");
                    Location spawnLoc = new NullLocation();
                    if (spawnSect.isDouble("yaw"))
                        spawnLoc.setYaw((float) spawnSect.getDouble("yaw"));
                    if (spawnSect.isDouble("pitch"))
                        spawnLoc.setPitch((float) spawnSect.getDouble("pitch"));
                    if (spawnSect.isDouble("x"))
                        spawnLoc.setX(spawnSect.getDouble("x"));
                    if (spawnSect.isDouble("y"))
                        spawnLoc.setY(spawnSect.getDouble("y"));
                    if (spawnSect.isDouble("z"))
                        spawnLoc.setZ(spawnSect.getDouble("z"));

                    world.setSpawnLocation(spawnLoc);
                }

                // migrate difficulty
                if (section.isString("difficulty")) {
                    final Difficulty difficulty = Difficulty.valueOf(section.getString("difficulty").toUpperCase());
                    if (difficulty != null) {
                        world.setDifficulty(difficulty);
                    }
                }

                // migrate keepspawninmemory
                if (section.isBoolean("keepspawninmemory")) {
                    world.setKeepSpawnInMemory(section.getBoolean("keepspawninmemory"));
                }

                newValues.put(entry.getKey(), world);
                wasChanged = true;
            } else {
                // huh?
                this.log(Level.WARNING, "Removing unknown entry in the config: " + entry);
                // just don't add to newValues
                wasChanged = true;
            }
        }

        if (wasChanged) {
            // clear config
            wconf.set("worlds", null);

            // and rebuild it
            ConfigurationSection rootSection = wconf.createSection("worlds");
            for (Map.Entry<String, Object> entry : newValues.entrySet()) {
                rootSection.set(entry.getKey(), entry.getValue());
            }

            try {
                wconf.save(new File(getDataFolder(), "worlds.yml"));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
View Full Code Here

            public boolean accept(File file, String s) {
                return s.equalsIgnoreCase("bukkit.yml");
            }
        });
        if (files != null && files.length == 1) {
            FileConfiguration bukkitConfig = YamlConfiguration.loadConfiguration(files[0]);
            if (bukkitConfig.isConfigurationSection("worlds")) {
                Set<String> keys = bukkitConfig.getConfigurationSection("worlds").getKeys(false);
                for (String key : keys) {
                    defaultGens.put(key, bukkitConfig.getString("worlds." + key + ".generator", ""));
                }
            }
        } else {
            this.plugin.log(Level.WARNING, "Could not read 'bukkit.yml'. Any Default worldgenerators will not be loaded!");
        }
View Full Code Here

  }

  // this is a catch-all to make general upgrades to old configuration files
  private void updateConfigurationFile()
  {
    FileConfiguration config = getConfig();

    // v2.2, 2013/05/04, remove remains of server mode
    if (config.get("server-mode") != null)
      config.set("server-mode", null);

    // v2.3, 2013/05/17, update lobby info
    if (config.getString("lobby-world") != null)
    {
      // set new parameter paths
      config.set("lobby.world", config.getString("lobby-world"));
      config.set("lobby.mode", "manual");

      // remove old configuration flag
      config.set("lobby-world", null);
    }

    // v2.3, 2013/06/03, allow for lobby mode enum (not "auto" boolean)
    if (config.getString("lobby.auto") != null)
    {
      boolean autoMode = config.getBoolean("lobby.auto", false);
      config.set("lobby.mode", autoMode ? "auto" : "manual");
      config.set("lobby.auto", null);
    }
  }
View Full Code Here

     *
     * @param file  File to load
     * @param clazz Class to modify
     */
    public static void pairFileAndClass(File file, Class clazz) {
        FileConfiguration config = YamlConfiguration.loadConfiguration(file);

        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));

            if (!endsWithSpace(file)) {
                writer.newLine();
            }

            for (Field field : clazz.getDeclaredFields()) {
                if (!Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers()) || !Modifier.isPublic(field.getModifiers())) {
                    continue;
                }

                String path = field.getName();

                try {
                    if (config.isSet(path)) {
                        field.set(null, ValueParser.parseToJava(config.get(path)));
                    } else {
                        if (field.isAnnotationPresent(PrecededBySpace.class)) {
                            writer.newLine();
                        }

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.