From 3281fcef4a62ef5aaf483a046224e2718fab0c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E4=B8=83?= <1653638943@qq.com> Date: Wed, 6 May 2026 16:28:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E7=A9=BA=E6=8C=87=E4=BB=A4bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Vortex.Adapter/Plugin.cs | 57 +++++++++++++++++++++++++++++--- Vortex.Adapter/Setting/Config.cs | 4 +-- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/Vortex.Adapter/Plugin.cs b/Vortex.Adapter/Plugin.cs index 91991d5..a4f530b 100644 --- a/Vortex.Adapter/Plugin.cs +++ b/Vortex.Adapter/Plugin.cs @@ -16,10 +16,12 @@ namespace Vortex.Adapter; [ApiVersion(2, 1)] public class Plugin : TerrariaPlugin { - public override string Author => "少司命"; + public override string Author => "少司命&十七"; public override string Description => "Vortex 适配插件"; public override string Name => Assembly.GetExecutingAssembly().GetName().Name!; - public override Version Version => new(1, 0, 0, 0); + public override Version Version => new(1, 1, 0, 0); + + private const string EmptyCommandHelpText = "[Vortex.Adapter] Empty placeholder command"; internal static readonly List ServerPlayers = new(); internal static Channel Channeler = Channel.CreateBounded(1); @@ -64,7 +66,7 @@ public override void Initialize() ServerApi.Hooks.NpcKilled.Register(this, OnKillNpc); GetDataHandlers.KillMe.Register(this.OnKill); - Config.Instance.SocketConfig.EmptyCommand.ForEach(x => Commands.ChatCommands.Add(new("", (_) => { }, x))); + RegisterEmptyCommands(Config.Instance.SocketConfig.EmptyCommand); GeneralHooks.ReloadEvent += Config.Reload; Utils.HandleCommandLine(Environment.GetCommandLineArgs()); @@ -102,14 +104,59 @@ protected override void Dispose(bool disposing) _timer.Elapsed -= TimerUpdate; _timer.Stop(); - RemoveAssemblyCommands(Assembly.GetExecutingAssembly()); + RemoveAssemblyCommands(Assembly.GetExecutingAssembly(), Config.Instance.SocketConfig.EmptyCommand); } base.Dispose(disposing); } - public static void RemoveAssemblyCommands(Assembly assembly) + public static void RemoveAssemblyCommands(Assembly assembly, IEnumerable? emptyCommands = null) { Commands.ChatCommands.RemoveAll(cmd => cmd.GetType().Assembly == assembly); + RemoveRegisteredEmptyCommands(emptyCommands); + } + + public static void RegisterEmptyCommands(IEnumerable? emptyCommands) + { + var normalizedNames = NormalizeEmptyCommandNames(emptyCommands); + RemoveRegisteredEmptyCommands(normalizedNames); + + foreach (var commandName in normalizedNames) + { + Commands.ChatCommands.Add(new TShockAPI.Command("", _ => { }, commandName) + { + HelpText = EmptyCommandHelpText + }); + } + } + + private static void RemoveRegisteredEmptyCommands(IEnumerable? emptyCommands) + { + var normalizedNames = NormalizeEmptyCommandNames(emptyCommands); + if (normalizedNames.Length == 0) + { + return; + } + + var nameSet = new HashSet(normalizedNames, StringComparer.OrdinalIgnoreCase); + Commands.ChatCommands.RemoveAll(cmd => + cmd.Names.Count == 1 && + nameSet.Contains(cmd.Names[0]) && + (cmd.HelpText == EmptyCommandHelpText || + (cmd.Permissions.Count == 1 && string.IsNullOrWhiteSpace(cmd.Permissions[0])))); + } + + private static string[] NormalizeEmptyCommandNames(IEnumerable? emptyCommands) + { + if (emptyCommands == null) + { + return []; + } + + return emptyCommands + .Where(static x => !string.IsNullOrWhiteSpace(x)) + .Select(static x => x.Trim()) + .Distinct(StringComparer.OrdinalIgnoreCase) + .ToArray(); } private void TimerUpdate(object? sender, ElapsedEventArgs e) diff --git a/Vortex.Adapter/Setting/Config.cs b/Vortex.Adapter/Setting/Config.cs index b0755d0..37f947e 100644 --- a/Vortex.Adapter/Setting/Config.cs +++ b/Vortex.Adapter/Setting/Config.cs @@ -48,8 +48,8 @@ public static Config Read() public static void Reload(ReloadEventArgs e) { - Plugin.RemoveAssemblyCommands(Assembly.GetExecutingAssembly()); + Plugin.RemoveAssemblyCommands(Assembly.GetExecutingAssembly(), _instance?.SocketConfig.EmptyCommand); _instance = Read(); - Instance.SocketConfig.EmptyCommand.ForEach(x => Commands.ChatCommands.Add(new("", (_) => { }, x))); + Plugin.RegisterEmptyCommands(Instance.SocketConfig.EmptyCommand); } } From 391823d83fa7ad0f8b994f8eff506ee1345e73ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E4=B8=83?= <1653638943@qq.com> Date: Wed, 6 May 2026 16:57:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E7=A9=BA=E6=8C=87=E4=BB=A4bug=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Vortex.Adapter/Plugin.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Vortex.Adapter/Plugin.cs b/Vortex.Adapter/Plugin.cs index a4f530b..f56b7af 100644 --- a/Vortex.Adapter/Plugin.cs +++ b/Vortex.Adapter/Plugin.cs @@ -16,10 +16,10 @@ namespace Vortex.Adapter; [ApiVersion(2, 1)] public class Plugin : TerrariaPlugin { - public override string Author => "少司命&十七"; + public override string Author => "少司命"; public override string Description => "Vortex 适配插件"; public override string Name => Assembly.GetExecutingAssembly().GetName().Name!; - public override Version Version => new(1, 1, 0, 0); + public override Version Version => new(1, 0, 0, 0); private const string EmptyCommandHelpText = "[Vortex.Adapter] Empty placeholder command"; @@ -112,13 +112,13 @@ protected override void Dispose(bool disposing) public static void RemoveAssemblyCommands(Assembly assembly, IEnumerable? emptyCommands = null) { Commands.ChatCommands.RemoveAll(cmd => cmd.GetType().Assembly == assembly); - RemoveRegisteredEmptyCommands(emptyCommands); + RemoveRegisteredEmptyCommandsCore(NormalizeEmptyCommandNames(emptyCommands)); } public static void RegisterEmptyCommands(IEnumerable? emptyCommands) { var normalizedNames = NormalizeEmptyCommandNames(emptyCommands); - RemoveRegisteredEmptyCommands(normalizedNames); + RemoveRegisteredEmptyCommandsCore(normalizedNames); foreach (var commandName in normalizedNames) { @@ -129,9 +129,8 @@ public static void RegisterEmptyCommands(IEnumerable? emptyCommands) } } - private static void RemoveRegisteredEmptyCommands(IEnumerable? emptyCommands) + private static void RemoveRegisteredEmptyCommandsCore(string[] normalizedNames) { - var normalizedNames = NormalizeEmptyCommandNames(emptyCommands); if (normalizedNames.Length == 0) { return; @@ -139,10 +138,8 @@ private static void RemoveRegisteredEmptyCommands(IEnumerable? emptyComm var nameSet = new HashSet(normalizedNames, StringComparer.OrdinalIgnoreCase); Commands.ChatCommands.RemoveAll(cmd => - cmd.Names.Count == 1 && - nameSet.Contains(cmd.Names[0]) && - (cmd.HelpText == EmptyCommandHelpText || - (cmd.Permissions.Count == 1 && string.IsNullOrWhiteSpace(cmd.Permissions[0])))); + cmd.HelpText == EmptyCommandHelpText && + nameSet.Contains(cmd.Name)); } private static string[] NormalizeEmptyCommandNames(IEnumerable? emptyCommands)