public static void Initialise() { plugin = SCPDiscordPlugin.instance; // Save default language files SaveDefaultLanguages(); // Read primary language file plugin.Info("Loading primary language file..."); try { LoadLanguageFile(Config.settings.language, false); } catch (Exception e) { if (e is DirectoryNotFoundException) { plugin.Error("Language directory not found."); } else if (e is UnauthorizedAccessException) { plugin.Error("Primary language file access denied."); } else if (e is FileNotFoundException) { plugin.Error("'" + Config.settings.language + ".yml' was not found."); } else if (e is JsonReaderException || e is YamlException) { plugin.Error("'" + Config.settings.language + ".yml' formatting error."); } plugin.Error("Error reading language file '" + Config.settings.language + ".yml'. Attempting to initialize backup system..."); plugin.Debug(e.ToString()); } // Read backup language file if not the same as the primary if (Config.settings.language != "english") { plugin.Info("Loading backup language file..."); try { LoadLanguageFile("english", true); } catch (Exception e) { if (e is DirectoryNotFoundException) { plugin.Error("Language directory not found."); } else if (e is UnauthorizedAccessException) { plugin.Error("Backup language file access denied."); } else if (e is FileNotFoundException) { plugin.Error("'" + Config.settings.language + ".yml' was not found."); } else if (e is JsonReaderException || e is YamlException) { plugin.Error("'" + Config.settings.language + ".yml' formatting error."); } plugin.Error("Error reading backup language file 'english.yml'."); plugin.Debug(e.ToString()); } } if (primary == null && backup == null) { plugin.Error("NO LANGUAGE FILE LOADED! DEACTIVATING SCPDISCORD."); plugin.Disable(); } ValidateLanguageStrings(); }
public Language(SCPDiscordPlugin plugin) { this.plugin = plugin; plugin.language = this; Thread.Sleep(2500); // Save default language files SaveDefaultLanguages(); // Read primary language file plugin.Info("Loading primary language file..."); try { ReadLanguage(plugin.GetConfigString("discord_language"), false); } catch (Exception e) { if (e is DirectoryNotFoundException) { plugin.Error("Language directory not found."); } else if (e is UnauthorizedAccessException) { plugin.Error("Primary language file access denied."); } else if (e is FileNotFoundException) { plugin.Error("'" + plugin.GetConfigString("discord_language") + ".yml' was not found."); } else if (e is JsonReaderException || e is YamlException) { plugin.Error("'" + plugin.GetConfigString("discord_language") + ".yml' formatting error."); } plugin.Error("Error reading language file '" + plugin.GetConfigString("discord_language") + ".yml'. Attempting to initialize backup system..."); plugin.Debug(e.ToString()); } // Read backup language file if not the same as the primary if (plugin.GetConfigString("discord_language") != "english") { plugin.Info("Loading backup language file..."); try { ReadLanguage("english", true); } catch (Exception e) { if (e is DirectoryNotFoundException) { plugin.Error("Language directory not found."); } else if (e is UnauthorizedAccessException) { plugin.Error("Backup language file access denied."); } else if (e is FileNotFoundException) { plugin.Error("'" + plugin.GetConfigString("discord_language") + ".yml' was not found."); } else if (e is JsonReaderException || e is YamlException) { plugin.Error("'" + plugin.GetConfigString("discord_language") + ".yml' formatting error."); } plugin.Error("Error reading backup language file 'english.yml'."); plugin.Debug(e.ToString()); } } if (primary == null && backup == null) { plugin.Error("NO LANGUAGE FILE LOADED! DEACTIVATING SCPDISCORD."); plugin.Disable(); } //Runs until the server has connected once Thread connectionThread = new Thread(new ThreadStart(() => new ConnectToBot(plugin))); connectionThread.Start(); //Runs the listener Thread botListenerThread = new Thread(new ThreadStart(() => new BotListener(plugin))); botListenerThread.Start(); //Keeps running to auto-reconnect if needed Thread watchdogThread = new Thread(new ThreadStart(() => new StartConnectionWatchdog(plugin))); watchdogThread.Start(); }