Saving Resources - rodrigoo-r/Harmony GitHub Wiki

Explanation

You may have configuration files packed at your JAR. To save any resouece packed in your JAR, you can use the following methods inside your plugin's main class:

  • saveFrom(String resourcePath)
  • saveFrom(String resourcePath, boolean replace) (If you set this to true, the file will be replaced even if it already exists)
  • safeSaveFrom(String resourcePath, Path destination)
  • safeSaveFrom(String resourcePath, Path destination, boolean replace) (If you set this to true, the file will be replaced even if it already exists)

NOTE: Harmony always create the default data folder for your plugin if it doesn't exists yet.


Configuration files

If you have config.yml inside your resources folder, you can easily load it without even using saveFrom or safeSaveFrom. To do this, you could use the getConfiguration method.

If any config.yml file exists into the plugin's data folder, it will be created autatically from your resources folder to the data folder. If it already exists, it will be loaded from the existing file.

Example usage:

YAMLConfiguration config = getConfiguration();

Other methods

If you just want to get a resource content without creating it locally to the data folder, you can use resolveFrom(String resourcePath) to get an InputStream from your resources folder.

Example:

Structure:

example project structure

Code:

InputStream stream = resolveFrom("settings.yml");