1
0
mirror of https://github.com/mcMMO-Dev/mcMMO.git synced 2026-02-21 11:13:00 +01:00

Treasure Config Split pt 2, Configs now register to be backed up with the config manager

This commit is contained in:
nossr50
2019-02-21 19:06:59 -08:00
parent 41bfba0c68
commit 349a714134
9 changed files with 318 additions and 99 deletions

View File

@@ -20,6 +20,7 @@ import java.util.List;
public abstract class Config implements VersionedConfig, Unload {
/* SETTINGS */
//private static final String FILE_EXTENSION = ".conf"; //HOCON
private boolean mergeNewKeys; //Whether or not to merge keys found in the default config
private boolean removeOldKeys; //Whether or not to remove unused keys form the config
private boolean copyDefaults; //Whether or not to copy the default config when first creating the file
@@ -65,8 +66,6 @@ public abstract class Config implements VersionedConfig, Unload {
DIRECTORY_DATA_FOLDER = pathToParentFolder; //Data Folder for our plugin
FILE_RELATIVE_PATH = relativePath; //Relative path to config from a parent folder
registerUnload();
//Attempt IO Operations
try {
//Makes sure we have valid Files corresponding to this config
@@ -83,6 +82,10 @@ public abstract class Config implements VersionedConfig, Unload {
} catch (IOException e) {
e.printStackTrace();
}
//Cleanup and backup registers
registerUnload();
registerFileBackup();
}
/**
@@ -94,6 +97,15 @@ public abstract class Config implements VersionedConfig, Unload {
mcMMO.getConfigManager().registerUnloadable(this);
}
/**
* Registers with the config managers file list
* Used for backing up configs with our zip library
*/
private void registerFileBackup()
{
mcMMO.getConfigManager().registerUserFile(getUserConfigFile());
}
/**
* Initializes the default copy File and the user config File
* @throws IOException
@@ -170,6 +182,14 @@ public abstract class Config implements VersionedConfig, Unload {
}
}
/**
* Gets the File representation of the this users config
* @return the users config File
*/
public File getUserConfigFile() {
return new File(DIRECTORY_DATA_FOLDER, FILE_RELATIVE_PATH);
}
/**
* Used to make a new config file at a specified relative output path inside the data directory by copying the matching file found in that same relative path within the JAR
* @param relativeOutputPath the path to the output file