Skip to content

Commit

Permalink
Added a constructor that provides data folder location
Browse files Browse the repository at this point in the history
Signed-off-by: DevDrizzy <[email protected]>
  • Loading branch information
DevDrizzy committed Feb 13, 2024
1 parent f3596b3 commit 28754fb
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/java/xyz/refinedev/api/storage/YamlStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,45 @@ public YamlStorage(JavaPlugin plugin, String name, boolean saveResource) {
this.readConfig();
}

/**
* Initiation method for a config file
*
* @param plugin {@link JavaPlugin plugin instance}
* @param name {@link String config file name}
* @param dataFolder {@link String data folder}
*/
public YamlStorage(JavaPlugin plugin, String name, String dataFolder) {
File file = new File(dataFolder, name + ".yml");

this.name = name;
this.config = new YamlFile(file);

if (!file.exists()) {
try {
this.config.createNewFile(false);
} catch (IOException ex) {
LOGGER.error("[Storage] Could not create/save " + name + ".yml!");
LOGGER.error("[Storage] Error: " + ex.getMessage());
}
}

try {
this.config.load();
} catch (IOException ex) {
LOGGER.error("[Storage] Could not load " + name + ".yml, please correct your syntax errors!");
LOGGER.error("[Storage] Error: " + ex.getMessage());
}

// Call this method for ParentYamlStorage to register child fields
// before loading the config...
this.registerChildStorages();

this.fields = this.getConfigFields();

this.config.options().header(String.join("\n", this.getHeader()));
this.readConfig();
}

/**
* Read config values from the config, if some are not present
* we save the default value of the {@link ConfigValue} to the config
Expand Down

0 comments on commit 28754fb

Please sign in to comment.