Exemple #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;
  }
Exemple #2
0
 public void reloadConfig() {
   fileConfiguration = YamlConfiguration.loadConfiguration(configFile);
   InputStream defConfigStream = plugin.getResource(fileName);
   if (defConfigStream != null) {
     YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
     fileConfiguration.setDefaults(defConfig);
   }
 }
  public void setupConfig() throws IOException {
    configFile = new File(plugin.getDataFolder(), fileName);

    if (!configFile.exists()) {
      configFile.createNewFile();
      copy(plugin.getResource(fileName), configFile);
    }
  }
Exemple #4
0
  public void reloadConfig() {
    fileConfiguration = YamlConfiguration.loadConfiguration(configFile);

    // Look for defaults in the jar
    InputStream defConfigStream = plugin.getResource(fileName);
    if (defConfigStream != null) {
      @SuppressWarnings("deprecation")
      YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
      fileConfiguration.setDefaults(defConfig);
    }
  }
  /** {@inheritDoc} */
  @Override
  public void loadLocale(Locale l) throws NoSuchLocalizationException {
    messages.remove(l);

    InputStream resstream = null;
    InputStream filestream = null;

    try {
      filestream = new FileInputStream(new File(plugin.getDataFolder(), l.getLanguage() + ".yml"));
    } catch (FileNotFoundException e) {
    }

    try {
      resstream =
          plugin.getResource(
              new StringBuilder(LOCALIZATION_FOLDER_NAME)
                  .append("/")
                  .append(l.getLanguage())
                  .append(".yml")
                  .toString());
    } catch (Exception e) {
    }

    if ((resstream == null) && (filestream == null)) throw new NoSuchLocalizationException(l);

    messages.put(l, new HashMap<Message, List<String>>(Message.values().length));

    FileConfiguration resconfig =
        (resstream == null) ? null : YamlConfiguration.loadConfiguration(resstream);
    FileConfiguration fileconfig =
        (filestream == null) ? null : YamlConfiguration.loadConfiguration(filestream);
    for (Message m : Message.values()) {
      List<String> values = m.getDefault();

      if (resconfig != null) {
        if (resconfig.isList(m.toString())) {
          values = resconfig.getStringList(m.toString());
        } else {
          values.add(resconfig.getString(m.toString(), values.get(0)));
        }
      }
      if (fileconfig != null) {
        if (fileconfig.isList(m.toString())) {
          values = fileconfig.getStringList(m.toString());
        } else {
          values.add(fileconfig.getString(m.toString(), values.get(0)));
        }
      }

      messages.get(l).put(m, values);
    }
  }
  /** Reloads the configuration from disk. */
  public void reload() {
    if (!checkMemberVariables())
      throw new IllegalStateException("Neither plugin nor the file to be used must be null!");

    config = YamlConfiguration.loadConfiguration(file);

    final InputStream defaultStream = plugin.getResource(file.getName());
    if (defaultStream != null) {
      final YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defaultStream);

      config.setDefaults(defConfig);
    }
  }
  // Load the conf file and search for configs in the jar memory
  public void ReloadConfig() {
    if (file == null) {
      file = new File(plugin.getDataFolder(), fname);
    }
    conf = YamlConfiguration.loadConfiguration(file);

    // Look for defaults in the jar
    InputStream isDefaults = plugin.getResource(fname);
    if (isDefaults != null) {
      YamlConfiguration confDefault = YamlConfiguration.loadConfiguration(isDefaults);
      conf.setDefaults(confDefault);
    }
  }
Exemple #8
0
  public void reloadConfig() {
    if (configFile == null) {
      File dataFolder = plugin.getDataFolder();
      if (dataFolder == null) throw new IllegalStateException();
      configFile = new File(dataFolder, fileName);
    }
    fileConfiguration = YamlConfiguration.loadConfiguration(configFile);

    // Look for defaults in the jar
    InputStream defConfigStream = plugin.getResource(fileName);
    if (defConfigStream != null) {
      YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
      fileConfiguration.setDefaults(defConfig);
    }
  }
  public SimpleYamlConfiguration(
      final JavaPlugin plugin,
      final String fileName,
      final LinkedHashMap<String, Object> configDefaults,
      final String name) {
    /*
     * accepts null as configDefaults -> check for resource and copies it if
     * found, makes an empty config if nothing is found
     */
    final String folderPath = plugin.getDataFolder().getAbsolutePath() + File.separator;
    file = new File(folderPath + fileName);

    if (file.exists() == false) {
      if (configDefaults == null) {
        if (plugin.getResource(fileName) != null) {
          plugin.saveResource(fileName, false);
          plugin.getLogger().info("New " + name + " file copied from jar");
          try {
            this.load(file);
          } catch (final Exception e) {
            e.printStackTrace();
          }
        }
      } else {
        for (final String key : configDefaults.keySet()) {
          this.set(key, configDefaults.get(key));
        }

        try {
          this.save(file);
          plugin.getLogger().info("New " + name + " file created");
        } catch (final IOException e) {
          e.printStackTrace();
        }
      }
    } else {
      try {
        this.load(file);
        plugin.getLogger().info(name + " file loaded");
      } catch (final Exception e) {
        e.printStackTrace();
      }
    }
  }