diff --git a/CommandHook/CommandHookModSystem.cs b/CommandHook/CommandHookModSystem.cs index 80cd386..8eb861f 100644 --- a/CommandHook/CommandHookModSystem.cs +++ b/CommandHook/CommandHookModSystem.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System; using Vintagestory.API.Common; using Vintagestory.API.Datastructures; using Vintagestory.API.Server; @@ -7,8 +7,9 @@ namespace CommandHook; public class CommandHookModSystem : ModSystem { - private readonly Dictionary wildcards = new(); - private readonly Dictionary registrations = new(); + private ModEntry[] modEntries = Array.Empty(); + private HookEntry[] hashTable = Array.Empty(); + private uint hashTableSize = 0; public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server; @@ -18,22 +19,6 @@ public class CommandHookModSystem : ModSystem api.Event.PlayerChat += OnPlayerChat; } - public void RegisterWildcard(string modId, CommandRegistration registration) - { - wildcards[modId] = registration; - } - - public void Register(string modId, string command, CommandRegistration registration) - { - if (!registrations.TryGetValue(modId, out var modReg)) - { - modReg = new ModRegistration(new Dictionary()); - registrations[modId] = modReg; - } - - modReg.Commands[command] = registration; - } - private void OnPlayerChat( IServerPlayer player, int channelId, @@ -46,22 +31,6 @@ public class CommandHookModSystem : ModSystem return; var cmdData = new CommandData(player, message); - - foreach (var (_, reg) in wildcards) - reg.Before?.Invoke(ref cmdData); - - foreach (var (_, modReg) in registrations) - if (modReg.Commands.TryGetValue(cmdData.CommandName, out var reg)) - reg.Before?.Invoke(ref cmdData); - - if (cmdData.Cancel) - consumed.value = true; - - foreach (var (_, reg) in wildcards) - reg.After?.Invoke(ref cmdData); - - foreach (var (_, modReg) in registrations) - if (modReg.Commands.TryGetValue(cmdData.CommandName, out var reg)) - reg.After?.Invoke(ref cmdData); + // TODO dispatch } } diff --git a/CommandHook/HookEntry.cs b/CommandHook/HookEntry.cs new file mode 100644 index 0000000..6a3feab --- /dev/null +++ b/CommandHook/HookEntry.cs @@ -0,0 +1,13 @@ +namespace CommandHook; + +public struct HookEntry +{ + public readonly string? CommandName; // null = wildcard + public readonly CommandRegistration Registration; + + public HookEntry(string? commandName, CommandRegistration registration) + { + CommandName = commandName; + Registration = registration; + } +} diff --git a/CommandHook/ModEntry.cs b/CommandHook/ModEntry.cs new file mode 100644 index 0000000..fd654b0 --- /dev/null +++ b/CommandHook/ModEntry.cs @@ -0,0 +1,13 @@ +namespace CommandHook; + +public struct ModEntry +{ + public readonly string ModId; + public readonly HookEntry[] Hooks; + + public ModEntry(string modId, HookEntry[] hooks) + { + ModId = modId; + Hooks = hooks; + } +} diff --git a/CommandHook/ModRegistration.cs b/CommandHook/ModRegistration.cs deleted file mode 100644 index b17e59c..0000000 --- a/CommandHook/ModRegistration.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; - -namespace CommandHook; - -public struct ModRegistration -{ - public readonly Dictionary Commands; - - public ModRegistration(Dictionary commands) - { - Commands = commands; - } -}