Ejemplo n.º 1
0
  @SuppressWarnings("ConstantConditions")
  public static ConfigImpl loadConfig(
      final ConfigFile config,
      final JavaPlugin plugin,
      final ClassLoader classLoader,
      final File dataFolder) {
    // Plugin or classloader must be specified
    Validate.isTrue(plugin != null || classLoader != null, "Plugin or classloader can't be null");

    final ConfigImpl cached;
    if ((cached = ConfigImpl.cache.get(config)) != null) {
      cached.reload(); // Make sure the config is up-to-date
      return cached;
    }

    final File file =
        new File(
            dataFolder != null ? dataFolder : (plugin != null ? plugin.getDataFolder() : null),
            config.getFileName());

    if (!file.exists()) // Copy the config from jar file
    {
      final InputStream inJarFile =
          classLoader != null
              ? classLoader.getResourceAsStream(config.getFileName())
              : plugin.getResource(config.getFileName());

      IOUtils.saveToFile(inJarFile, file);
    }

    final ConfigImpl configuration =
        new ConfigImpl(YamlConfiguration.loadConfiguration(file), file, config);
    ConfigImpl.cache.put(config, configuration);
    return configuration;
  }
Ejemplo n.º 2
0
 /**
  * Construct new ConfigImpl instance
  *
  * @param configuration bukkit {@link YamlConfiguration} instance
  * @param file source file of the config
  * @param configFile the {@link ConfigFile} instance
  */
 public ConfigImpl(
     final YamlConfiguration configuration, final File file, final ConfigFile configFile) {
   this.configuration = configuration;
   this.file = file;
   this.fileName = configFile.getFileName();
 }