Files
HellionChat/HellionChat/Commands.cs
T
JonKazama-Hellion fee2459e73 refactor(services): route logging through IPluginLogProxy
F12.2 step 5b — service cluster (~42 sites in 16 files):
MessageManager, GameFunctions/{Chat, GameFunctions, KeybindManager},
EmoteCache, PayloadHandler, AutoTellTabsService, FontManager, Commands,
Util/{WrapperUtil, AutoTranslate, MemoryUtil}, Message, Themes/ThemeRegistry,
Ipc/ExtraChat, Configuration.

The proxy interface gained Dalamud's params-overload signature
(messageTemplate + params object[]) to cover Configuration.cs:86 which
relies on Serilog-style placeholders.

Verified: zero remaining Plugin.Log.X(...) call-sites in HellionChat/,
build green, build-suite 690/690.
2026-05-13 08:38:40 +02:00

90 lines
2.2 KiB
C#
Executable File

using Dalamud.Game.Command;
namespace HellionChat;
internal sealed class Commands : IDisposable
{
private readonly Dictionary<string, CommandWrapper> Registered = [];
public void Dispose()
{
foreach (var name in Registered.Keys)
Plugin.CommandManager.RemoveHandler(name);
}
internal void Initialise()
{
foreach (var wrapper in Registered.Values)
{
Plugin.CommandManager.AddHandler(
wrapper.Name,
new CommandInfo(Invoke)
{
HelpMessage = wrapper.Description ?? string.Empty,
ShowInHelp = wrapper.ShowInHelp,
}
);
}
}
internal CommandWrapper Register(
string name,
string? description = null,
bool? showInHelp = null
)
{
if (Registered.TryGetValue(name, out var wrapper))
{
if (description != null)
wrapper.Description = description;
if (showInHelp != null)
wrapper.ShowInHelp = showInHelp.Value;
return wrapper;
}
Registered[name] = new CommandWrapper(name, description, showInHelp ?? true);
return Registered[name];
}
private void Invoke(string command, string arguments)
{
if (!Registered.TryGetValue(command, out var wrapper))
{
Plugin.LogProxy.Warning($"Missing registration for command {command}");
return;
}
try
{
wrapper.Invoke(command, arguments);
}
catch (Exception ex)
{
Plugin.LogProxy.Error(ex, $"Error while executing command {command}");
}
}
}
internal sealed class CommandWrapper
{
internal string Name { get; }
internal string? Description { get; set; }
internal bool ShowInHelp { get; set; }
internal event Action<string, string>? Execute;
internal CommandWrapper(string name, string? description, bool showInHelp)
{
Name = name;
Description = description;
ShowInHelp = showInHelp;
}
internal void Invoke(string command, string arguments)
{
Execute?.Invoke(command, arguments);
}
}