diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/config/Config.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/config/Config.java index b1308c0cf..dac14aa50 100644 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/config/Config.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/config/Config.java @@ -2,7 +2,6 @@ import io.github.thatsmusic99.configurationmaster.api.ConfigFile; import io.github.thatsmusic99.configurationmaster.api.ConfigSection; -import io.github.thatsmusic99.configurationmaster.api.Title; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -20,60 +19,43 @@ public class Config { public final Locale default_lang; public final boolean auto_lang, protocolLib_IsDisabled, connectionMsgsAreOnByDefault, kickPhraseCommandIsEnabled; - public final double config_version; public final int nether_ceiling_max_y; public final Component sayCommandFormat; public Config() { configFile = new File(AnarchyExploitFixes.getInstance().getDataFolder(), "config.yml"); - createFiles(); loadConfig(); - // Config Version - This has no function yet but can be used to parse older configs to new versions in the future. - this.config_version = getDouble("config-version", 1.0); + structureConfig(); // Language Settings - createSection("Language", "language"); this.default_lang = Locale.forLanguageTag(getString("language.default-language", "en_us", "The default language that will be used if auto-language is false or no matching language file was found.").replace("_", "-")); this.auto_lang = getBoolean("language.auto-language", true, "If set to true, will display messages based on client language"); // General Settings - createSection("General", "general"); this.protocolLib_IsDisabled = getBoolean("general.disable-all-ProtocolLib", false, "Use only if you are having problems with ProtocolLib when starting the plugin."); this.nether_ceiling_max_y = getInt("general.nether-ceiling-y", 127, "The Y-level at which the nether ceiling generates the last layer of bedrock on your server."); // Force config order - createSection("Patches", "patches"); - createSection("Preventions", "preventions"); - createSection("Lag Preventions", "lag-preventions"); - createSection("Dupe Preventions", "dupe-preventions"); - createSection("Combat", "combat"); - createSection("Illegals", "illegals"); - createSection("Chunk Limits", "chunk-limits"); - createSection("Bedrock", "bedrock"); - createSection("Elytra", "elytra"); config.addDefault("elytra.elytra-speed.display-actionbar", true, "Display info in Actionbar while flying."); config.addDefault("elytra.elytra-speed.display-chunk-info-in-actionbar", true, "Inform flying player if they are in old or new chunks."); config.addDefault("elytra.elytra-speed.play-sound-when-too-fast", true, "Plays XP pickup sound to alert players when theyre going above the limit."); config.addDefault("elytra.elytra-speed.teleport-instead-of-canceling-movement", false, "Recommended to leave false if you dont experience any issues."); - createSection("Chat", "chat"); // Misc - createSection("Miscellaneous", "misc"); - this.sayCommandFormat = MiniMessage.miniMessage().deserialize(getString("misc.say-command-format", "SERVER: %message%")); + this.sayCommandFormat = MiniMessage.miniMessage().deserialize(getString("misc.say-command-format", "SERVER: %message%", "Uses MiniMessage formatting.")); config.addDefault("misc.join-leave-messages.enable", true); // add default here so enable option shows up first. this.connectionMsgsAreOnByDefault = getBoolean("misc.join-leave-messages.connection-messages-on-by-default", true, "default mode of /toggleconnectionmsgs"); config.addDefault("misc.join-leave-messages.show-in-console", false); // add default here so show-in-console option is not misplaced. this.kickPhraseCommandIsEnabled = getBoolean("misc.enable-kickphrase-command", false, "Enable the /aef kickphrase command."); - - // 1b1t Options last like in the original version - createSection("1b1t Options", "1b1t-options"); } - private void createFiles() { + private void loadConfig() { + // Create folder and file if not exist try { File parent = new File(configFile.getParent()); if (!parent.exists()) { - if (!parent.mkdir()) AnarchyExploitFixes.getLog().severe("Unable to create plugin config directory."); + if (!parent.mkdir()) + AnarchyExploitFixes.getLog().severe("Unable to create plugin config directory."); } if (!configFile.exists()) { configFile.createNewFile(); // Result can be ignored because this method only returns false if the file already exists, @@ -81,9 +63,7 @@ private void createFiles() { } catch (IOException e) { e.printStackTrace(); } - } - - private void loadConfig() { + // Load file try { config = ConfigFile.loadConfig(configFile); } catch (Exception e) { @@ -99,7 +79,25 @@ public void saveConfig() { } } - public void createSection(String title, String path) { + private void structureConfig() { + config.addDefault("config-version", 1.00); + createTitledSection("Language", "language"); + createTitledSection("General", "general"); + createTitledSection("Patches", "patches"); + createTitledSection("Preventions", "preventions"); + createTitledSection("Lag Preventions", "lag-preventions"); + createTitledSection("Dupe Preventions", "dupe-preventions"); + createTitledSection("Combat", "combat"); + createTitledSection("Illegals", "illegals"); + createTitledSection("Chunk Limits", "chunk-limits"); + createTitledSection("Bedrock", "bedrock"); + createTitledSection("Elytra", "elytra"); + createTitledSection("Chat", "chat"); + createTitledSection("Miscellaneous", "misc"); + createTitledSection("1b1t Options", "1b1t-options"); + } + + public void createTitledSection(String title, String path) { config.addSection(title); config.addDefault(path, null); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/config/Config.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/config/Config.java index 737717d1f..2963b319e 100644 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/config/Config.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/config/Config.java @@ -9,7 +9,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.logging.Logger; public class Config { @@ -18,62 +17,45 @@ public class Config { public final Locale default_lang; public final boolean auto_lang, protocolLib_IsDisabled, connectionMsgsAreOnByDefault, kickPhraseCommandIsEnabled; - public final double config_version; public final int nether_ceiling_max_y, nether_floor_min_y, overworld_floor_min_y; public final String sayCommandFormat; public Config() { configFile = new File(AnarchyExploitFixes.getInstance().getDataFolder(), "config.yml"); - createFiles(); loadConfig(); - // Config Version - This has no function yet but can be used to parse older configs to new versions in the future. - this.config_version = getDouble("config-version", 1.0); + structureConfig(); // Language Settings - createSection("Language", "language"); this.default_lang = Locale.forLanguageTag(getString("language.default-language", "en_us", "The default language that will be used if auto-language is false or no matching language file was found.").replace("_", "-")); this.auto_lang = getBoolean("language.auto-language", true, "If set to true, will display messages based on client language"); // General Settings - createSection("General", "general"); this.protocolLib_IsDisabled = getBoolean("general.disable-all-ProtocolLib", false, "Use only if you are having problems with ProtocolLib when starting the plugin."); this.nether_ceiling_max_y = getInt("general.nether-ceiling-y", 127, "The Y-level at which the nether ceiling generates the last layer of bedrock on your server."); this.nether_floor_min_y = getInt("general.nether-floor-y", 0, "The Y-level at which the nether floor generates the last layer of bedrock on your server."); this.overworld_floor_min_y = getInt("general.overworld-floor-y", AnarchyExploitFixes.getMCVersion() > 17 ? -64 : 0, "The Y-level at which the overworld floor generates the last layer of bedrock on your server."); // Force config order - createSection("Patches", "patches"); - createSection("Preventions", "preventions"); - createSection("Lag Preventions", "lag-preventions"); - createSection("Dupe Preventions", "dupe-preventions"); - createSection("Combat", "combat"); - createSection("Illegals", "illegals"); - createSection("Chunk Limits", "chunk-limits"); - createSection("Bedrock", "bedrock"); - createSection("Elytra", "elytra"); config.addDefault("elytra.elytra-speed.display-actionbar", true, "Display info in Actionbar while flying."); config.addDefault("elytra.elytra-speed.display-chunk-info-in-actionbar", true, "Inform flying player if they are in old or new chunks."); config.addDefault("elytra.elytra-speed.play-sound-when-too-fast", true, "Plays XP pickup sound to alert players when theyre going above the limit."); config.addDefault("elytra.elytra-speed.teleport-instead-of-canceling-movement", false, "Recommended to leave false if you dont experience any issues."); - createSection("Chat", "chat"); // Misc - createSection("Miscellaneous", "misc"); this.sayCommandFormat = getString("misc.say-command-format", "&7Server: &6%message%"); config.addDefault("misc.join-leave-messages.enable", true); // add default here so enable option shows up first. this.connectionMsgsAreOnByDefault = getBoolean("misc.join-leave-messages.connection-messages-on-by-default", true, "default mode of /toggleconnectionmsgs"); config.addDefault("misc.join-leave-messages.show-in-console", false); // add default here so show-in-console option is not misplaced. this.kickPhraseCommandIsEnabled = getBoolean("misc.enable-kickphrase-command", false, "Enable the /aef kickphrase command."); - - // 1b1t Options last like in the original version - createSection("1b1t Options", "1b1t-options"); } - private void createFiles() { + private void loadConfig() { + // Create folder and file if not exist try { File parent = new File(configFile.getParent()); if (!parent.exists()) { - if (!parent.mkdir()) AnarchyExploitFixes.getLog().severe("Unable to create plugin config directory."); + if (!parent.mkdir()) + AnarchyExploitFixes.getLog().severe("Unable to create plugin config directory."); } if (!configFile.exists()) { configFile.createNewFile(); // Result can be ignored because this method only returns false if the file already exists, @@ -81,9 +63,7 @@ private void createFiles() { } catch (IOException e) { e.printStackTrace(); } - } - - private void loadConfig() { + // Load file try { config = ConfigFile.loadConfig(configFile); } catch (Exception e) { @@ -99,7 +79,25 @@ public void saveConfig() { } } - public void createSection(String title, String path) { + private void structureConfig() { + config.addDefault("config-version", 1.00); + createTitledSection("Language", "language"); + createTitledSection("General", "general"); + createTitledSection("Patches", "patches"); + createTitledSection("Preventions", "preventions"); + createTitledSection("Lag Preventions", "lag-preventions"); + createTitledSection("Dupe Preventions", "dupe-preventions"); + createTitledSection("Combat", "combat"); + createTitledSection("Illegals", "illegals"); + createTitledSection("Chunk Limits", "chunk-limits"); + createTitledSection("Bedrock", "bedrock"); + createTitledSection("Elytra", "elytra"); + createTitledSection("Chat", "chat"); + createTitledSection("Miscellaneous", "misc"); + createTitledSection("1b1t Options", "1b1t-options"); + } + + public void createTitledSection(String title, String path) { config.addSection(title); config.addDefault(path, null); }