fix: rebuild on change
This commit is contained in:
@@ -28,8 +28,6 @@ public class CommandHookModSystem : ModSystem
|
|||||||
harmony = new Harmony(Mod.Info.ModID);
|
harmony = new Harmony(Mod.Info.ModID);
|
||||||
harmony.PatchAll();
|
harmony.PatchAll();
|
||||||
|
|
||||||
api.Event.ServerRunPhase(EnumServerRunPhase.RunGame, Rebuild);
|
|
||||||
|
|
||||||
Mod.Logger.Notification("Loaded");
|
Mod.Logger.Notification("Loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,33 +48,33 @@ public class CommandHookModSystem : ModSystem
|
|||||||
return;
|
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)
|
listeners.Add(listener);
|
||||||
continue;
|
changed = true;
|
||||||
|
}
|
||||||
if (CommandListEquals(listeners[i].Commands, commands))
|
else if (!CommandListEquals(listeners[index].Commands, commands))
|
||||||
return;
|
{
|
||||||
|
listeners[index] = listener;
|
||||||
listeners[i] = listener;
|
changed = true;
|
||||||
Rebuild();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
listeners.Add(listener);
|
if (changed)
|
||||||
|
Rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unregister(ICommandHookListener listener)
|
public void Unregister(ICommandHookListener listener)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < listeners.Count; i++)
|
int index = listeners.FindIndex(l => l.ModId == listener.ModId);
|
||||||
{
|
|
||||||
if (listeners[i].ModId != listener.ModId)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
listeners.RemoveAt(i);
|
if (index < 0)
|
||||||
Rebuild();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
listeners.RemoveAt(index);
|
||||||
|
Rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Rebuild()
|
private void Rebuild()
|
||||||
|
|||||||
Reference in New Issue
Block a user