From e6aee141fbe55fe4e8446ed84dfe8c1a0815042f Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 21 Feb 2019 16:44:28 -0800 Subject: [PATCH] Update config constructors to pass removeOldKeys boolean --- .../gmail/nossr50/config/AdvancedConfig.java | 2 +- .../java/com/gmail/nossr50/config/Config.java | 7 ++++--- .../gmail/nossr50/config/ConfigCollection.java | 10 ++++++---- .../gmail/nossr50/config/ConfigValidated.java | 8 ++++---- .../gmail/nossr50/config/CoreSkillsConfig.java | 2 +- .../com/gmail/nossr50/config/MainConfig.java | 2 +- .../com/gmail/nossr50/config/RankConfig.java | 2 +- .../com/gmail/nossr50/config/SoundConfig.java | 2 +- .../collectionconfigs/MultiConfigContainer.java | 17 +++++++++++------ .../config/experience/ExperienceConfig.java | 2 +- .../nossr50/config/party/ItemWeightConfig.java | 2 +- .../config/skills/alchemy/PotionConfig.java | 2 +- .../nossr50/config/treasure/TreasureConfig.java | 4 ++-- 13 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index 6b0d436fc..8c0dce38c 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -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 diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index f5891fdf8..7cb44a6a6 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -48,13 +48,13 @@ public abstract class Config implements VersionedConfig, Unload { /* CONFIG MANAGER */ //private ConfigurationLoader 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) diff --git a/src/main/java/com/gmail/nossr50/config/ConfigCollection.java b/src/main/java/com/gmail/nossr50/config/ConfigCollection.java index 16a4131e1..aab32f8a5 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigCollection.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigCollection.java @@ -17,9 +17,10 @@ public abstract class ConfigCollection 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 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(); diff --git a/src/main/java/com/gmail/nossr50/config/ConfigValidated.java b/src/main/java/com/gmail/nossr50/config/ConfigValidated.java index a5cbec0c9..61e225ee7 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigValidated.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigValidated.java @@ -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(); } diff --git a/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java b/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java index 6a94fa7c4..a6b56d1cd 100644 --- a/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java +++ b/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java @@ -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); } /** diff --git a/src/main/java/com/gmail/nossr50/config/MainConfig.java b/src/main/java/com/gmail/nossr50/config/MainConfig.java index c1814f95c..fac41fe88 100644 --- a/src/main/java/com/gmail/nossr50/config/MainConfig.java +++ b/src/main/java/com/gmail/nossr50/config/MainConfig.java @@ -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); } /** diff --git a/src/main/java/com/gmail/nossr50/config/RankConfig.java b/src/main/java/com/gmail/nossr50/config/RankConfig.java index 501cc7057..feb266851 100644 --- a/src/main/java/com/gmail/nossr50/config/RankConfig.java +++ b/src/main/java/com/gmail/nossr50/config/RankConfig.java @@ -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; } diff --git a/src/main/java/com/gmail/nossr50/config/SoundConfig.java b/src/main/java/com/gmail/nossr50/config/SoundConfig.java index e8960337e..3e1cd836c 100644 --- a/src/main/java/com/gmail/nossr50/config/SoundConfig.java +++ b/src/main/java/com/gmail/nossr50/config/SoundConfig.java @@ -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); } /** diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java index ca8bc44f8..b505bf3aa 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java @@ -45,7 +45,7 @@ public class MultiConfigContainer 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 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 implements Unload { continue; //Load and add the collections - initConfigAndAddCollection(fileName, false); + initConfigAndAddCollection(dataFolder.getAbsolutePath(), fileName, false, false, false); } } diff --git a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java index 8f68091e6..3ea5de637 100644 --- a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java +++ b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java @@ -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); } /** diff --git a/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java b/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java index ac19a8849..f3546fe00 100644 --- a/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java +++ b/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java @@ -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); } /** diff --git a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java index 8068fe9d9..5588647e5 100644 --- a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java +++ b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java @@ -61,7 +61,7 @@ public class PotionConfig extends ConfigCollection { private Map potionMap = new HashMap(); public PotionConfig() { - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true, true); register(); } diff --git a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java index b07c8cb8b..4ee736b19 100755 --- a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java @@ -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 validateKeys() { // Validate all the settings! List reason = new ArrayList(); for (String tier : config.getConfigurationSection("Enchantment_Drop_Rates").getKeys(false)) {