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() { public AdvancedConfig() {
//super(mcMMO.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true); //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 @Override

View File

@ -48,13 +48,13 @@ public abstract class Config implements VersionedConfig, Unload {
/* CONFIG MANAGER */ /* CONFIG MANAGER */
//private ConfigurationLoader<CommentedConfigurationNode> configManager; //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... //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..."); 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 * 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 * Finds any keys in the users config that are not present in the default config and removes them
*/ */
//TODO: Finish this
private void removeOldKeys() private void removeOldKeys()
{ {
if(!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 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 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 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) { public ConfigCollection(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) {
super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults); super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
//init //init
initCollection(); 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 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 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 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) { public ConfigCollection(File parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) {
super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults); super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys);
//init //init
initCollection(); 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 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 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(); 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 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 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(); validateEntries();
} }

View File

@ -11,7 +11,7 @@ public class CoreSkillsConfig extends Config {
public CoreSkillsConfig() { public CoreSkillsConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml", true); //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() { public MainConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml", true); //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() { public RankConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true); //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; //this.instance = this;
} }

View File

@ -16,7 +16,7 @@ public class SoundConfig extends ConfigValidated {
public SoundConfig() { public SoundConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml", true); //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 //Load Configs
//Vanilla Config //Vanilla Config
initConfigAndAddCollection(getVanillaConfigName(configPrefix), true); initConfigAndAddCollection(mcMMO.p.getDataFolder().getAbsolutePath(),getVanillaConfigName(configPrefix), false, true, false);
//Custom Configs //Custom Configs
loadCustomCollections(configPrefix); loadCustomCollections(configPrefix);
@ -90,15 +90,20 @@ public class MultiConfigContainer<T> implements Unload {
/** /**
* Initializes a config and attempts to load add its collection * 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; ConfigCollection configCollection = null;
try { 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) { } catch (InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -145,7 +150,7 @@ public class MultiConfigContainer<T> implements Unload {
continue; continue;
//Load and add the collections //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.. //TODO: Should merge be false? Seems okay to leave it as true..
public ExperienceConfig() { public ExperienceConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true); //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() { public ItemWeightConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "itemweights.yml"); //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>(); private Map<String, AlchemyPotion> potionMap = new HashMap<String, AlchemyPotion>();
public PotionConfig() { public PotionConfig() {
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true); super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true, true);
register(); register();
} }

View File

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