private Create ( Type type, DarkRift.Server.PluginBaseLoadData loadData, DarkRift.Server.PluginLoadData backupLoadData = null ) : T | ||
type | Type | The type to load. |
loadData | DarkRift.Server.PluginBaseLoadData | The data to load into the plugin. |
backupLoadData | DarkRift.Server.PluginLoadData | The backup load data to try for backwards compatability. |
return | T |
internal T Create<T>(Type type, PluginBaseLoadData loadData, PluginLoadData backupLoadData = null) where T : PluginBase
{
//Create an instance of the plugin
T plugin;
try
{
plugin = (T)Activator.CreateInstance(type, loadData);
}
catch (MissingMethodException)
{
//Failed, perhaps using backup PluginLoadData would help?
if (backupLoadData != null)
{
plugin = (T)Activator.CreateInstance(type, backupLoadData);
logger.Warning($"Plugin {type.Name} was loaded using a PluginLoadData object instead of the desired {loadData.GetType().Name}. Consider replacing the constructor with one accepting a " + loadData.GetType().Name + " object instead.");
}
else
{
throw;
}
}
//Log creation
if (!plugin.Hidden)
logger.Trace($"Created plugin '{type.Name}'.");
return plugin;
}
PluginFactory::Create ( string type, DarkRift.Server.PluginBaseLoadData loadData, DarkRift.Server.PluginLoadData backupLoadData = null ) : T |
/// <summary> /// Load the plugin given. /// </summary> /// <param name="name">The name of the plugin instance.</param> /// <param name="type">The plugin type to load.</param> /// <param name="pluginLoadData">The data for this plugin.</param> /// <param name="backupLoadData">The data for this plugin if the first fails.</param> /// <param name="createResourceDirectory">Whether to create a resource directory or not.</param> protected virtual T LoadPlugin(string name, Type type, PluginBaseLoadData pluginLoadData, PluginLoadData backupLoadData, bool createResourceDirectory) { //Ensure the resource directory is present if (createResourceDirectory) { dataManager.CreateResourceDirectory(type.Name); } T plugin = pluginFactory.Create <T>(type, pluginLoadData); plugins.Add(name, plugin); return(plugin); }