/** Load the configuration. */
  @SuppressWarnings("unchecked")
  public void load() {
    // Create the default configuration file
    plugin.createDefaultConfiguration(new File(plugin.getDataFolder(), "config.yml"), "config.yml");

    config =
        new YAMLProcessor(
            new File(plugin.getDataFolder(), "config.yml"), true, YAMLFormat.EXTENDED);
    try {
      config.load();
    } catch (IOException e) {
      log.severe("Error reading configuration for global config: ");
      e.printStackTrace();
    }

    config.removeProperty("suppress-tick-sync-warnings");
    useRegionsScheduler = config.getBoolean("regions.use-scheduler", true);
    migrateRegionsToUuid = config.getBoolean("regions.uuid-migration.perform-on-next-start", true);
    keepUnresolvedNames =
        config.getBoolean("regions.uuid-migration.keep-names-that-lack-uuids", true);
    useRegionsCreatureSpawnEvent = config.getBoolean("regions.use-creature-spawn-event", true);
    useGodPermission =
        config.getBoolean(
            "auto-invincible", config.getBoolean("auto-invincible-permission", false));
    useGodGroup = config.getBoolean("auto-invincible-group", false);
    useAmphibiousGroup = config.getBoolean("auto-no-drowning-group", false);
    config.removeProperty("auto-invincible-permission");
    usePlayerMove = config.getBoolean("use-player-move-event", true);
    usePlayerTeleports = config.getBoolean("use-player-teleports", true);

    deopOnJoin = config.getBoolean("security.deop-everyone-on-join", false);
    blockInGameOp = config.getBoolean("security.block-in-game-op-command", false);

    hostKeys = new HashMap<String, String>();
    Object hostKeysRaw = config.getProperty("host-keys");
    if (hostKeysRaw == null || !(hostKeysRaw instanceof Map)) {
      config.setProperty("host-keys", new HashMap<String, String>());
    } else {
      for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) hostKeysRaw).entrySet()) {
        String key = String.valueOf(entry.getKey());
        String value = String.valueOf(entry.getValue());
        hostKeys.put(key.toLowerCase(), value);
      }
    }

    // ====================================================================
    // Region store drivers
    // ====================================================================

    boolean useSqlDatabase = config.getBoolean("regions.sql.use", false);
    String sqlDsn = config.getString("regions.sql.dsn", "jdbc:mysql://localhost/worldguard");
    String sqlUsername = config.getString("regions.sql.username", "worldguard");
    String sqlPassword = config.getString("regions.sql.password", "worldguard");
    String sqlTablePrefix = config.getString("regions.sql.table-prefix", "");

    DataSourceConfig dataSourceConfig =
        new DataSourceConfig(sqlDsn, sqlUsername, sqlPassword, sqlTablePrefix);
    SQLDriver sqlDriver = new SQLDriver(dataSourceConfig);
    DirectoryYamlDriver yamlDriver = new DirectoryYamlDriver(getWorldsDataFolder(), "regions.yml");

    this.regionStoreDriverMap =
        ImmutableMap.<DriverType, RegionDriver>builder()
            .put(DriverType.MYSQL, sqlDriver)
            .put(DriverType.YAML, yamlDriver)
            .build();
    this.selectedRegionStoreDriver = useSqlDatabase ? sqlDriver : yamlDriver;

    // Load configurations for each world
    for (World world : plugin.getServer().getWorlds()) {
      get(world);
    }

    config.setHeader(CONFIG_HEADER);
  }
 public void disableUuidMigration() {
   config.setProperty("regions.uuid-migration.perform-on-next-start", false);
   if (!config.save()) {
     log.severe("Error saving configuration!");
   }
 }
  private boolean loadConfig(File file) {
    boolean isUpdated = false;
    if (!file.exists()) {
      try {
        file.createNewFile();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    config = new YAMLProcessor(file, false, YAMLFormat.EXTENDED);
    try {
      config.load();
    } catch (IOException e) {
      logger.severe("Error loading WEPIF Config: " + e);
      e.printStackTrace();
    }
    List<String> keys = config.getKeys(null);
    config.setHeader(CONFIG_HEADER);

    if (!keys.contains("ignore-nijiperms-bridges")) {
      config.setProperty("ignore-nijiperms-bridges", true);
      isUpdated = true;
    }

    if (!keys.contains("resolvers")) {
      // List<String> resolverKeys = config.getKeys("resolvers");
      List<String> resolvers = new ArrayList<String>();
      for (Class<?> clazz : availableResolvers) {
        resolvers.add(clazz.getSimpleName());
      }
      enabledResolvers.addAll(Arrays.asList(availableResolvers));
      config.setProperty("resolvers.enabled", resolvers);
      isUpdated = true;
    } else {
      List<String> disabledResolvers =
          config.getStringList("resolvers.disabled", new ArrayList<String>());
      List<String> stagedEnabled = config.getStringList("resolvers.enabled", null);
      for (Iterator<String> i = stagedEnabled.iterator(); i.hasNext(); ) {
        String nextName = i.next();
        Class<?> next = null;
        try {
          next = Class.forName(getClass().getPackage().getName() + "." + nextName);
        } catch (ClassNotFoundException e) {
        }

        if (next == null || !PermissionsResolver.class.isAssignableFrom(next)) {
          logger.warning(
              "WEPIF: Invalid or unknown class found in enabled resolvers: "
                  + nextName
                  + ". Moving to disabled resolvers list.");
          i.remove();
          disabledResolvers.add(nextName);
          isUpdated = true;
          continue;
        }
        enabledResolvers.add(next.asSubclass(PermissionsResolver.class));
      }

      for (Class<?> clazz : availableResolvers) {
        if (!stagedEnabled.contains(clazz.getSimpleName())
            && !disabledResolvers.contains(clazz.getSimpleName())) {
          disabledResolvers.add(clazz.getSimpleName());
          logger.info(
              "New permissions resolver: "
                  + clazz.getSimpleName()
                  + " detected. "
                  + "Added to disabled resolvers list.");
          isUpdated = true;
        }
      }
      config.setProperty("resolvers.disabled", disabledResolvers);
      config.setProperty("resolvers.enabled", stagedEnabled);
    }

    if (keys.contains("dinner-perms") || keys.contains("dinnerperms")) {
      config.removeProperty("dinner-perms");
      config.removeProperty("dinnerperms");
      isUpdated = true;
    }
    if (!keys.contains("permissions")) {
      ConfigurationPermissionsResolver.generateDefaultPerms(config.addNode("permissions"));
      isUpdated = true;
    }
    if (isUpdated) {
      logger.info("WEPIF: Updated config file");
      config.save();
    }
    return isUpdated;
  }