private void _loadPlugins() { var pluginsDirectory = new DirectoryInfo(_pluginsPath); if (!pluginsDirectory.Exists) { pluginsDirectory.Create(); } foreach (var file in pluginsDirectory.GetFiles("*.dll")) { var assembly = Assembly.LoadFrom(file.FullName); foreach (var type in assembly.GetTypes()) { if (!type.IsSubclassOf(typeof(IPlugin)) || type.IsAbstract) { continue; } Longship.Log($"Loading plugin {file.Name}..."); try { _plugins[type] = new LoadedPlugin() { Plugin = type.InvokeMember( null, BindingFlags.CreateInstance, null, null, null) as IPlugin, Name = file.Name }; } catch (Exception e) { Longship.LogError($"Can't load plugin {file.Name}."); Longship.LogException(e); } } } }
public bool DisablePlugin <T>() where T : IPlugin { if (!_plugins.TryGetValue(typeof(T), out var value)) { return(false); } Longship.Log($"Disabling {value.Name}..."); try { Longship.Instance.EventManager.ClearListeners(value.Plugin); Longship.Instance.CommandsManager.ClearListeners(value.Plugin); value.Plugin.OnDisable(); } catch (Exception e) { Longship.LogError($"Error while disabling plugin {value.Name}"); Longship.LogException(e); } Longship.Log($"{value.Name} disabled."); return(false); }