diff --git a/CommandHook/CommandHookModSystem.cs b/CommandHook/CommandHookModSystem.cs index a8db59e..c3b4539 100644 --- a/CommandHook/CommandHookModSystem.cs +++ b/CommandHook/CommandHookModSystem.cs @@ -1,4 +1,5 @@ using System.Collections.Frozen; +using System.Collections.Generic; using HarmonyLib; using Vintagestory.API.Common; using Vintagestory.API.Server; @@ -30,6 +31,31 @@ public class CommandHookModSystem : ModSystem Instance = null; } + public void Register(string modId, string commandName, CommandRegistration registration) + { + var builder = new Dictionary>(); + + foreach (var (cmd, mods) in registrations) + { + var inner = new Dictionary(); + foreach (var (id, reg) in mods) + inner[id] = reg; + builder[cmd] = inner; + } + + if (!builder.TryGetValue(commandName, out var target)) + { + target = new Dictionary(); + builder[commandName] = target; + } + target[modId] = registration; + + registrations = builder.ToFrozenDictionary( + pair => pair.Key, + pair => pair.Value.ToFrozenDictionary() + ); + } + public bool FireBefore(string commandName, ref CommandData data) { if (registrations.TryGetValue(commandName, out var mods))