From 7d152794bad611d737fbecd7507d274d32a55e8b Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 8 Mar 2019 17:54:23 -0800 Subject: [PATCH] add missing defaults and constructor for database config --- .../java/com/gmail/nossr50/config/Config.java | 4 +-- .../gmail/nossr50/config/ConfigConstants.java | 27 +++++++++++++++++++ .../gmail/nossr50/config/ConfigManager.java | 5 ++++ .../database/ConfigCategoryDatabase.java | 8 +++--- .../ConfigCategoryMaxConnections.java | 6 ++--- .../database/ConfigCategoryMaxPoolSize.java | 6 ++--- .../hocon/database/ConfigCategoryMySQL.java | 2 +- .../config/hocon/database/ConfigDatabase.java | 22 ++++++++++++++- 8 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/ConfigConstants.java diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index 54ed0dd63..187c4a84a 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -50,11 +50,11 @@ public abstract class Config implements VersionedConfig, Unload { /* CONFIG MANAGER */ //private ConfigurationLoader configManager; - public Config(String pathToParentFolder, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) { + /*public Config(String pathToParentFolder, String relativePath, boolean mergeNewKeys, boolean copyDefaults, boolean removeOldKeys) { //TODO: Check if this works... 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, boolean removeOldKeys) { /* diff --git a/src/main/java/com/gmail/nossr50/config/ConfigConstants.java b/src/main/java/com/gmail/nossr50/config/ConfigConstants.java new file mode 100644 index 000000000..36a7168df --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/ConfigConstants.java @@ -0,0 +1,27 @@ +package com.gmail.nossr50.config; + +import com.gmail.nossr50.mcMMO; + +import java.io.File; + +/** + * Constants relating to config folders and paths + */ +public class ConfigConstants { + /* FOLDER NAMES */ + public static final String FOLDER_NAME_CONFIG = "config"; + public static final String FOLDER_NAME_SKILLS = "skills"; + + /* 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; + + /** + * Return the data folder for mcMMO + * @return the File for the data folder used by mcMMO + */ + public static File getDataFolder() + { + return mcMMO.p.getDataFolder(); + } +} diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 89758a71c..bc5211888 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -3,6 +3,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.experience.ExperienceConfig; +import com.gmail.nossr50.config.hocon.database.ConfigDatabase; import com.gmail.nossr50.config.party.ItemWeightConfig; import com.gmail.nossr50.config.skills.alchemy.PotionConfig; import com.gmail.nossr50.config.treasure.ExcavationTreasureConfig; @@ -64,6 +65,7 @@ public final class ConfigManager { /* CONFIG INSTANCES */ + private ConfigDatabase configDatabase; private MainConfig mainConfig; private FishingTreasureConfig fishingTreasureConfig; private ExcavationTreasureConfig excavationTreasureConfig; @@ -92,6 +94,7 @@ public final class ConfigManager { // I'm pretty these are supposed to be done in a specific order, so don't rearrange them willy nilly //TODO: Not sure about the order of MainConfig + configDatabase = new ConfigDatabase(); mainConfig = new MainConfig(); fishingTreasureConfig = new FishingTreasureConfig(); @@ -299,4 +302,6 @@ public final class ConfigManager { public ExperienceMapManager getExperienceMapManager() { return experienceMapManager; } + + public ConfigDatabase getConfigDatabase() { return configDatabase; } } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryDatabase.java b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryDatabase.java index e506425f3..cd6a3671f 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryDatabase.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryDatabase.java @@ -7,16 +7,16 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; public class ConfigCategoryDatabase { @Setting(value = "User_Name", comment = "The authorized user for your MySQL/MariaDB DB") - private String username; + private String username = "example_user_name"; @Setting(value = "User_Password", comment = "The password for your authorized user") - private String password; + private String password = "example_user_password"; @Setting(value = "Database_Name", comment = "The database name for your DB, this DB must already exist on the SQL server.") - private String databaseName; + private String databaseName = "example_database_name"; @Setting(value = "Table_Prefix", comment = "The Prefix that will be used for tables in your DB") - private String tablePrefix; + private String tablePrefix = "mcmmo_"; @Setting(value = "Max_Connections", comment = "This setting is the max simultaneous MySQL/MariaDB connections allowed at a time, this needs to be high enough to support multiple player logins in quick succession") private ConfigCategoryMaxConnections configCategoryMaxConnections; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxConnections.java b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxConnections.java index 6e575c694..d1106199c 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxConnections.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxConnections.java @@ -7,12 +7,12 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; public class ConfigCategoryMaxConnections { @Setting(value = "Misc") - private int misc; + private int misc = 30; @Setting(value = "Load") - private int load; + private int load = 30; @Setting(value = "Save") - private int save; + private int save = 30; } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxPoolSize.java b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxPoolSize.java index 797175082..b8efc7862 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxPoolSize.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxPoolSize.java @@ -6,11 +6,11 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable public class ConfigCategoryMaxPoolSize { @Setting(value = "Misc") - private int misc; + private int misc = 10; @Setting(value = "Load") - private int load; + private int load = 20; @Setting(value = "Save") - private int save; + private int save = 20; } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMySQL.java b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMySQL.java index 5c7cd8eef..4242cd685 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMySQL.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMySQL.java @@ -7,7 +7,7 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; public class ConfigCategoryMySQL { @Setting(value = "Enabled", comment = "If set to true, mcMMO will use MySQL/MariaDB instead of FlatFile storage") - private boolean enabled; + private boolean enabled = true; @Setting(value = "Database", comment = "Database settings for MySQL/MariaDB") private ConfigCategoryDatabase configCategoryDatabase; 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 b7572243a..42306c563 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 @@ -1,12 +1,32 @@ package com.gmail.nossr50.config.hocon.database; +import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.config.ConfigConstants; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class ConfigDatabase { +public class ConfigDatabase extends Config { @Setting(value = "MySQL", comment = "Settings for using MySQL or MariaDB database") private ConfigCategoryMySQL configCategoryMySQL; + public ConfigDatabase() { + super(ConfigConstants.getDataFolder(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true, false, true); + } + + @Override + public void unload() { + + } + + /** + * The version of this config + * + * @return + */ + @Override + public double getConfigVersion() { + return 1; + } }