Esempio n. 1
0
        public void RegisterConfig(Plugin plugin, Config.ConfigSetting setting)
        {
            if (!settings.ContainsKey(plugin))
            {
                PluginManager.Manager.Logger.Error("CONFIG_MANAGER", "Trying to register a config setting before the plugin has registered with Config Manager");
            }
            else if (!CheckTypeMatch(setting))
            {
                PluginManager.Manager.Logger.Error("CONFIG_MANAGER", "Trying to register a config setting \"" + setting.Key + "\" with a mismatched default and setting type (Expected \"" + GetTypeString(setting.ConfigValueType) + "\", got \"" + (setting.Default != null ? setting.Default.GetType().ToString() : "null") + "\" instead)");
            }
            else
            {
                Dictionary <string, Config.ConfigSetting> pluginSettings = settings[plugin];

                // Warn if registering an existing config as the primary user
                if (setting.PrimaryUser)
                {
                    if (primary_settings_map.ContainsKey(setting.Key))
                    {
                        if (primary_settings_map[setting.Key] != plugin)
                        {
                            PluginManager.Manager.Logger.Warn("CONFIG_MANAGER", plugin.ToString() + " is trying to register as a primary user of config setting " + setting.Key + " this may cause some weird behaviour");
                        }
                    }
                    else
                    {
                        PluginManager.Manager.Logger.Debug("CONFIG_MANAGER", "Adding primary config setting " + setting.Key + " for plugin " + plugin.Details.id);
                        primary_settings_map.Add(setting.Key, plugin);
                    }
                }
                else
                {
                    if (!secondary_settings_map.ContainsKey(setting.Key))
                    {
                        secondary_settings_map.Add(setting.Key, new List <Plugin>());
                    }

                    secondary_settings_map[setting.Key].Add(plugin);
                }

                if (!pluginSettings.ContainsKey(setting.Key))
                {
                    pluginSettings.Add(setting.Key, setting);
                }
                else
                {
                    PluginManager.Manager.Logger.Warn("CONFIG_MANAGER", plugin.ToString() + " is trying to register a duplicate setting: " + setting.Key);
                }
            }
        }
        public bool RegisterConfig(Plugin plugin, Config.ConfigSetting setting)
        {
            if (!settings.ContainsKey(plugin))
            {
                PluginManager.Manager.Logger.Error("CONFIG_MANAGER", "Trying to register a config setting before the plugin has registered with Config Manager");
                return(false);
            }

            Dictionary <string, Config.ConfigSetting> pluginSettings = settings[plugin];

            // Warn if registering an existing config as the primary user
            if (setting.PrimaryUser)
            {
                if (primary_settings_map.ContainsKey(setting.Key))
                {
                    if (primary_settings_map[setting.Key] != plugin)
                    {
                        PluginManager.Manager.Logger.Warn("CONFIG_MANAGER", plugin.ToString() + " is trying to register as a primary user of config setting " + setting.Key + " this may cause some weird behaviour");
                    }
                }
                else
                {
                    PluginManager.Manager.Logger.Debug("CONFIG_MANAGER", "Adding primary config setting " + setting.Key + " for plugin " + plugin.Details.id);
                    primary_settings_map.Add(setting.Key, plugin);
                }
            }
            else
            {
                if (!secondary_settings_map.ContainsKey(setting.Key))
                {
                    secondary_settings_map.Add(setting.Key, new List <Plugin>());
                }

                secondary_settings_map[setting.Key].Add(plugin);
            }

            if (!pluginSettings.ContainsKey(setting.Key))
            {
                pluginSettings.Add(setting.Key, setting);
            }
            else
            {
                PluginManager.Manager.Logger.Warn("CONFIG_MANAGER", plugin.ToString() + " is trying to register a duplicate setting: " + setting.Key);
            }

            return(true);
        }