Files
HellionChat/ChatTwo/Commands.cs
T
JonKazama-Hellion 7d5496e959 refactor(namespace): rename ChatTwo.* to HellionChat.* across all source files
81 namespace declarations and 100 using directives converted via sed,
plus two FQN-aliases (ChatTwoPartyFinderPayload in PayloadHandler.cs and
ModifierFlag in KeybindManager.cs) updated. Critical: Language.Designer.cs
and HellionStrings.Designer.cs ResourceManager string arguments updated
synchronously — these are runtime reflection lookups not caught by the
C# compiler.

Two intentional ChatTwo references remain: the legacy migration path
'ChatTwo.json' in Plugin.cs (still points to upstream Chat 2's config
file by design) and the InternalsVisibleTo declaration in
AssemblyInfo.cs (handled in the upcoming repo-folder rename task).

The local alias names 'ChatTwoPartyFinderPayload' and 'ChatTwoConflictDetector'
are preserved as local symbols; only their target namespaces and references
changed.
2026-05-03 21:23:28 +02:00

83 lines
2.1 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.Log.Warning($"Missing registration for command {command}");
return;
}
try
{
wrapper.Invoke(command, arguments);
}
catch (Exception ex)
{
Plugin.Log.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);
}
}