<commit_before>package net.blay09.mods.eirairc.config;

import net.blay09.mods.eirairc.config.settings.BotSettings;
import net.blay09.mods.eirairc.config.settings.GeneralSettings;
import net.blay09.mods.eirairc.config.settings.ThemeSettings;
import net.blay09.mods.eirairc.util.Globals;
import net.blay09.mods.eirairc.util.I19n;
import net.blay09.mods.eirairc.util.Utils;
import net.minecraft.command.ICommandSender;
import net.minecraftforge.common.config.Configuration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Blay09 on 29.09.2014.
 */
public class SharedGlobalConfig {

	public static final String GENERAL = "general";
	public static final String NETWORK = "network";
	public static final String THEME = "theme";
	public static final String BOT = "bot";
	public static final String SETTINGS = "settings";

	public static Configuration thisConfig;

	// General
	public static String defaultChat = "Minecraft";
	public static boolean enablePlayerAliases = false;
	public static boolean enablePlayerColors = true;
	public static final List<String> colorBlacklist = new ArrayList<String>();
	public static boolean hidePlayerTags = false;
	public static boolean debugMode = false;
	public static boolean preventUserPing = false;

	// Network Settings
	public static String bindIP = "";
	public static boolean sslTrustAllCerts = false;
	public static String sslCustomTrustStore = "";
	public static boolean sslDisableDiffieHellman = true;
	public static String proxyHost = "";
	public static String proxyUsername = "";
	public static String proxyPassword = "";

	// Default Settings
	public static final ThemeSettings theme = new ThemeSettings(null);
	public static final BotSettings botSettings = new BotSettings(null);
	public static final GeneralSettings generalSettings = new GeneralSettings(null);

	public static void load(File configDir) {
		if(thisConfig == null) {
			thisConfig = new Configuration(new File(configDir, "shared.cfg"));
		}

		// General
		defaultChat = thisConfig.getString("defaultChat", GENERAL, defaultChat, I19n.format("eirairc:config.property.defaultChat.tooltip"), "eirairc:config.property.defaultChat");
		enablePlayerAliases = thisConfig.getBoolean("enablePlayerAliases", GENERAL, enablePlayerAliases, I19n.format("eirairc:config.property.enablePlayerAliases.tooltip"), "eirairc:config.property.enablePlayerAliases");
		enablePlayerColors = thisConfig.getBoolean("enablePlayerColors", GENERAL, enablePlayerColors, I19n.format("eirairc:config.property.enablePlayerColors.tooltip"), "eirairc:config.property.enablePlayerColors");
		String[] colorBlacklistArray = thisConfig.getStringList("colorBlacklist", GENERAL, Globals.DEFAULT_COLOR_BLACKLIST, I19n.format("eirairc:config.property.colorBlacklist.tooltip"), null, "eirairc:config.property.colorBlacklist");
		for(String entry : colorBlacklistArray) {
			colorBlacklist.add(entry);
		}
		hidePlayerTags = thisConfig.getBoolean("hidePlayerTags", GENERAL, hidePlayerTags, I19n.format("eirairc:config.property.hidePlayerTags.tooltip"), "eirairc:config.property.hidePlayerTags");
		preventUserPing = thisConfig.getBoolean("preventUserPing", GENERAL, preventUserPing, I19n.format("eirairc:config.property.preventUserPing.tooltip"), "eirairc:config.property.preventUserPing");
		debugMode = thisConfig.getBoolean("debugMode", GENERAL, debugMode, I19n.format("eirairc:config.property.debugMode.tooltip"), "eirairc:config.property.debugMode");

		// Network
		bindIP = thisConfig.getString("bindIP", NETWORK, bindIP, I19n.format("eirairc:config.property.bindIP.tooltip"), "eirairc:config.property.bindIP");
		sslTrustAllCerts = thisConfig.getBoolean("sslTrustAllCerts", NETWORK, sslTrustAllCerts, I19n.format("eirairc:config.property.sslTrustAllCerts.tooltip"), "eirairc:config.property.sslTrustAllCerts");
		sslCustomTrustStore = thisConfig.getString("sslCustomTrustStore", NETWORK, sslCustomTrustStore, I19n.format("eirairc:config.property.sslCustomTrustStore.tooltip"), "eirairc:config.property.sslCustomTrustStore");
		sslDisableDiffieHellman = thisConfig.getBoolean("sslDisableDiffieHellman", NETWORK, sslDisableDiffieHellman, I19n.format("eirairc:config.property.sslDisableDiffieHellman.tooltip"), "eirairc:config.property.sslDisableDiffieHellman");
		proxyHost = thisConfig.getString("proxyHost", NETWORK, proxyHost, I19n.format("eirairc:config.property.proxyHost.tooltip"), "eirairc:config.property.proxyHost");
		proxyUsername = thisConfig.getString("proxyUsername", NETWORK, proxyUsername, I19n.format("eirairc:config.property.proxyUsername.tooltip"), "eirairc:config.property.proxyUsername");
		proxyPassword = thisConfig.getString("proxyPassword", NETWORK, proxyPassword, I19n.format("eirairc:config.property.proxyPassword.tooltip"), "eirairc:config.property.proxyPassword");

		// Default Settings
		theme.load(thisConfig, THEME, true);
		botSettings.load(thisConfig, BOT, true);
		generalSettings.load(thisConfig, SETTINGS, true);

		save();
	}

	public static void save() {
		// Category Comments
		thisConfig.setCategoryComment(GENERAL, I19n.format("eirairc:config.category.general.tooltip"));
		thisConfig.setCategoryComment(NETWORK, I19n.format("eirairc:config.category.network.tooltip"));
		thisConfig.setCategoryComment(THEME, I19n.format("eirairc:config.category.theme.tooltip"));
		thisConfig.setCategoryComment(BOT, I19n.format("eirairc:config.category.bot.tooltip"));
		thisConfig.setCategoryComment(SETTINGS, I19n.format("eirairc:config.category.settings.tooltip"));

		// General
		thisConfig.get(GENERAL, "defaultChat", "", I19n.format("eirairc:config.property.defaultChat")).set(defaultChat);
		thisConfig.get(GENERAL, "enablePlayerAliases", false, I19n.format("eirairc:config.property.enablePlayerAliases.tooltip")).set(enablePlayerAliases);
		thisConfig.get(GENERAL, "enablePlayerColors", false, I19n.format("eirairc:config.property.enablePlayerColors.tooltip")).set(enablePlayerColors);
		thisConfig.get(GENERAL, "colorBlacklist", new String[0], I19n.format("eirairc:config.property.colorBlacklist.tooltip")).set(colorBlacklist.toArray(new String[colorBlacklist.size()]));
		thisConfig.get(GENERAL, "hidePlayerTags", false, I19n.format("eirairc:config.property.hidePlayerTags.tooltip")).set(hidePlayerTags);
		thisConfig.get(GENERAL, "preventUserPing", false, I19n.format("eirairc:config.property.preventUserPing.tooltip")).set(preventUserPing);
		thisConfig.get(GENERAL, "debugMode", false, I19n.format("eirairc:config.property.debugMode.tooltip")).set(debugMode);

		// Network
		thisConfig.get(NETWORK, "bindIP", "", I19n.format("eirairc:config.property.bindIP.tooltip")).set(bindIP);
		thisConfig.get(NETWORK, "sslTrustAllCerts", false, I19n.format("eirairc:config.property.sslTrustAllCerts.tooltip")).set(sslTrustAllCerts);
		thisConfig.get(NETWORK, "sslCustomTrustStore", I19n.format("eirairc:config.property.sslCustomTrustStore.tooltip")).set(sslCustomTrustStore);
		thisConfig.get(NETWORK, "sslDisableDiffieHellman", false, I19n.format("eirairc:config.property.sslDisableDiffieHellman.tooltip")).set(sslDisableDiffieHellman);
		thisConfig.get(NETWORK, "proxyHost", "", I19n.format("eirairc:config.property.proxyHost.tooltip")).set(proxyHost);
		thisConfig.get(NETWORK, "proxyUsername", "", I19n.format("eirairc:config.property.proxyUsername.tooltip")).set(proxyUsername);
		thisConfig.get(NETWORK, "proxyPassword", "", I19n.format("eirairc:config.property.proxyPassword.tooltip")).set(proxyPassword);

		// Default Settings
		theme.save(thisConfig, THEME);
		botSettings.save(thisConfig, BOT);
		generalSettings.save(thisConfig, SETTINGS);

		thisConfig.save();
	}

	public static void loadLegacy(File configDir, Configuration legacyConfig) {
		thisConfig = new Configuration(new File(configDir, "shared.cfg"));

		// General
		enablePlayerAliases = legacyConfig.getBoolean("enableAliases", "serveronly", enablePlayerAliases, "");
		enablePlayerColors = legacyConfig.getBoolean("enableNameColors", "display", enablePlayerColors, "");
		String[] colorBlacklistArray = legacyConfig.getStringList("colorBlackList", "serveronly", new String[0], "");
		for(String entry : colorBlacklistArray) {
			colorBlacklist.add(Utils.unquote(entry));
		}
		debugMode = legacyConfig.getBoolean("debugMode", "global", debugMode, "");
		hidePlayerTags = legacyConfig.getBoolean("hidePlayerTags", "display", hidePlayerTags, "");

		// Network
		sslTrustAllCerts = legacyConfig.getBoolean("sslTrustAllCerts", "network", sslTrustAllCerts, "");
		sslCustomTrustStore = Utils.unquote(legacyConfig.getString("sslCustomTrustStore", "network", sslCustomTrustStore, ""));
		sslDisableDiffieHellman = legacyConfig.getBoolean("sslDisableDiffieHellman", "network", sslDisableDiffieHellman, "");
		proxyHost = Utils.unquote(legacyConfig.getString("proxyHost", "network", proxyHost, ""));
		proxyUsername = Utils.unquote(legacyConfig.getString("proxyUsername", "network", proxyUsername, ""));
		proxyPassword = Utils.unquote(legacyConfig.getString("proxyPassword", "network", proxyPassword, ""));

		// Theme
		theme.load(thisConfig, THEME, true);
		theme.loadLegacy(legacyConfig, null);
		botSettings.load(thisConfig, BOT, true);
		botSettings.loadLegacy(legacyConfig, null);
		generalSettings.load(thisConfig, SETTINGS, true);
		generalSettings.loadLegacy(legacyConfig, null);

		save();
	}<commit_msg>Clear colorBlacklist before adding entries<commit_after>package net.blay09.mods.eirairc.config;

import net.blay09.mods.eirairc.config.settings.BotSettings;
import net.blay09.mods.eirairc.config.settings.GeneralSettings;
import net.blay09.mods.eirairc.config.settings.ThemeSettings;
import net.blay09.mods.eirairc.util.Globals;
import net.blay09.mods.eirairc.util.I19n;
import net.blay09.mods.eirairc.util.Utils;
import net.minecraft.command.ICommandSender;
import net.minecraftforge.common.config.Configuration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Blay09 on 29.09.2014.
 */
public class SharedGlobalConfig {

	public static final String GENERAL = "general";
	public static final String NETWORK = "network";
	public static final String THEME = "theme";
	public static final String BOT = "bot";
	public static final String SETTINGS = "settings";

	public static Configuration thisConfig;

	// General
	public static String defaultChat = "Minecraft";
	public static boolean enablePlayerAliases = false;
	public static boolean enablePlayerColors = true;
	public static final List<String> colorBlacklist = new ArrayList<String>();
	public static boolean hidePlayerTags = false;
	public static boolean debugMode = false;
	public static boolean preventUserPing = false;

	// Network Settings
	public static String bindIP = "";
	public static boolean sslTrustAllCerts = false;
	public static String sslCustomTrustStore = "";
	public static boolean sslDisableDiffieHellman = true;
	public static String proxyHost = "";
	public static String proxyUsername = "";
	public static String proxyPassword = "";

	// Default Settings
	public static final ThemeSettings theme = new ThemeSettings(null);
	public static final BotSettings botSettings = new BotSettings(null);
	public static final GeneralSettings generalSettings = new GeneralSettings(null);

	public static void load(File configDir) {
		if(thisConfig == null) {
			thisConfig = new Configuration(new File(configDir, "shared.cfg"));
		}

		// General
		defaultChat = thisConfig.getString("defaultChat", GENERAL, defaultChat, I19n.format("eirairc:config.property.defaultChat.tooltip"), "eirairc:config.property.defaultChat");
		enablePlayerAliases = thisConfig.getBoolean("enablePlayerAliases", GENERAL, enablePlayerAliases, I19n.format("eirairc:config.property.enablePlayerAliases.tooltip"), "eirairc:config.property.enablePlayerAliases");
		enablePlayerColors = thisConfig.getBoolean("enablePlayerColors", GENERAL, enablePlayerColors, I19n.format("eirairc:config.property.enablePlayerColors.tooltip"), "eirairc:config.property.enablePlayerColors");
		String[] colorBlacklistArray = thisConfig.getStringList("colorBlacklist", GENERAL, Globals.DEFAULT_COLOR_BLACKLIST, I19n.format("eirairc:config.property.colorBlacklist.tooltip"), null, "eirairc:config.property.colorBlacklist");
		colorBlacklist.clear();
		for(String entry : colorBlacklistArray) {
			colorBlacklist.add(entry);
		}
		hidePlayerTags = thisConfig.getBoolean("hidePlayerTags", GENERAL, hidePlayerTags, I19n.format("eirairc:config.property.hidePlayerTags.tooltip"), "eirairc:config.property.hidePlayerTags");
		preventUserPing = thisConfig.getBoolean("preventUserPing", GENERAL, preventUserPing, I19n.format("eirairc:config.property.preventUserPing.tooltip"), "eirairc:config.property.preventUserPing");
		debugMode = thisConfig.getBoolean("debugMode", GENERAL, debugMode, I19n.format("eirairc:config.property.debugMode.tooltip"), "eirairc:config.property.debugMode");

		// Network
		bindIP = thisConfig.getString("bindIP", NETWORK, bindIP, I19n.format("eirairc:config.property.bindIP.tooltip"), "eirairc:config.property.bindIP");
		sslTrustAllCerts = thisConfig.getBoolean("sslTrustAllCerts", NETWORK, sslTrustAllCerts, I19n.format("eirairc:config.property.sslTrustAllCerts.tooltip"), "eirairc:config.property.sslTrustAllCerts");
		sslCustomTrustStore = thisConfig.getString("sslCustomTrustStore", NETWORK, sslCustomTrustStore, I19n.format("eirairc:config.property.sslCustomTrustStore.tooltip"), "eirairc:config.property.sslCustomTrustStore");
		sslDisableDiffieHellman = thisConfig.getBoolean("sslDisableDiffieHellman", NETWORK, sslDisableDiffieHellman, I19n.format("eirairc:config.property.sslDisableDiffieHellman.tooltip"), "eirairc:config.property.sslDisableDiffieHellman");
		proxyHost = thisConfig.getString("proxyHost", NETWORK, proxyHost, I19n.format("eirairc:config.property.proxyHost.tooltip"), "eirairc:config.property.proxyHost");
		proxyUsername = thisConfig.getString("proxyUsername", NETWORK, proxyUsername, I19n.format("eirairc:config.property.proxyUsername.tooltip"), "eirairc:config.property.proxyUsername");
		proxyPassword = thisConfig.getString("proxyPassword", NETWORK, proxyPassword, I19n.format("eirairc:config.property.proxyPassword.tooltip"), "eirairc:config.property.proxyPassword");

		// Default Settings
		theme.load(thisConfig, THEME, true);
		botSettings.load(thisConfig, BOT, true);
		generalSettings.load(thisConfig, SETTINGS, true);

		save();
	}

	public static void save() {
		// Category Comments
		thisConfig.setCategoryComment(GENERAL, I19n.format("eirairc:config.category.general.tooltip"));
		thisConfig.setCategoryComment(NETWORK, I19n.format("eirairc:config.category.network.tooltip"));
		thisConfig.setCategoryComment(THEME, I19n.format("eirairc:config.category.theme.tooltip"));
		thisConfig.setCategoryComment(BOT, I19n.format("eirairc:config.category.bot.tooltip"));
		thisConfig.setCategoryComment(SETTINGS, I19n.format("eirairc:config.category.settings.tooltip"));

		// General
		thisConfig.get(GENERAL, "defaultChat", "", I19n.format("eirairc:config.property.defaultChat")).set(defaultChat);
		thisConfig.get(GENERAL, "enablePlayerAliases", false, I19n.format("eirairc:config.property.enablePlayerAliases.tooltip")).set(enablePlayerAliases);
		thisConfig.get(GENERAL, "enablePlayerColors", false, I19n.format("eirairc:config.property.enablePlayerColors.tooltip")).set(enablePlayerColors);
		thisConfig.get(GENERAL, "colorBlacklist", new String[0], I19n.format("eirairc:config.property.colorBlacklist.tooltip")).set(colorBlacklist.toArray(new String[colorBlacklist.size()]));
		thisConfig.get(GENERAL, "hidePlayerTags", false, I19n.format("eirairc:config.property.hidePlayerTags.tooltip")).set(hidePlayerTags);
		thisConfig.get(GENERAL, "preventUserPing", false, I19n.format("eirairc:config.property.preventUserPing.tooltip")).set(preventUserPing);
		thisConfig.get(GENERAL, "debugMode", false, I19n.format("eirairc:config.property.debugMode.tooltip")).set(debugMode);

		// Network
		thisConfig.get(NETWORK, "bindIP", "", I19n.format("eirairc:config.property.bindIP.tooltip")).set(bindIP);
		thisConfig.get(NETWORK, "sslTrustAllCerts", false, I19n.format("eirairc:config.property.sslTrustAllCerts.tooltip")).set(sslTrustAllCerts);
		thisConfig.get(NETWORK, "sslCustomTrustStore", I19n.format("eirairc:config.property.sslCustomTrustStore.tooltip")).set(sslCustomTrustStore);
		thisConfig.get(NETWORK, "sslDisableDiffieHellman", false, I19n.format("eirairc:config.property.sslDisableDiffieHellman.tooltip")).set(sslDisableDiffieHellman);
		thisConfig.get(NETWORK, "proxyHost", "", I19n.format("eirairc:config.property.proxyHost.tooltip")).set(proxyHost);
		thisConfig.get(NETWORK, "proxyUsername", "", I19n.format("eirairc:config.property.proxyUsername.tooltip")).set(proxyUsername);
		thisConfig.get(NETWORK, "proxyPassword", "", I19n.format("eirairc:config.property.proxyPassword.tooltip")).set(proxyPassword);

		// Default Settings
		theme.save(thisConfig, THEME);
		botSettings.save(thisConfig, BOT);
		generalSettings.save(thisConfig, SETTINGS);

		thisConfig.save();
	}

	public static void loadLegacy(File configDir, Configuration legacyConfig) {
		thisConfig = new Configuration(new File(configDir, "shared.cfg"));

		// General
		enablePlayerAliases = legacyConfig.getBoolean("enableAliases", "serveronly", enablePlayerAliases, "");
		enablePlayerColors = legacyConfig.getBoolean("enableNameColors", "display", enablePlayerColors, "");
		String[] colorBlacklistArray = legacyConfig.getStringList("colorBlackList", "serveronly", new String[0], "");
		colorBlacklist.clear();
		for(String entry : colorBlacklistArray) {
			colorBlacklist.add(Utils.unquote(entry));
		}
		debugMode = legacyConfig.getBoolean("debugMode", "global", debugMode, "");
		hidePlayerTags = legacyConfig.getBoolean("hidePlayerTags", "display", hidePlayerTags, "");

		// Network
		sslTrustAllCerts = legacyConfig.getBoolean("sslTrustAllCerts", "network", sslTrustAllCerts, "");
		sslCustomTrustStore = Utils.unquote(legacyConfig.getString("sslCustomTrustStore", "network", sslCustomTrustStore, ""));
		sslDisableDiffieHellman = legacyConfig.getBoolean("sslDisableDiffieHellman", "network", sslDisableDiffieHellman, "");
		proxyHost = Utils.unquote(legacyConfig.getString("proxyHost", "network", proxyHost, ""));
		proxyUsername = Utils.unquote(legacyConfig.getString("proxyUsername", "network", proxyUsername, ""));
		proxyPassword = Utils.unquote(legacyConfig.getString("proxyPassword", "network", proxyPassword, ""));

		// Theme
		theme.load(thisConfig, THEME, true);
		theme.loadLegacy(legacyConfig, null);
		botSettings.load(thisConfig, BOT, true);
		botSettings.loadLegacy(legacyConfig, null);
		generalSettings.load(thisConfig, SETTINGS, true);
		generalSettings.loadLegacy(legacyConfig, null);

		save();
	}
{'fraction_non_alphanumeric': 0.13078030828310844, 'fraction_numerical': 0.01002720145074404, 'mean_word_length': 7.652514997692663, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3316646', 'n_tokens_mistral': 6125, 'n_tokens_neox': 5775, 'n_words': 876}