namespace Artemis.Core
{
///
/// An optional entry point for your plugin
///
public abstract class PluginBootstrapper
{
private Plugin? _plugin;
///
/// Called when the plugin is loaded
///
///
public virtual void OnPluginLoaded(Plugin plugin)
{
}
///
/// Called when the plugin is activated
///
/// The plugin instance of your plugin
public virtual void OnPluginEnabled(Plugin plugin)
{
}
///
/// Called when the plugin is deactivated or when Artemis shuts down
///
/// The plugin instance of your plugin
public virtual void OnPluginDisabled(Plugin plugin)
{
}
///
/// Adds the provided prerequisite to the plugin.
///
/// The prerequisite to add
public void AddPluginPrerequisite(PluginPrerequisite prerequisite)
{
// TODO: We can keep track of them and add them after load, same goes for the others
if (_plugin == null)
throw new ArtemisPluginException("Cannot add plugin prerequisites before the plugin is loaded");
if (!_plugin.Info.Prerequisites.Contains(prerequisite))
_plugin.Info.Prerequisites.Add(prerequisite);
}
///
/// Removes the provided prerequisite from the plugin.
///
/// The prerequisite to remove
///
/// is successfully removed; otherwise . This method also returns
/// if the prerequisite was not found.
///
public bool RemovePluginPrerequisite(PluginPrerequisite prerequisite)
{
if (_plugin == null)
throw new ArtemisPluginException("Cannot add plugin prerequisites before the plugin is loaded");
return _plugin.Info.Prerequisites.Remove(prerequisite);
}
///
/// Adds the provided prerequisite to the feature of type .
///
/// The prerequisite to add
public void AddFeaturePrerequisite(PluginPrerequisite prerequisite) where T : PluginFeature
{
if (_plugin == null)
throw new ArtemisPluginException("Cannot add feature prerequisites before the plugin is loaded");
PluginFeatureInfo info = _plugin.GetFeatureInfo();
if (!info.Prerequisites.Contains(prerequisite))
info.Prerequisites.Add(prerequisite);
}
///
/// Removes the provided prerequisite from the feature of type .
///
/// The prerequisite to remove
///
/// is successfully removed; otherwise . This method also returns
/// if the prerequisite was not found.
///
public bool RemoveFeaturePrerequisite(PluginPrerequisite prerequisite) where T : PluginFeature
{
if (_plugin == null)
throw new ArtemisPluginException("Cannot add feature prerequisites before the plugin is loaded");
return _plugin.GetFeatureInfo().Prerequisites.Remove(prerequisite);
}
internal void InternalOnPluginLoaded(Plugin plugin)
{
_plugin = plugin;
OnPluginLoaded(plugin);
}
}
}