Update config constructors to pass removeOldKeys boolean

This commit is contained in:
nossr50 2019-02-21 16:44:28 -08:00
parent b0b0167ee2
commit e6aee141fb
13 changed files with 35 additions and 27 deletions

View File

@ -126,7 +126,7 @@ public class AdvancedConfig extends ConfigValidated {
public AdvancedConfig() {
//super(mcMMO.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "advanced.yml", true, true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "advanced.yml", true, true, true);
}
@Override

View File

@ -48,13 +48,13 @@ public abstract class Config implements VersionedConfig, Unload {
/* CONFIG MANAGER */
//private ConfigurationLoader<CommentedConfigurationNode> configManager;
public Config(String pathToParentFolder, String relativePath, boolean mergeNewKeys, boolean copyDefaults) {
public Config(String pathToParentFolder, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) {
//TODO: Check if this works...
this(new File(pathToParentFolder), relativePath, mergeNewKeys, copyDefaults);
this(new File(pathToParentFolder), relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
System.out.println("mcMMO Debug: Don't forget to check if loading config file by string instead of File works...");
}
public Config(File pathToParentFolder, String relativePath, boolean mergeNewKeys, boolean copyDefaults) {
public Config(File pathToParentFolder, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) {
/*
* These must be at the top
*/
@ -284,6 +284,7 @@ public abstract class Config implements VersionedConfig, Unload {
/**
* Finds any keys in the users config that are not present in the default config and removes them
*/
//TODO: Finish this
private void removeOldKeys()
{
if(!removeOldKeys)

View File

@ -17,9 +17,10 @@ public abstract class ConfigCollection<T> extends Config implements Registers, G
* @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files
* @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load
* @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path
* @param removeOldKeys if true, the users config file will have keys not found in the internal default resource file of the same name and path removed
*/
public ConfigCollection(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults) {
super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults);
public ConfigCollection(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) {
super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
//init
initCollection();
@ -33,9 +34,10 @@ public abstract class ConfigCollection<T> extends Config implements Registers, G
* @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files
* @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load
* @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path
* @param removeOldKeys if true, the users config file will have keys not found in the internal default resource file of the same name and path removed
*/
public ConfigCollection(File parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults) {
super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults);
public ConfigCollection(File parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) {
super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
//init
initCollection();

View File

@ -16,9 +16,9 @@ public abstract class ConfigValidated extends Config implements DefaultKeys {
* @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load
* @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path
*/
public ConfigValidated(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults)
public ConfigValidated(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys)
{
super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults);
super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
validateEntries();
}
@ -28,9 +28,9 @@ public abstract class ConfigValidated extends Config implements DefaultKeys {
* @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load
* @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path
*/
public ConfigValidated(File parentFolderFile, String relativePath, boolean mergeNewKeys, boolean copyDefaults)
public ConfigValidated(File parentFolderFile, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys)
{
super(parentFolderFile, relativePath, mergeNewKeys, copyDefaults);
super(parentFolderFile, relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
validateEntries();
}

View File

@ -11,7 +11,7 @@ public class CoreSkillsConfig extends Config {
public CoreSkillsConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(),"coreskills.yml", true, true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(),"coreskills.yml", true, true, true);
}
/**

View File

@ -204,7 +204,7 @@ public class MainConfig extends ConfigValidated {
public MainConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "config.yml", true, true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "config.yml", true, true, true);
}
/**

View File

@ -14,7 +14,7 @@ public class RankConfig extends ConfigValidated {
public RankConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(),"skillranks.yml", true, true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(),"skillranks.yml", true, true, true);
//this.instance = this;
}

View File

@ -16,7 +16,7 @@ public class SoundConfig extends ConfigValidated {
public SoundConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "sounds.yml", true, true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "sounds.yml", true, true, true);
}
/**

View File

@ -45,7 +45,7 @@ public class MultiConfigContainer<T> implements Unload {
//Load Configs
//Vanilla Config
initConfigAndAddCollection(getVanillaConfigName(configPrefix), true);
initConfigAndAddCollection(mcMMO.p.getDataFolder().getAbsolutePath(),getVanillaConfigName(configPrefix), false, true, false);
//Custom Configs
loadCustomCollections(configPrefix);
@ -90,15 +90,20 @@ public class MultiConfigContainer<T> implements Unload {
/**
* Initializes a config and attempts to load add its collection
* @param configFileName the filename of the config to load
* @param parentFolderPath Path to the "parent" folder on disk
* @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files
* @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load
* @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path
* @param removeOldKeys if true, the users config file will have keys not found in the internal default resource file of the same name and path removed
*/
private void initConfigAndAddCollection(String configFileName, Boolean copyDefaults)
private void initConfigAndAddCollection(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys)
{
mcMMO.p.getLogger().info("Reading from collection config - "+configFileName);
mcMMO.p.getLogger().info("Reading from collection config - "+relativePath);
ConfigCollection configCollection = null;
try {
configCollection = (ConfigCollection) getConfigClass(collectionClassType).getConstructor(String.class, Boolean.class).newInstance(configFileName, copyDefaults);
//String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys
configCollection = (ConfigCollection) getConfigClass(collectionClassType).getConstructor(String.class, String.class, Boolean.class, Boolean.class, Boolean.class).newInstance(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
@ -145,7 +150,7 @@ public class MultiConfigContainer<T> implements Unload {
continue;
//Load and add the collections
initConfigAndAddCollection(fileName, false);
initConfigAndAddCollection(dataFolder.getAbsolutePath(), fileName, false, false, false);
}
}

View File

@ -79,7 +79,7 @@ public class ExperienceConfig extends ConfigValidated {
//TODO: Should merge be false? Seems okay to leave it as true..
public ExperienceConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "experience.yml", true, true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "experience.yml", true, true, false);
}
/**

View File

@ -16,7 +16,7 @@ public class ItemWeightConfig extends Config {
public ItemWeightConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "itemweights.yml");
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "itemweights.yml", true, true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "itemweights.yml", true, true, false);
}
/**

View File

@ -61,7 +61,7 @@ public class PotionConfig extends ConfigCollection {
private Map<String, AlchemyPotion> potionMap = new HashMap<String, AlchemyPotion>();
public PotionConfig() {
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true, true);
register();
}

View File

@ -34,7 +34,7 @@ public class TreasureConfig extends ConfigCollection {
public TreasureConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"treasures.yml");
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "treasures.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "treasures.yml", false, true, false);
}
/**
@ -60,7 +60,7 @@ public class TreasureConfig extends ConfigCollection {
}
@Override
protected boolean validateKeys() {
public List<String> validateKeys() {
// Validate all the settings!
List<String> reason = new ArrayList<String>();
for (String tier : config.getConfigurationSection("Enchantment_Drop_Rates").getKeys(false)) {