Ejemplo n.º 1
0
 private static void OnPluginLoad(PluginLoadedArgs e)
 {
     OnPluginLoaded?.Invoke(e);
 }
Ejemplo n.º 2
0
 internal static void RunPluginLoaded(PointBlankPlugin plugin) => OnPluginLoaded?.Invoke(plugin);
Ejemplo n.º 3
0
        public void LoadPlugins()
        {
            MakeSuperSureCriticalPluginsAreEnabled();
            PurgeDuplicateEnabledPlugins();

            Log.Write(Log.Type.PLUGIN, "Reloading plugins for guild " + _parentHandler.GetGuild().Name);
            OnPrePluginsLoaded?.Invoke();

            Filter <string> filter = new Filter <string>(x => _enabledPlugins.GetValue().Any(y => NameMatches(x, y)), x => ContainsDependencies(_enabledPlugins.GetValue(), x));

            string[] toLoad = PluginLoader.GetPlugins().Select(x => Plugin.GetFullName(x)).ToArray();
            toLoad = filter.FilterModules(toLoad).ToArray();

            Log.Write(Log.Type.PLUGIN, "Loading plugins: " + string.Join(',', toLoad));

            foreach (string name in toLoad)
            {
                Type pluginType = PluginLoader.GetPlugin(name);
                if (pluginType == null)
                {
                    Log.Write(Log.Type.WARNING, $"Attempted to instantiate unloaded/unknown plugin type {name}");
                }
                else
                {
                    Log.Plugin($"Instantiating plugin '{Plugin.GetVersionedFullName(pluginType)}'.");
                    IPlugin plugin = AssemblyLoader.Instantiate <IPlugin>(pluginType);
                    _activePlugins.Add(plugin);
                }
            }

            bool initError = false;

            foreach (IPlugin plugin in _activePlugins)
            {
                try
                {
                    Log.Write(Log.Type.PLUGIN, "Pre-initializing plugin " + Plugin.GetVersionedFullName(plugin.GetType()));
                    plugin.PreInitialize(_parentHandler);
                } catch (Exception exc)
                {
                    ReportInitError("pre-initialization", new PluginInitializationException(Plugin.GetName(plugin.GetType()), exc), plugin, ref initError);
                }
            }

            foreach (IPlugin plugin in _activePlugins)
            {
                try
                {
                    Log.Write(Log.Type.PLUGIN, "Initializing plugin " + Plugin.GetVersionedFullName(plugin.GetType()));
                    plugin.Initialize();
                }
                catch (Exception exc)
                {
                    ReportInitError("initialization", new PluginInitializationException(Plugin.GetName(plugin.GetType()), exc), plugin, ref initError);
                }
            }

            foreach (IPlugin plugin in _activePlugins)
            {
                try
                {
                    Log.Write(Log.Type.PLUGIN, "Post-initializing plugin " + Plugin.GetVersionedFullName(plugin.GetType()));
                    plugin.PostInitialize();
                }
                catch (Exception exc)
                {
                    ReportInitError("post-initialization", new PluginInitializationException(Plugin.GetName(plugin.GetType()), exc), plugin, ref initError);
                }

                OnPluginLoaded?.Invoke(plugin);
            }

            if (initError)
            {
                ReloadPlugins();
            }

            OnPluginsLoaded?.Invoke();
        }