Pumpkin Plugin API for C#
| bin/Release | ||
| obj | ||
| src | ||
| .gitmodules | ||
| generate.sh | ||
| LICENSE | ||
| NuGet.Config | ||
| PumpkinApi.csproj | ||
| README.md | ||
Pumpkin Plugin API for C# (.NET)
This package provides everything needed to write a Pumpkin server plugin compiled to WebAssembly using C# (.NET 10+).
Quick start
-
Create a new C# Class Library project for your plugin:
dotnet new classlib -n MyPumpkinPlugin cd MyPumpkinPlugin -
Add a
NuGet.Configto your project to include the .NET experimental feed:<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" /> </packageSources> </configuration> -
Add the required packages:
dotnet add package PumpkinMC.PumpkinApi dotnet add package ByteCodeAlliance.Componentize.DotNet.Wasm.SDK --prerelease -
Configure your
.csprojto targetwasi-wasm:<PropertyGroup> <TargetFramework>net10.0</TargetFramework> <RuntimeIdentifier>wasi-wasm</RuntimeIdentifier> </PropertyGroup> -
Implement your plugin by implementing the interfaces from the package (e.g.,
PluginWorld.IPluginWorldExportsandPluginWorld.wit.Exports.pumpkin.plugin.v0_1_0.IMetadataExports).
using PluginWorld;
using PluginWorld.wit.Exports.pumpkin.plugin.v0_1_0;
using PluginWorld.wit.Imports.pumpkin.plugin.v0_1_0;
namespace MyPumpkinPlugin;
public class MyPlugin : IPluginWorldExports, IMetadataExports
{
public static void InitPlugin() { }
public static void OnLoad(IContextImports.Context context)
{
ILoggingImports.Log(ILoggingImports.Level.Info, "C# plugin loaded!");
}
public static void OnUnload(IContextImports.Context context) { }
public static IEventImports.Event HandleEvent(uint eventId, IServerImports.Server server, IEventImports.Event @event)
{
return @event;
}
public static int HandleCommand(uint commandId, ICommandImports.CommandSender sender, IServerImports.Server server, ICommandImports.ConsumedArgs args)
{
return 0;
}
public static void HandleTask(uint handlerId, IServerImports.Server server) { }
public static IMetadataExports.PluginMetadata Metadata()
{
return new IMetadataExports.PluginMetadata(
"my-csharp-plugin",
"0.1.0",
"An example C# plugin.",
["you"],
[]
);
}
}
- Build your plugin into a WebAssembly component:
dotnet build -c Release
The output will contain a .wasm file that you can use in your Pumpkin server.