Beispiel #1
0
        /// <summary>
        /// Unloads all plugins.
        /// </summary>
        public static void UnloadAll()
        {
            if (IsLocked)
            {
                throw new NotSupportedException();
            }

            IsLocked = true;
            foreach (var key in Plugins.Keys)
            {
                if (Plugins.TryGetValue(key, out var plugin) && plugin.LoadStatus == PluginContainer.Status.Loaded)
                {
                    plugin.LoadStatus = PluginContainer.Status.Unloaded;
                    try
                    {
                        plugin.Plugin.OnUnloadPlugin();
                        (plugin as IDisposable)?.Dispose();
                    }
                    catch (HaltPluginException)
                    {
                    }
                    catch (Exception e)
                    {
                        plugin.SetFailState(e);
                    }

                    AdminCommandManager.UnloadPlugin(plugin.Plugin);
                    ConVarManager.UnloadPlugin(plugin.Plugin);
                    plugin.Plugin = null;
                }
            }

            Plugins.Clear();
            IsLocked = false;
            AdminManager.ReloadAdmins();
        }
Beispiel #2
0
        /// <summary>
        /// Unloads a plugin.
        /// </summary>
        /// <param name="name">The name of the plugin.</param>
        public static void Unload(string name)
        {
            if (IsLocked)
            {
                throw new NotSupportedException();
            }

            var key = NameToKey(name);

            if (Plugins.TryGetValue(key, out var plugin))
            {
                plugin.LoadStatus = PluginContainer.Status.Unloaded;
                try
                {
                    IsLocked = true;
                    plugin.Plugin.OnUnloadPlugin();
                    (plugin as IDisposable)?.Dispose();
                    IsLocked = false;
                }
                catch (HaltPluginException)
                {
                }
                catch (Exception e)
                {
                    plugin.SetFailState(e);
                }

                Language.UnloadPlugin(plugin.Plugin);
                AdminCommandManager.UnloadPlugin(plugin.Plugin);
                ConVarManager.UnloadPlugin(plugin.Plugin);
                plugin.Plugin = null;
                AdminManager.ReloadAdmins();

                Plugins.Remove(key);
            }
        }