docs: update example to use static Register/Unregister

This commit is contained in:
2026-06-28 15:34:06 +02:00
parent f57a16f5cc
commit 2f434fbdfa
+5 -5
View File
@@ -39,7 +39,7 @@ Add it as a dependency in your `modinfo.json`:
```json
"dependencies": {
"game": "1.22.3",
"commandhook": "2.0.0"
"commandhook": "2.1.0"
}
```
@@ -116,16 +116,16 @@ Register it once your mod starts, unregister it on dispose:
```csharp
public override void StartServerSide(ICoreServerAPI api)
{
// CommandHookModSystem.Instance is null if CommandHook isn't loaded,
// hence the ?. Register your listener once, here.
CommandHookModSystem.Instance?.Register(myListener);
// Register your listener once, here. No-ops silently if CommandHook
// isn't loaded.
CommandHookModSystem.Register(myListener);
}
public override void Dispose()
{
// Always unregister on dispose, otherwise a stale listener stays in
// the dispatch table after your mod is gone.
CommandHookModSystem.Instance?.Unregister(myListener);
CommandHookModSystem.Unregister(myListener);
}
```