From cbdcacd6c2e540c4423db5423150adb8bbfdf43c Mon Sep 17 00:00:00 2001 From: anth64 Date: Wed, 17 Jun 2026 22:49:13 +0200 Subject: [PATCH] fix: rebuild on change --- CommandHook/CommandHookModSystem.cs | 38 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/CommandHook/CommandHookModSystem.cs b/CommandHook/CommandHookModSystem.cs index a67dbef..6d16cb3 100644 --- a/CommandHook/CommandHookModSystem.cs +++ b/CommandHook/CommandHookModSystem.cs @@ -28,8 +28,6 @@ public class CommandHookModSystem : ModSystem harmony = new Harmony(Mod.Info.ModID); harmony.PatchAll(); - api.Event.ServerRunPhase(EnumServerRunPhase.RunGame, Rebuild); - Mod.Logger.Notification("Loaded"); } @@ -50,33 +48,33 @@ public class CommandHookModSystem : ModSystem return; } - for (int i = 0; i < listeners.Count; i++) + int index = listeners.FindIndex(l => l.ModId == listener.ModId); + + bool changed = false; + if (index < 0) { - if (listeners[i].ModId != listener.ModId) - continue; - - if (CommandListEquals(listeners[i].Commands, commands)) - return; - - listeners[i] = listener; - Rebuild(); - return; + listeners.Add(listener); + changed = true; + } + else if (!CommandListEquals(listeners[index].Commands, commands)) + { + listeners[index] = listener; + changed = true; } - listeners.Add(listener); + if (changed) + Rebuild(); } public void Unregister(ICommandHookListener listener) { - for (int i = 0; i < listeners.Count; i++) - { - if (listeners[i].ModId != listener.ModId) - continue; + int index = listeners.FindIndex(l => l.ModId == listener.ModId); - listeners.RemoveAt(i); - Rebuild(); + if (index < 0) return; - } + + listeners.RemoveAt(index); + Rebuild(); } private void Rebuild()