refactor: collapse WildcardModRegistration into CommandRegistration

This commit is contained in:
2026-06-03 19:02:22 +02:00
parent 1fb1d41824
commit 1aaea585be
3 changed files with 5 additions and 24 deletions
+4 -4
View File
@@ -7,7 +7,7 @@ namespace CommandHook;
public class CommandHookModSystem : ModSystem
{
private readonly Dictionary<string, WildcardModRegistration> wildcards = new();
private readonly Dictionary<string, CommandRegistration> wildcards = new();
private readonly Dictionary<string, ModRegistration> registrations = new();
public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server;
@@ -18,12 +18,12 @@ public class CommandHookModSystem : ModSystem
api.Event.PlayerChat += OnPlayerChat;
}
public void RegisterWildcard(string modId, WildcardModRegistration registration)
public void RegisterWildcard(string modId, CommandRegistration registration)
{
wildcards[modId] = registration;
}
public void Register(string modId, CommandRegistration registration)
public void Register(string modId, string command, CommandRegistration registration)
{
if (!registrations.TryGetValue(modId, out var modReg))
{
@@ -31,7 +31,7 @@ public class CommandHookModSystem : ModSystem
registrations[modId] = modReg;
}
modReg.Commands[registration.CommandFilter] = registration;
modReg.Commands[command] = registration;
}
private void OnPlayerChat(
+1 -7
View File
@@ -2,17 +2,11 @@ namespace CommandHook;
public struct CommandRegistration
{
public readonly string CommandFilter;
public readonly CommandHookDelegate? Before;
public readonly CommandHookDelegate? After;
public CommandRegistration(
string commandFilter,
CommandHookDelegate? before,
CommandHookDelegate? after
)
public CommandRegistration(CommandHookDelegate? before, CommandHookDelegate? after)
{
CommandFilter = commandFilter;
Before = before;
After = after;
}
-13
View File
@@ -1,13 +0,0 @@
namespace CommandHook;
public struct WildcardModRegistration
{
public readonly CommandHookDelegate? Before;
public readonly CommandHookDelegate? After;
public WildcardModRegistration(CommandHookDelegate? before, CommandHookDelegate? after)
{
Before = before;
After = after;
}
}