Plugin ↔ Plugin

The following page describes how a plugin may interact with another plugin, e.g. calling functions.

Given that there are two plugins PluginA and PluginB , it is possible to call methods / access each other using the PluginManager.

A reference to the build *.dll of the other plugin is required in the solution, similiar to the HogWarpSdk.dll reference done in Configure the project.

Make sure to only access another plugin earliest in the PostLoad lifecycle, as it is not guaranteed to be loaded if called earlier.

Example

PluginA.cs
namespace PluginA;

public class Plugin : HogWarpSdk.IPlugin
{
    public string Author { get; } = "YourName";
    public string Name { get; } = "PluginA";
    public Version Version { get; } = new(1, 0, 0, 0);
    
    public Plugin() { }

    public void PostLoad() { }

    public void Shutdown() { }
    
    public void DoSomething() 
    {
        // This method is called from a different plugin
    }
}

PluginB.cs
namespace PluginB;

public class Plugin : HogWarpSdk.IPlugin
{
    public string Author { get; } = "YourName";
    public string Name { get; } = "PluginB";
    public Version Version { get; } = new(1, 0, 0, 0);
    
    public Plugin() { }

    public void PostLoad() 
    { 
        _logger.Info("Post load");

        var pluginA = HogWarpSdk.Server.PluginManager.Get<PluginA.Plugin>();
        if (pluginA != null)
        {
            _logger.Info($"PluginA found, version {pluginA.Version}");
            pluginA.DoSomething();
        }
        else
        {
            _logger.Info("PluginA not found");
        }
    }

    public void Shutdown() { }
}

Last updated