From d3b437f6d3bad2db907835d913d44e0c9deb24f7 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 12 Mar 2019 00:37:26 -0700 Subject: [PATCH] Renaming config classes --- .../nossr50/config/hocon/ConfigSection.java | 7 ++++ .../config/hocon/database/ConfigDatabase.java | 18 ++++++++--- ...se.java => UserConfigSectionDatabase.java} | 3 +- ...a => UserConfigSectionMaxConnections.java} | 2 +- ...java => UserConfigSectionMaxPoolSize.java} | 2 +- ...MySQL.java => UserConfigSectionMySQL.java} | 32 +++++++++---------- ...rver.java => UserConfigSectionServer.java} | 14 ++++---- ...ryUser.java => UserConfigSectionUser.java} | 2 +- .../nossr50/database/SQLDatabaseManager.java | 22 ++++++------- src/main/java/com/gmail/nossr50/mcMMO.java | 6 ++-- 10 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/ConfigSection.java rename src/main/java/com/gmail/nossr50/config/hocon/database/{ConfigCategoryDatabase.java => UserConfigSectionDatabase.java} (86%) rename src/main/java/com/gmail/nossr50/config/hocon/database/{ConfigCategoryMaxConnections.java => UserConfigSectionMaxConnections.java} (92%) rename src/main/java/com/gmail/nossr50/config/hocon/database/{ConfigCategoryMaxPoolSize.java => UserConfigSectionMaxPoolSize.java} (92%) rename src/main/java/com/gmail/nossr50/config/hocon/database/{ConfigCategoryMySQL.java => UserConfigSectionMySQL.java} (54%) rename src/main/java/com/gmail/nossr50/config/hocon/database/{ConfigCategoryServer.java => UserConfigSectionServer.java} (77%) rename src/main/java/com/gmail/nossr50/config/hocon/database/{ConfigCategoryUser.java => UserConfigSectionUser.java} (94%) diff --git a/src/main/java/com/gmail/nossr50/config/hocon/ConfigSection.java b/src/main/java/com/gmail/nossr50/config/hocon/ConfigSection.java new file mode 100644 index 000000000..5f1d9c7d1 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/ConfigSection.java @@ -0,0 +1,7 @@ +package com.gmail.nossr50.config.hocon; + +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +@ConfigSerializable +public class ConfigSection { +} 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 1e6d6fcbc..38140247e 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 @@ -8,9 +8,6 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable public class ConfigDatabase extends Config { - @Setting(value = "MySQL", comment = "Settings for using MySQL or MariaDB database") - private ConfigCategoryMySQL configCategoryMySQL; - public ConfigDatabase() { super("mysql", ConfigConstants.getDataFolder(), ConfigConstants.RELATIVE_PATH_CONFIG_DIR, true,true, false, true); @@ -18,6 +15,17 @@ public class ConfigDatabase extends Config { initFullConfig(); //Load Config } + /* + * CONFIG NODES + */ + + @Setting(value = "MySQL", comment = "Settings for using MySQL or MariaDB database") + private UserConfigSectionMySQL userConfigSectionMySQL; + + /* + * CLASS OVERRIDES + */ + @Override public void unload() { @@ -37,7 +45,7 @@ public class ConfigDatabase extends Config { * GETTER BOILERPLATE */ - public ConfigCategoryMySQL getConfigCategoryMySQL() { - return configCategoryMySQL; + public UserConfigSectionMySQL getUserConfigSectionMySQL() { + return userConfigSectionMySQL; } } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryDatabase.java b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionDatabase.java similarity index 86% rename from src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryDatabase.java rename to src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionDatabase.java index 4198d6cfd..6ccfbfd1b 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryDatabase.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionDatabase.java @@ -1,10 +1,11 @@ package com.gmail.nossr50.config.hocon.database; +import com.gmail.nossr50.config.hocon.ConfigSection; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class ConfigCategoryDatabase { +public class UserConfigSectionDatabase extends ConfigSection { @Setting(value = "Database_Name", comment = "The database name for your DB, this DB must already exist on the SQL server.") private String databaseName = "example_database_name"; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxConnections.java b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionMaxConnections.java similarity index 92% rename from src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxConnections.java rename to src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionMaxConnections.java index a85202ea6..1f17ba008 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxConnections.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionMaxConnections.java @@ -4,7 +4,7 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class ConfigCategoryMaxConnections { +public class UserConfigSectionMaxConnections { @Setting(value = "Misc") private int misc = 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/UserConfigSectionMaxPoolSize.java similarity index 92% rename from src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxPoolSize.java rename to src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionMaxPoolSize.java index 66db2ce17..3af87ba09 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMaxPoolSize.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionMaxPoolSize.java @@ -4,7 +4,7 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class ConfigCategoryMaxPoolSize { +public class UserConfigSectionMaxPoolSize { @Setting(value = "Misc") private int misc = 10; diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMySQL.java b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionMySQL.java similarity index 54% rename from src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMySQL.java rename to src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionMySQL.java index 3ec40e561..17fc7a2ff 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryMySQL.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionMySQL.java @@ -5,19 +5,19 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class ConfigCategoryMySQL { +public class UserConfigSectionMySQL { @Setting(value = "Enabled", comment = "If set to true, mcMMO will use MySQL/MariaDB instead of FlatFile storage") private boolean enabled = true; @Setting(value = "User", comment = "Your MySQL User Settings") - private ConfigCategoryUser configCategoryUser; + private UserConfigSectionUser userConfigSectionUser; @Setting(value = "Database", comment = "Database settings for MySQL/MariaDB") - private ConfigCategoryDatabase configCategoryDatabase; + private UserConfigSectionDatabase userConfigSectionDatabase; @Setting(value = "Server", comment = "Your MySQL/MariaDB server settings.") - private ConfigCategoryServer configCategoryServer; + private UserConfigSectionServer userConfigSectionServer; /* * GETTER BOILERPLATE @@ -27,16 +27,16 @@ public class ConfigCategoryMySQL { return enabled; } - public ConfigCategoryUser getConfigCategoryUser() { - return configCategoryUser; + public UserConfigSectionUser getUserConfigSectionUser() { + return userConfigSectionUser; } - public ConfigCategoryDatabase getConfigCategoryDatabase() { - return configCategoryDatabase; + public UserConfigSectionDatabase getUserConfigSectionDatabase() { + return userConfigSectionDatabase; } - public ConfigCategoryServer getConfigCategoryServer() { - return configCategoryServer; + public UserConfigSectionServer getUserConfigSectionServer() { + return userConfigSectionServer; } public int getMaxPoolSize(SQLDatabaseManager.PoolIdentifier poolIdentifier) @@ -44,11 +44,11 @@ public class ConfigCategoryMySQL { switch (poolIdentifier) { case LOAD: - return configCategoryServer.getConfigCategoryMaxPoolSize().getLoad(); + return userConfigSectionServer.getUserConfigSectionMaxPoolSize().getLoad(); case SAVE: - return configCategoryServer.getConfigCategoryMaxPoolSize().getSave(); + return userConfigSectionServer.getUserConfigSectionMaxPoolSize().getSave(); case MISC: - return configCategoryServer.getConfigCategoryMaxPoolSize().getMisc(); + return userConfigSectionServer.getUserConfigSectionMaxPoolSize().getMisc(); default: return 20; } @@ -59,11 +59,11 @@ public class ConfigCategoryMySQL { switch (poolIdentifier) { case LOAD: - return configCategoryServer.getConfigCategoryMaxPoolSize().getLoad(); + return userConfigSectionServer.getUserConfigSectionMaxPoolSize().getLoad(); case SAVE: - return configCategoryServer.getConfigCategoryMaxPoolSize().getSave(); + return userConfigSectionServer.getUserConfigSectionMaxPoolSize().getSave(); case MISC: - return configCategoryServer.getConfigCategoryMaxPoolSize().getMisc(); + return userConfigSectionServer.getUserConfigSectionMaxPoolSize().getMisc(); default: return 20; } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryServer.java b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionServer.java similarity index 77% rename from src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryServer.java rename to src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionServer.java index 72400953b..734334561 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryServer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionServer.java @@ -4,7 +4,7 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class ConfigCategoryServer { +public class UserConfigSectionServer { @Setting(value = "Use_SSL", comment = "Enables SSL for MySQL/MariaDB connections, newer versions of MySQL will spam your console if you aren't using SSL." + " It is recommended that you turn this on if you are using a newer version of MySQL," + @@ -18,10 +18,10 @@ public class ConfigCategoryServer { private String serverAddress = "localhost"; @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; + private UserConfigSectionMaxConnections userConfigSectionMaxConnections; @Setting(value = "Max_Pool_Size", comment = "This setting is the max size of the pool of cached connections that we hold at any given time.") - private ConfigCategoryMaxPoolSize configCategoryMaxPoolSize; + private UserConfigSectionMaxPoolSize userConfigSectionMaxPoolSize; /* * GETTER BOILERPLATE @@ -39,12 +39,12 @@ public class ConfigCategoryServer { return serverAddress; } - public ConfigCategoryMaxConnections getConfigCategoryMaxConnections() { - return configCategoryMaxConnections; + public UserConfigSectionMaxConnections getUserConfigSectionMaxConnections() { + return userConfigSectionMaxConnections; } - public ConfigCategoryMaxPoolSize getConfigCategoryMaxPoolSize() { - return configCategoryMaxPoolSize; + public UserConfigSectionMaxPoolSize getUserConfigSectionMaxPoolSize() { + return userConfigSectionMaxPoolSize; } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryUser.java b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionUser.java similarity index 94% rename from src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryUser.java rename to src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionUser.java index 149fbd8e1..1c86f57cd 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/database/ConfigCategoryUser.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/database/UserConfigSectionUser.java @@ -4,7 +4,7 @@ import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @ConfigSerializable -public class ConfigCategoryUser { +public class UserConfigSectionUser { @Setting(value = "User_Name", comment = "The authorized user for your MySQL/MariaDB DB") private String username = "example_user_name"; diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index 924b5fd7a..b8b27b2ee 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -22,7 +22,7 @@ import java.util.concurrent.locks.ReentrantLock; public final class SQLDatabaseManager implements DatabaseManager { private static final String ALL_QUERY_VERSION = "total"; public static final String COM_MYSQL_JDBC_DRIVER = "com.mysql.jdbc.Driver"; - private String tablePrefix = mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getTablePrefix(); + private String tablePrefix = mcMMO.getMySQLConfigSettings().getUserConfigSectionDatabase().getTablePrefix(); private final Map cachedUserIDs = new HashMap(); @@ -33,10 +33,10 @@ public final class SQLDatabaseManager implements DatabaseManager { private ReentrantLock massUpdateLock = new ReentrantLock(); protected SQLDatabaseManager() { - String connectionString = "jdbc:mysql://" + mcMMO.getMySQLConfigSettings().getConfigCategoryServer().getServerAddress() - + ":" + mcMMO.getMySQLConfigSettings().getConfigCategoryServer().getServerPort() + "/" + mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName(); + String connectionString = "jdbc:mysql://" + mcMMO.getMySQLConfigSettings().getUserConfigSectionServer().getServerAddress() + + ":" + mcMMO.getMySQLConfigSettings().getUserConfigSectionServer().getServerPort() + "/" + mcMMO.getMySQLConfigSettings().getUserConfigSectionDatabase().getDatabaseName(); - if(mcMMO.getMySQLConfigSettings().getConfigCategoryServer().isUseSSL()) + if(mcMMO.getMySQLConfigSettings().getUserConfigSectionServer().isUseSSL()) connectionString += "?verifyServerCertificate=false"+ "&useSSL=true"+ @@ -85,9 +85,9 @@ public final class SQLDatabaseManager implements DatabaseManager { poolProperties.setUrl(connectionString); //MySQL User Name - poolProperties.setUsername(mcMMO.getMySQLConfigSettings().getConfigCategoryUser().getUsername()); + poolProperties.setUsername(mcMMO.getMySQLConfigSettings().getUserConfigSectionUser().getUsername()); //MySQL User Password - poolProperties.setPassword(mcMMO.getMySQLConfigSettings().getConfigCategoryUser().getPassword()); + poolProperties.setPassword(mcMMO.getMySQLConfigSettings().getUserConfigSectionUser().getPassword()); //Initial Size poolProperties.setInitialSize(0); @@ -783,7 +783,7 @@ public final class SQLDatabaseManager implements DatabaseManager { + " WHERE table_schema = ?" + " AND table_name = ?"); //Database name - statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName()); + statement.setString(1, mcMMO.getMySQLConfigSettings().getUserConfigSectionDatabase().getDatabaseName()); statement.setString(2, tablePrefix + "users"); resultSet = statement.executeQuery(); if (!resultSet.next()) { @@ -800,7 +800,7 @@ public final class SQLDatabaseManager implements DatabaseManager { } tryClose(resultSet); //Database name - statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName()); + statement.setString(1, mcMMO.getMySQLConfigSettings().getUserConfigSectionDatabase().getDatabaseName()); statement.setString(2, tablePrefix + "huds"); resultSet = statement.executeQuery(); if (!resultSet.next()) { @@ -815,7 +815,7 @@ public final class SQLDatabaseManager implements DatabaseManager { } tryClose(resultSet); //Database name - statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName()); + statement.setString(1, mcMMO.getMySQLConfigSettings().getUserConfigSectionDatabase().getDatabaseName()); statement.setString(2, tablePrefix + "cooldowns"); resultSet = statement.executeQuery(); if (!resultSet.next()) { @@ -841,7 +841,7 @@ public final class SQLDatabaseManager implements DatabaseManager { } tryClose(resultSet); //Database name - statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName()); + statement.setString(1, mcMMO.getMySQLConfigSettings().getUserConfigSectionDatabase().getDatabaseName()); statement.setString(2, tablePrefix + "skills"); resultSet = statement.executeQuery(); if (!resultSet.next()) { @@ -870,7 +870,7 @@ public final class SQLDatabaseManager implements DatabaseManager { } tryClose(resultSet); //Database name - statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName()); + statement.setString(1, mcMMO.getMySQLConfigSettings().getUserConfigSectionDatabase().getDatabaseName()); statement.setString(2, tablePrefix + "experience"); resultSet = statement.executeQuery(); if (!resultSet.next()) { diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index d550c58f7..cb16b2e23 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -5,7 +5,7 @@ import com.gmail.nossr50.config.CoreSkillsConfig; import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.config.WorldBlacklist; import com.gmail.nossr50.config.experience.ExperienceConfig; -import com.gmail.nossr50.config.hocon.database.ConfigCategoryMySQL; +import com.gmail.nossr50.config.hocon.database.UserConfigSectionMySQL; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManagerFactory; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; @@ -327,9 +327,9 @@ public class mcMMO extends JavaPlugin { * Returns settings for MySQL from the users config * @return returns settings for MySQL from the users config */ - public static ConfigCategoryMySQL getMySQLConfigSettings() + public static UserConfigSectionMySQL getMySQLConfigSettings() { - return configManager.getConfigDatabase().getConfigCategoryMySQL(); + return configManager.getConfigDatabase().getUserConfigSectionMySQL(); } /*public static ModManager getModManager() {