fix: rebuild on change

This commit is contained in:
2026-06-17 22:49:13 +02:00
parent a69e81a3cb
commit cbdcacd6c2
+18 -20
View File
@@ -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()