diff --git a/PluginCommandManager.cs b/PluginCommandManager.cs index 6cea1b4..6ea1a4a 100644 --- a/PluginCommandManager.cs +++ b/PluginCommandManager.cs @@ -1,10 +1,10 @@ -using System; +using Dalamud.Game.Command; +using Dalamud.Plugin; +using DalamudPluginProjectTemplate.Attributes; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Dalamud.Game.Command; -using Dalamud.Plugin; -using DalamudPluginProjectTemplate.Attributes; using static Dalamud.Game.Command.CommandInfo; // ReSharper disable ForCanBeConvertedToForeach @@ -14,17 +14,17 @@ public class PluginCommandManager : IDisposable { private readonly DalamudPluginInterface pluginInterface; private readonly (string, CommandInfo)[] pluginCommands; + private readonly THost host; public PluginCommandManager(THost host, DalamudPluginInterface pluginInterface) { this.pluginInterface = pluginInterface; + this.host = host; - #region Command Registration this.pluginCommands = host.GetType().GetMethods() .Where(method => method.GetCustomAttribute() != null) - .SelectMany(method => GetCommandInfoTuple((HandlerDelegate)Delegate.CreateDelegate(typeof(HandlerDelegate), host, method))) + .SelectMany(GetCommandInfoTuple) .ToArray(); - #endregion AddComandHandlers(); } @@ -51,13 +51,10 @@ private void RemoveCommandHandlers() } } - public void Dispose() + private IEnumerable<(string, CommandInfo)> GetCommandInfoTuple(MethodInfo method) { - RemoveCommandHandlers(); - } + var handlerDelegate = (HandlerDelegate)Delegate.CreateDelegate(typeof(HandlerDelegate), this.host, method); - private static IEnumerable<(string, CommandInfo)> GetCommandInfoTuple(HandlerDelegate handlerDelegate) - { var command = handlerDelegate.Method.GetCustomAttribute(); var aliases = handlerDelegate.Method.GetCustomAttribute(); var helpMessage = handlerDelegate.Method.GetCustomAttribute(); @@ -82,5 +79,10 @@ public void Dispose() return commandInfoTuples; } + + public void Dispose() + { + RemoveCommandHandlers(); + } } }