From 7cdd8d27c0fc42b2ad91ac34583a3138eb710367 Mon Sep 17 00:00:00 2001 From: anth64 Date: Thu, 4 Jun 2026 21:35:57 +0200 Subject: [PATCH] refactor: collapse hooks into nested frozen dictionary --- CommandHook/CommandHookModSystem.cs | 7 +++---- CommandHook/HookEntry.cs | 13 ------------- CommandHook/ModEntry.cs | 13 ------------- 3 files changed, 3 insertions(+), 30 deletions(-) delete mode 100644 CommandHook/HookEntry.cs delete mode 100644 CommandHook/ModEntry.cs diff --git a/CommandHook/CommandHookModSystem.cs b/CommandHook/CommandHookModSystem.cs index 8eb861f..474eeae 100644 --- a/CommandHook/CommandHookModSystem.cs +++ b/CommandHook/CommandHookModSystem.cs @@ -1,4 +1,4 @@ -using System; +using System.Collections.Frozen; using Vintagestory.API.Common; using Vintagestory.API.Datastructures; using Vintagestory.API.Server; @@ -7,9 +7,8 @@ namespace CommandHook; public class CommandHookModSystem : ModSystem { - private ModEntry[] modEntries = Array.Empty(); - private HookEntry[] hashTable = Array.Empty(); - private uint hashTableSize = 0; + private FrozenDictionary> registrations = + FrozenDictionary>.Empty; public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server; diff --git a/CommandHook/HookEntry.cs b/CommandHook/HookEntry.cs deleted file mode 100644 index 6a3feab..0000000 --- a/CommandHook/HookEntry.cs +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index fd654b0..0000000 --- a/CommandHook/ModEntry.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CommandHook; - -public struct ModEntry -{ - public readonly string ModId; - public readonly HookEntry[] Hooks; - - public ModEntry(string modId, HookEntry[] hooks) - { - ModId = modId; - Hooks = hooks; - } -}