public void Reload() { plugin.SetUpFileSystem(); syncedPlayers = JArray.Parse(File.ReadAllText(FileManager.GetAppFolder() + "SCPDiscord/rolesync.json")).ToDictionary(k => ((JObject)k).Properties().First().Name, v => v.Values().First().Value <string>()); }
internal static void Reload(SCPDiscord plugin) { ready = false; plugin.SetUpFileSystem(); // Reads file contents into FileStream FileStream stream = File.OpenRead(FileManager.GetAppFolder() + "SCPDiscord/" + plugin.GetConfigString("scpdiscord_config")); // Converts the FileStream into a YAML Dictionary object IDeserializer deserializer = new DeserializerBuilder().Build(); object yamlObject = deserializer.Deserialize(new StreamReader(stream)); // Converts the YAML Dictionary into JSON String ISerializer serializer = new SerializerBuilder() .JsonCompatible() .Build(); string jsonString = serializer.Serialize(yamlObject); JObject json = JObject.Parse(jsonString); // Reads the configvalidation node first as it is used for reading the others try { configBools["settings.configvalidation"] = json.SelectToken("settings.configvalidation").Value <bool>(); } catch (ArgumentNullException) { if (GetBool("settings.configvalidation")) { plugin.Warn("Config bool 'settings.configvalidation' not found, using default value: true"); } } // Read config strings foreach (KeyValuePair <string, string> node in configStrings.ToList()) { try { configStrings[node.Key] = json.SelectToken(node.Key).Value <string>(); } catch (ArgumentNullException) { if (GetBool("settings.configvalidation")) { plugin.Warn("Config string '" + node.Key + "' not found, using default value: \"" + node.Value + "\""); } } } // Read config ints foreach (KeyValuePair <string, int> node in configInts.ToList()) { try { configInts[node.Key] = json.SelectToken(node.Key).Value <int>(); } catch (ArgumentNullException) { if (GetBool("settings.configvalidation")) { plugin.Warn("Config int '" + node.Key + "' not found, using default value: \"" + node.Value + "\""); } } } // Read config bools foreach (KeyValuePair <string, bool> node in configBools.ToList().Where(kvm => !(kvm.Key == "settings.configvalidation"))) { try { configBools[node.Key] = json.SelectToken(node.Key).Value <bool>(); } catch (ArgumentNullException) { if (GetBool("settings.configvalidation")) { plugin.Warn("Config bool '" + node.Key + "' not found, using default value: " + node.Value); } } } // Read config arrays foreach (KeyValuePair <string, string[]> node in configArrays.ToList()) { try { configArrays[node.Key] = json.SelectToken(node.Key).Value <JArray>().Values <string>().ToArray(); } catch (ArgumentNullException) { if (GetBool("settings.configvalidation")) { plugin.Warn("Config array '" + node.Key + "' not found, using default value: []"); } } } // Read config dictionaries foreach (KeyValuePair <string, Dictionary <string, string> > node in configDicts.ToList()) { try { configDicts[node.Key] = json.SelectToken(node.Key).Value <JArray>().ToDictionary(k => ((JObject)k).Properties().First().Name, v => v.Values().First().Value <string>()); } catch (ArgumentNullException) { if (GetBool("settings.configvalidation")) { plugin.Warn("Config dictionary '" + node.Key + "' not found, using default value: []"); } } } if (GetBool("settings.configvalidation")) { ValidateConfig(plugin); } ready = true; }
public void Reload() { plugin.SetUpFileSystem(); syncedPlayers = JArray.Parse(File.ReadAllText(FileManager.GetAppFolder(plugin.GetConfigBool("scpdiscord_rolesync_global")) + "SCPDiscord/rolesync.json")).ToDictionary(k => ((JObject)k).Properties().First().Name, v => v.Values().First().Value <string>()); plugin.Info("Successfully loaded config '" + FileManager.GetAppFolder(plugin.GetConfigBool("scpdiscord_rolesync_global")) + "SCPDiscord/rolesync.json'."); }