fix(commandhookmodsystem): short-circuit Before dispatch on cancel

FireBefore continued invoking every registered listener even after one had set Cancel, running callbacks against a command that was already dead. Break out of the loop as soon as Cancel is set.
This commit is contained in:
2026-06-17 19:13:14 +02:00
parent a130042206
commit d0dcd599cf
2 changed files with 11 additions and 3 deletions
+6
View File
@@ -125,8 +125,14 @@ public class CommandHookModSystem : ModSystem
internal bool FireBefore(string commandName, ref CommandData data) internal bool FireBefore(string commandName, ref CommandData data)
{ {
if (registrations.TryGetValue(commandName, out var mods)) if (registrations.TryGetValue(commandName, out var mods))
{
foreach (var (_, reg) in mods) foreach (var (_, reg) in mods)
{
reg.Before?.Invoke(ref data); reg.Before?.Invoke(ref data);
if (data.Cancel)
break;
}
}
return data.Cancel; return data.Cancel;
} }
+3 -1
View File
@@ -3,7 +3,9 @@
"modid": "commandhook", "modid": "commandhook",
"name": "CommandHook", "name": "CommandHook",
"description": "Exposes server command events for other mods to hook into.", "description": "Exposes server command events for other mods to hook into.",
"authors": ["anth64"], "authors": [
"anth64"
],
"version": "0.1.0", "version": "0.1.0",
"side": "Server", "side": "Server",
"dependencies": { "dependencies": {