Skip to content

Commit

Permalink
cleanup config
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jul 9, 2023
1 parent 0f44d33 commit b94f3eb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,70 +19,51 @@ 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", "<gray>SERVER: <gold>%message%"));
this.sayCommandFormat = MiniMessage.miniMessage().deserialize(getString("misc.say-command-format", "<gray>SERVER: <gold>%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 <phrase> 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,
}
} catch (IOException e) {
e.printStackTrace();
}
}

private void loadConfig() {
// Load file
try {
config = ConfigFile.loadConfig(configFile);
} catch (Exception e) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;

public class Config {

Expand All @@ -18,72 +17,53 @@ 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 <phrase> 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,
}
} catch (IOException e) {
e.printStackTrace();
}
}

private void loadConfig() {
// Load file
try {
config = ConfigFile.loadConfig(configFile);
} catch (Exception e) {
Expand All @@ -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);
}
Expand Down

0 comments on commit b94f3eb

Please sign in to comment.