refactor: collapse WildcardModRegistration into CommandRegistration
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user