From 55b1da03415088662d6bc8d7d4e06174ad9ef12b Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 8 Mar 2019 19:40:01 -0800 Subject: [PATCH] no more MultiConfigContainers, updating existing config classes for HOCON (WIP) --- Changelog.txt | 1 + .../gmail/nossr50/config/AdvancedConfig.java | 4 +- .../java/com/gmail/nossr50/config/Config.java | 53 +++++++++++++++++-- .../nossr50/config/ConfigCollection.java | 23 ++------ .../gmail/nossr50/config/ConfigConstants.java | 6 ++- .../gmail/nossr50/config/ConfigManager.java | 31 +++++------ .../gmail/nossr50/config/ConfigValidated.java | 18 ++----- .../nossr50/config/CoreSkillsConfig.java | 4 +- .../com/gmail/nossr50/config/MainConfig.java | 4 +- .../com/gmail/nossr50/config/RankConfig.java | 4 +- .../com/gmail/nossr50/config/SoundConfig.java | 4 +- .../MultiConfigContainer.java | 50 +++++++++++------ .../collectionconfigs/RepairConfig.java | 7 ++- .../collectionconfigs/SalvageConfig.java | 7 ++- .../config/experience/ExperienceConfig.java | 5 +- .../experience/HerbalismExperienceConfig.java | 7 --- .../experience/MiningExperienceConfig.java | 7 --- .../WoodcuttingExperienceConfig.java | 7 --- .../config/hocon/database/ConfigDatabase.java | 3 +- .../experience/HerbalismExperienceConfig.java | 36 +++++++++++++ .../experience/MiningExperienceConfig.java | 36 +++++++++++++ .../WoodcuttingExperienceConfig.java | 36 +++++++++++++ .../config/party/ItemWeightConfig.java | 3 +- .../config/skills/alchemy/PotionConfig.java | 5 +- .../treasure/ExcavationTreasureConfig.java | 3 +- .../treasure/FishingTreasureConfig.java | 3 +- .../treasure/HerbalismTreasureConfig.java | 3 +- 27 files changed, 263 insertions(+), 107 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/config/experience/HerbalismExperienceConfig.java delete mode 100644 src/main/java/com/gmail/nossr50/config/experience/MiningExperienceConfig.java delete mode 100644 src/main/java/com/gmail/nossr50/config/experience/WoodcuttingExperienceConfig.java create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/experience/HerbalismExperienceConfig.java create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/experience/MiningExperienceConfig.java create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/experience/WoodcuttingExperienceConfig.java diff --git a/Changelog.txt b/Changelog.txt index 7c4e5314f..b68bf75bb 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -115,6 +115,7 @@ Version 2.1.16 Breaking Kelp should now count the whole plant for XP Spawned Mobs that are not supposed to award XP will no longer reward XP once transformed (ie: drowned) mcMMO's config system has been rewritten + Repair and Salvage configs are now confined to a single file mcMMO will no longer shutdown if it finds invalid config entries mcMMO will nag admins about invalid config entries when they join the server mcMMO's mod config system has been temporarily disabled as modded bukkit servers don't exist anymore (Forge Bukkit hybrid servers) diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index ac202c5d2..e0829baf5 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -4,11 +4,13 @@ import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill; import com.gmail.nossr50.mcMMO; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.bukkit.ChatColor; import java.util.ArrayList; import java.util.List; +@ConfigSerializable public class AdvancedConfig extends ConfigValidated { public static final String SKILLS = "Skills"; @@ -125,7 +127,7 @@ public class AdvancedConfig extends ConfigValidated { public AdvancedConfig() { //super(mcMMO.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "advanced.yml", true, true, true); + super("advanced", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, 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 187c4a84a..89b65f870 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -5,11 +5,14 @@ import com.google.common.io.Files; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.commented.CommentedConfigurationNode; import ninja.leaping.configurate.hocon.HoconConfigurationLoader; +import ninja.leaping.configurate.loader.ConfigurationLoader; import ninja.leaping.configurate.objectmapping.ObjectMappingException; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; /** @@ -17,11 +20,14 @@ import java.util.List; */ public abstract class Config implements VersionedConfig, Unload { + public static final String HOCON_FILE_EXTENSION = ".conf"; /* 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 + private boolean generateDefaults; //Whether or not we use Configurate to generate a default file, if this is false we copy the file from the JAR + private String fileName; //The file name of the config /* PATH VARS */ @@ -56,16 +62,18 @@ public abstract class Config implements VersionedConfig, Unload { 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, boolean removeOldKeys) { + public Config(String fileName, File pathToParentFolder, String relativePath, boolean generateDefaults, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) { /* * These must be at the top */ + this.fileName = fileName; + this.generateDefaults = generateDefaults; this.copyDefaults = copyDefaults; this.mergeNewKeys = mergeNewKeys; //Whether or not we add new keys when they are found this.removeOldKeys = removeOldKeys; mkdirDefaults(); // Make our default config dir DIRECTORY_DATA_FOLDER = pathToParentFolder; //Data Folder for our plugin - FILE_RELATIVE_PATH = relativePath; //Relative path to config from a parent folder + FILE_RELATIVE_PATH = relativePath + fileName + HOCON_FILE_EXTENSION; //Relative path to config from a parent folder //Attempt IO Operations try { @@ -151,9 +159,39 @@ public abstract class Config implements VersionedConfig, Unload { * @throws IOException */ private File initDefaultConfig() throws IOException { - return copyDefaultFromJar(getDefaultConfigCopyRelativePath(), true); + if(generateDefaults) + { + return generateDefaultFile(); + } else + return copyDefaultFromJar(getDefaultConfigCopyRelativePath(), true); } + /** + * Generates a default config file using the Configurate library, makes use of @Setting and @ConfigSerializable annotations in the config file + * Assigns the default root node to the newly loaded default config if successful + * @return the File for the newly created config + */ + private File generateDefaultFile() + { + //Not sure if this will work properly... + Path potentialFile = Paths.get(getDefaultConfigCopyRelativePath()); + ConfigurationLoader generation_loader + = HoconConfigurationLoader.builder().setPath(potentialFile).build(); + try { + defaultRootNode = generation_loader.load(); + generation_loader.save(defaultRootNode); + mcMMO.p.getLogger().info("Generated a default file for "+fileName); + } catch(IOException e) { + mcMMO.p.getLogger().severe("Error when trying to generate a default configuration file for " + getDefaultConfigCopyRelativePath()); + e.printStackTrace(); + } + + //Return the default file + return getDefaultConfigFile(); + } + + + /** * Attemps to load the config file if it exists, if it doesn't it copies a new one from within the JAR * @return user config File @@ -242,6 +280,15 @@ public abstract class Config implements VersionedConfig, Unload { return DIRECTORY_DEFAULTS + File.separator + FILE_RELATIVE_PATH; } + /** + * Grabs the File representation of the default config, which is stored on disk in a defaults folder + * this file will be overwritten every time mcMMO starts to keep it up to date. + * @return the copy of the default config file, stored in the defaults directory + */ + private File getDefaultConfigFile() { + return new File(DIRECTORY_DATA_FOLDER, DIRECTORY_DEFAULTS + File.separator + FILE_RELATIVE_PATH); + } + /** * Creates the defaults directory */ diff --git a/src/main/java/com/gmail/nossr50/config/ConfigCollection.java b/src/main/java/com/gmail/nossr50/config/ConfigCollection.java index a0efff056..7bc5be308 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigCollection.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigCollection.java @@ -13,14 +13,14 @@ public abstract class ConfigCollection extends Config implements Registers, G protected Collection genericCollection; /** - * @param parentFolderPath Path to the "parent" folder on disk + * @param pathToParentFolder 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 */ - public ConfigCollection(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) { - super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys); + public ConfigCollection(String fileName, File pathToParentFolder, String relativePath, boolean generateDefaults, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) { + super(fileName, pathToParentFolder, relativePath, generateDefaults, mergeNewKeys, copyDefaults, removeOldKeys); //init initCollection(); @@ -29,23 +29,6 @@ public abstract class ConfigCollection extends Config implements Registers, G //register(); } - /** - * @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 - */ - public ConfigCollection(File parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) { - super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys); - - //init - initCollection(); - - //load - //register(); - } - /** * Initializes the generic collection held by this class */ diff --git a/src/main/java/com/gmail/nossr50/config/ConfigConstants.java b/src/main/java/com/gmail/nossr50/config/ConfigConstants.java index 36a7168df..c0b3b9a73 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigConstants.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigConstants.java @@ -11,10 +11,12 @@ public class ConfigConstants { /* FOLDER NAMES */ public static final String FOLDER_NAME_CONFIG = "config"; public static final String FOLDER_NAME_SKILLS = "skills"; + public static final String FOLDER_NAME_EXPERIENCE = "Experience Settings"; /* RELATIVE PATHS */ - public final static String RELATIVE_PATH_CONFIG_DIR = File.separator + FOLDER_NAME_CONFIG; - public final static String RELATIVE_PATH_SKILLS_DIR = RELATIVE_PATH_CONFIG_DIR + File.separator + FOLDER_NAME_SKILLS; + public final static String RELATIVE_PATH_CONFIG_DIR = File.separator + FOLDER_NAME_CONFIG + File.separator; + public final static String RELATIVE_PATH_SKILLS_DIR = RELATIVE_PATH_CONFIG_DIR + FOLDER_NAME_SKILLS + File.separator; + public final static String RELATIVE_PATH_XP_DIR = RELATIVE_PATH_CONFIG_DIR + FOLDER_NAME_EXPERIENCE + File.separator; /** * Return the data folder for mcMMO diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index bc5211888..0210d9fe8 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -1,7 +1,7 @@ package com.gmail.nossr50.config; -import com.gmail.nossr50.config.collectionconfigs.CollectionClassType; -import com.gmail.nossr50.config.collectionconfigs.MultiConfigContainer; +import com.gmail.nossr50.config.collectionconfigs.RepairConfig; +import com.gmail.nossr50.config.collectionconfigs.SalvageConfig; import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.hocon.database.ConfigDatabase; import com.gmail.nossr50.config.party.ItemWeightConfig; @@ -24,12 +24,6 @@ import java.util.ArrayList; * This makes sure that mcMMO properly loads and unloads its values on reload * * Config Manager also holds all of our MultiConfigContainers - * - * MultiConfigContainers - * Represents a collection of config files that serve a similar purpose - * As an example, with Repair you can have an unlimited number of files named repair.*.yml and each one will be treated the same and have its collections registered - * The master file is always named x.vanilla.yml, for example "repair.vanilla.yml" - * To be honest I'm not sure how many people make use of this system, but I'm keeping it since its been in mcMMO for like 6+ years */ public final class ConfigManager { @@ -40,8 +34,8 @@ public final class ConfigManager { /* MULTI CONFIG INSTANCES */ - private MultiConfigContainer repairableMultiConfigContainer; - private MultiConfigContainer salvageableMultiConfigContainer; + //private MultiConfigContainer repairableMultiConfigContainer; + //private MultiConfigContainer salvageableMultiConfigContainer; /* COLLECTION MANAGERS */ @@ -77,6 +71,8 @@ public final class ConfigManager { private SoundConfig soundConfig; private RankConfig rankConfig; private ItemWeightConfig itemWeightConfig; + private RepairConfig repairConfig; + private SalvageConfig salvageConfig; /* CONFIG ERRORS */ @@ -116,6 +112,11 @@ public final class ConfigManager { itemWeightConfig = new ItemWeightConfig(); + repairConfig = new RepairConfig(); + + salvageConfig = new SalvageConfig(); + + /*if (MainConfig.getInstance().getToolModsEnabled()) { new ToolConfigManager(); } @@ -133,7 +134,7 @@ public final class ConfigManager { }*/ // Multi Config Containers - initMultiConfigContainers(); + //initMultiConfigContainers(); /* * Managers @@ -155,7 +156,7 @@ public final class ConfigManager { /** * Initializes all of our Multi Config Containers */ - private void initMultiConfigContainers() + /*private void initMultiConfigContainers() { //Repair repairableMultiConfigContainer = new MultiConfigContainer<>("repair", CollectionClassType.REPAIR); @@ -164,7 +165,7 @@ public final class ConfigManager { //Salvage salvageableMultiConfigContainer = new MultiConfigContainer<>("salvage", CollectionClassType.SALVAGE); unloadables.add(salvageableMultiConfigContainer); - } + }*/ /** * Initializes any managers related to config collections @@ -186,7 +187,7 @@ public final class ConfigManager { */ public ArrayList getRepairables() { - return (ArrayList) repairableMultiConfigContainer.getCollection(); + return (ArrayList) repairConfig.genericCollection; } /** @@ -195,7 +196,7 @@ public final class ConfigManager { */ public ArrayList getSalvageables() { - return (ArrayList) salvageableMultiConfigContainer.getCollection(); + return (ArrayList) salvageConfig.genericCollection; } /** diff --git a/src/main/java/com/gmail/nossr50/config/ConfigValidated.java b/src/main/java/com/gmail/nossr50/config/ConfigValidated.java index 76b8770c1..e0a506c83 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigValidated.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigValidated.java @@ -8,26 +8,14 @@ import java.io.File; */ public abstract class ConfigValidated extends Config implements UnsafeValueValidation { /** - * @param parentFolderPath Path to the "parent" folder on disk + * @param pathToParentFolder File for 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 */ - public ConfigValidated(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) + public ConfigValidated(String fileName, File pathToParentFolder, String relativePath, boolean generateDefaults, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) { - super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults, removeOldKeys); - validateEntries(); - } - - /** - * @param parentFolderFile File for 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 - */ - public ConfigValidated(File parentFolderFile, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) - { - super(parentFolderFile, relativePath, mergeNewKeys, copyDefaults, removeOldKeys); + super(fileName, pathToParentFolder, relativePath, generateDefaults, 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 a6b56d1cd..013474570 100644 --- a/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java +++ b/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java @@ -4,14 +4,16 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; +@ConfigSerializable public class CoreSkillsConfig extends Config { public static final String ENABLED = "Enabled"; //private static CoreSkillsConfig instance; public CoreSkillsConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(),"coreskills.yml", true, true, true); + super("coreskills", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, 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 779998ae4..f1775d414 100644 --- a/src/main/java/com/gmail/nossr50/config/MainConfig.java +++ b/src/main/java/com/gmail/nossr50/config/MainConfig.java @@ -7,6 +7,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.entity.EntityType; @@ -14,6 +15,7 @@ import org.bukkit.entity.EntityType; import java.util.ArrayList; import java.util.List; +@ConfigSerializable public class MainConfig extends ConfigValidated { public static final String METRICS = "Metrics"; @@ -205,7 +207,7 @@ public class MainConfig extends ConfigValidated { public MainConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "config.yml", true, true, true); + super("main", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, 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 feb266851..dbd16511e 100644 --- a/src/main/java/com/gmail/nossr50/config/RankConfig.java +++ b/src/main/java/com/gmail/nossr50/config/RankConfig.java @@ -3,10 +3,12 @@ package com.gmail.nossr50.config; import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill; import com.gmail.nossr50.mcMMO; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import java.util.ArrayList; import java.util.List; +@ConfigSerializable public class RankConfig extends ConfigValidated { public static final String RETRO_MODE = "RetroMode"; public static final String STANDARD = "Standard"; @@ -14,7 +16,7 @@ public class RankConfig extends ConfigValidated { public RankConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(),"skillranks.yml", true, true, true); + super("skillranks", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, 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 3e1cd836c..563a94220 100644 --- a/src/main/java/com/gmail/nossr50/config/SoundConfig.java +++ b/src/main/java/com/gmail/nossr50/config/SoundConfig.java @@ -2,10 +2,12 @@ package com.gmail.nossr50.config; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.sounds.SoundType; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import java.util.ArrayList; import java.util.List; +@ConfigSerializable public class SoundConfig extends ConfigValidated { public static final String SOUNDS = "Sounds"; public static final String VOLUME = "Volume"; @@ -16,7 +18,7 @@ public class SoundConfig extends ConfigValidated { public SoundConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "sounds.yml", true, true, true); + super("sounds", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, 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 480012160..fa5637485 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java @@ -1,3 +1,4 @@ +/* package com.gmail.nossr50.config.collectionconfigs; import com.gmail.nossr50.config.ConfigCollection; @@ -9,16 +10,22 @@ import java.util.ArrayList; import java.util.Collection; import java.util.regex.Pattern; +*/ /** * Represents a type of config collection, these config collections are spread across multiple config files potentially * @param - */ + *//* + public class MultiConfigContainer implements Unload { - /* CONSTANTS */ + */ +/* CONSTANTS *//* + public static final String DEFAULT_MULTICONFIG_FILENAME_SUFFIX = ".vanilla.yml"; - /* VARS */ + */ +/* VARS *//* + private final String configPrefix; private Collection collection; public final CollectionClassType collectionClassType; @@ -50,20 +57,24 @@ public class MultiConfigContainer implements Unload { loadCustomCollections(configPrefix); } - /** + */ +/** * Add another collection to this collection * @param otherCollection - */ + *//* + private void addCollection(Collection otherCollection) { collection.addAll(otherCollection); } - /** + */ +/** * Grabs the Class to instance for this config collection * @param collectionClassType the type of class * @return the class to instance for this config collection - */ + *//* + private Class getConfigClass(CollectionClassType collectionClassType) { switch(collectionClassType) { @@ -77,22 +88,26 @@ public class MultiConfigContainer implements Unload { } } - /** + */ +/** * Gets the name of the vanilla config which is always present * @param configPrefix the prefix to the filename, for example "repair" or "salvage" * @return the name of the vanilla config file for this collection - */ + *//* + private String getVanillaConfigName(String configPrefix) { return configPrefix+DEFAULT_MULTICONFIG_FILENAME_SUFFIX; } - /** + */ +/** * Initializes a config and attempts to load add its collection * @param fileName * @param merge * @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 - */ + *//* + private void initConfigAndAddCollection(String fileName, boolean merge, boolean copyDefaults) { mcMMO.p.getLogger().info("Reading from collection config - "+fileName); @@ -105,7 +120,8 @@ public class MultiConfigContainer implements Unload { configCollection = new SalvageConfig(fileName, merge, copyDefaults); } - /*try { + */ +/*try { //String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys //String fileName, boolean merge, boolean copyDefaults configCollection = (ConfigCollection) getConfigClass(collectionClassType).getConstructor(String.class, Boolean.class, Boolean.class).newInstance(fileName, merge, copyDefaults); @@ -117,17 +133,20 @@ public class MultiConfigContainer implements Unload { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); - }*/ + }*//* + //Add the collection loaded from this config addCollection(configCollection.getLoadedCollection()); } - /** + */ +/** * mcMMO allows collection config files to be named things like repair.whatevernameyouwanthere.yml and so on, * these files are treated in the same way as the vanilla file. They serve the purpose of organization * @param configPrefix the prefix of the file name, for example "repair", "salvage", etc - */ + *//* + public void loadCustomCollections(String configPrefix) { String vanillaConfigFileName = getVanillaConfigName(configPrefix); @@ -163,3 +182,4 @@ public class MultiConfigContainer implements Unload { return collection; } } +*/ diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java index 05d19f371..88c8c315c 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.config.collectionconfigs; import com.gmail.nossr50.config.ConfigCollection; +import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.datatypes.skills.ItemType; import com.gmail.nossr50.datatypes.skills.MaterialType; import com.gmail.nossr50.mcMMO; @@ -9,6 +10,7 @@ import com.gmail.nossr50.skills.repair.repairables.RepairableFactory; import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.skills.SkillUtils; import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -18,6 +20,7 @@ import java.util.List; /** * This config */ +@ConfigSerializable public class RepairConfig extends ConfigCollection { public static final String REPAIRABLES = "Repairables"; @@ -31,9 +34,9 @@ public class RepairConfig extends ConfigCollection { public static final String MINIMUM_LEVEL = "MinimumLevel"; public static final String MINIMUM_QUANTITY = "MinimumQuantity"; - public RepairConfig(String fileName, boolean merge, boolean copyDefaults) { + public RepairConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, merge, copyDefaults, false); + super("repair", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_SKILLS_DIR, true, false, true, false); register(); } diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java index 9690e3a11..f70568d56 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.config.collectionconfigs; import com.gmail.nossr50.config.ConfigCollection; +import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.datatypes.skills.ItemType; import com.gmail.nossr50.datatypes.skills.MaterialType; import com.gmail.nossr50.mcMMO; @@ -9,12 +10,14 @@ import com.gmail.nossr50.skills.salvage.salvageables.SalvageableFactory; import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.skills.SkillUtils; import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; +@ConfigSerializable public class SalvageConfig extends ConfigCollection { public static final String SALVAGEABLES = "Salvageables"; @@ -27,9 +30,9 @@ public class SalvageConfig extends ConfigCollection { public static final String XP_MULTIPLIER = "XpMultiplier"; public static final String MAXIMUM_QUANTITY = "MaximumQuantity"; - public SalvageConfig(String fileName, boolean merge, boolean copyDefaults) { + public SalvageConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, merge, copyDefaults, false); + super("salvage", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_SKILLS_DIR, true, false, true, false); register(); } 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 32f013da9..1416ec8e2 100644 --- a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java +++ b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.config.experience; +import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.config.ConfigValidated; import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.skills.MaterialType; @@ -7,6 +8,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.bukkit.Material; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; @@ -15,6 +17,7 @@ import org.bukkit.entity.EntityType; import java.util.ArrayList; import java.util.List; +@ConfigSerializable public class ExperienceConfig extends ConfigValidated { public static final String EXPLOIT_FIX = "ExploitFix"; public static final String ENDERMAN_ENDERMITE_FARMS = "EndermanEndermiteFarms"; @@ -79,7 +82,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, false); + super("experience", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, false, true, false); } /** diff --git a/src/main/java/com/gmail/nossr50/config/experience/HerbalismExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/HerbalismExperienceConfig.java deleted file mode 100644 index 2d3cb0c6d..000000000 --- a/src/main/java/com/gmail/nossr50/config/experience/HerbalismExperienceConfig.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.gmail.nossr50.config.experience; - -import com.gmail.nossr50.config.ConfigValidated; - -public class HerbalismExperienceConfig extends ConfigValidated { - -} diff --git a/src/main/java/com/gmail/nossr50/config/experience/MiningExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/MiningExperienceConfig.java deleted file mode 100644 index 8a1bde298..000000000 --- a/src/main/java/com/gmail/nossr50/config/experience/MiningExperienceConfig.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.gmail.nossr50.config.experience; - -import com.gmail.nossr50.config.ConfigValidated; - -public class MiningExperienceConfig extends ConfigValidated { - -} diff --git a/src/main/java/com/gmail/nossr50/config/experience/WoodcuttingExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/WoodcuttingExperienceConfig.java deleted file mode 100644 index 7d5ce50bc..000000000 --- a/src/main/java/com/gmail/nossr50/config/experience/WoodcuttingExperienceConfig.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.gmail.nossr50.config.experience; - -import com.gmail.nossr50.config.ConfigValidated; - -public class WoodcuttingExperienceConfig extends ConfigValidated { - -} diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigDatabase.java b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigDatabase.java index 42306c563..3202fccf1 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigDatabase.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigDatabase.java @@ -12,7 +12,8 @@ public class ConfigDatabase extends Config { private ConfigCategoryMySQL configCategoryMySQL; public ConfigDatabase() { - super(ConfigConstants.getDataFolder(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, false, true); + super("mysql", ConfigConstants.getDataFolder(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, + true,true, false, true); } @Override diff --git a/src/main/java/com/gmail/nossr50/config/hocon/experience/HerbalismExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/hocon/experience/HerbalismExperienceConfig.java new file mode 100644 index 000000000..b50b7428d --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/experience/HerbalismExperienceConfig.java @@ -0,0 +1,36 @@ +package com.gmail.nossr50.config.hocon.experience; + +import com.gmail.nossr50.config.ConfigConstants; +import com.gmail.nossr50.config.ConfigValidated; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +import java.util.List; + +@ConfigSerializable +public class HerbalismExperienceConfig extends ConfigValidated { + + public HerbalismExperienceConfig() + { + super("xp_herbalism", ConfigConstants.getDataFolder(), ConfigConstants.RELATIVE_PATH_XP_DIR, true, true, true, false); + } + + @Override + public void unload() { + + } + + @Override + public List validateKeys() { + return null; + } + + /** + * The version of this config + * + * @return + */ + @Override + public double getConfigVersion() { + return 1; + } +} diff --git a/src/main/java/com/gmail/nossr50/config/hocon/experience/MiningExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/hocon/experience/MiningExperienceConfig.java new file mode 100644 index 000000000..0a038c816 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/experience/MiningExperienceConfig.java @@ -0,0 +1,36 @@ +package com.gmail.nossr50.config.hocon.experience; + +import com.gmail.nossr50.config.ConfigConstants; +import com.gmail.nossr50.config.ConfigValidated; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +import java.util.List; + +@ConfigSerializable +public class MiningExperienceConfig extends ConfigValidated { + + public MiningExperienceConfig() + { + super("xp_mining", ConfigConstants.getDataFolder(), ConfigConstants.RELATIVE_PATH_XP_DIR, true, true, true, false); + } + + @Override + public void unload() { + + } + + @Override + public List validateKeys() { + return null; + } + + /** + * The version of this config + * + * @return + */ + @Override + public double getConfigVersion() { + return 1; + } +} diff --git a/src/main/java/com/gmail/nossr50/config/hocon/experience/WoodcuttingExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/hocon/experience/WoodcuttingExperienceConfig.java new file mode 100644 index 000000000..8471385db --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/experience/WoodcuttingExperienceConfig.java @@ -0,0 +1,36 @@ +package com.gmail.nossr50.config.hocon.experience; + +import com.gmail.nossr50.config.ConfigConstants; +import com.gmail.nossr50.config.ConfigValidated; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +import java.util.List; + +@ConfigSerializable +public class WoodcuttingExperienceConfig extends ConfigValidated { + + public WoodcuttingExperienceConfig() + { + super("xp_woodcutting", ConfigConstants.getDataFolder(), ConfigConstants.RELATIVE_PATH_XP_DIR, true, true, true, false); + } + + @Override + public void unload() { + + } + + @Override + public List validateKeys() { + return null; + } + + /** + * The version of this config + * + * @return + */ + @Override + public double getConfigVersion() { + return 1; + } +} 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 69612ba5c..cff981754 100644 --- a/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java +++ b/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.config.party; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; import ninja.leaping.configurate.objectmapping.ObjectMappingException; @@ -16,7 +17,7 @@ public class ItemWeightConfig extends Config { public ItemWeightConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "itemweights.yml"); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "itemweights.yml", true, true, false); + super("itemweights", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, 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 fbf633d97..4a79d3c31 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 @@ -1,11 +1,13 @@ package com.gmail.nossr50.config.skills.alchemy; import com.gmail.nossr50.config.ConfigCollection; +import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion; import com.gmail.nossr50.mcMMO; import com.google.common.reflect.TypeToken; import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.objectmapping.ObjectMappingException; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; @@ -23,6 +25,7 @@ import java.util.Map; /** * Eventually I'm going to delete all of our Alchemy code and rewrite it from scratch */ +@ConfigSerializable public class PotionConfig extends ConfigCollection { /* CONSTANTS */ @@ -63,7 +66,7 @@ public class PotionConfig extends ConfigCollection { private Map potionMap = new HashMap(); public PotionConfig() { - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true, true); + super("skillranks", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, true, true, true); initIngredientLists(); register(); } diff --git a/src/main/java/com/gmail/nossr50/config/treasure/ExcavationTreasureConfig.java b/src/main/java/com/gmail/nossr50/config/treasure/ExcavationTreasureConfig.java index ef4fbeb7e..7e1c30362 100644 --- a/src/main/java/com/gmail/nossr50/config/treasure/ExcavationTreasureConfig.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/ExcavationTreasureConfig.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.config.treasure; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.config.Registers; import com.gmail.nossr50.config.UnsafeValueValidation; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; @@ -25,7 +26,7 @@ public class ExcavationTreasureConfig extends Config implements UnsafeValueValid public HashMap> excavationMap = new HashMap>(); public ExcavationTreasureConfig() { - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "excavation_treasures.yml", false, true, false); + super("excavation_drops", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, false, true, false); register(); } diff --git a/src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java b/src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java index f7b53f40b..21251aac9 100644 --- a/src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.config.treasure; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.config.Registers; import com.gmail.nossr50.config.UnsafeValueValidation; import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure; @@ -56,7 +57,7 @@ public class FishingTreasureConfig extends Config implements UnsafeValueValidati } public FishingTreasureConfig() { - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "fishing_treasures.yml", false, true, false); + super("fishing_drops", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, false, true, false); register(); } diff --git a/src/main/java/com/gmail/nossr50/config/treasure/HerbalismTreasureConfig.java b/src/main/java/com/gmail/nossr50/config/treasure/HerbalismTreasureConfig.java index d35378d7c..39c426b7c 100644 --- a/src/main/java/com/gmail/nossr50/config/treasure/HerbalismTreasureConfig.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/HerbalismTreasureConfig.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.config.treasure; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.config.Registers; import com.gmail.nossr50.config.UnsafeValueValidation; import com.gmail.nossr50.datatypes.treasure.HylianTreasure; @@ -28,7 +29,7 @@ public class HerbalismTreasureConfig extends Config implements UnsafeValueValida public HashMap> hylianMap = new HashMap>(); public HerbalismTreasureConfig() { - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "herbalism_treasures.yml", false, true, false); + super("hylian_luck_drops", mcMMO.p.getDataFolder().getAbsoluteFile(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, false, true, false); register(); }