From ce851148f08976d8352041f00a8e24afec621c55 Mon Sep 17 00:00:00 2001 From: anth64 Date: Tue, 2 Jun 2026 22:54:34 +0200 Subject: [PATCH] refactor: rewrite CommandData as struct --- CommandHook/CommandData.cs | 21 ++++++++++----------- CommandHook/CommandHookModSystem.cs | 12 +++--------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/CommandHook/CommandData.cs b/CommandHook/CommandData.cs index 3c9425d..ac0652f 100644 --- a/CommandHook/CommandData.cs +++ b/CommandHook/CommandData.cs @@ -2,19 +2,18 @@ using Vintagestory.API.Server; namespace CommandHook; -public class CommandData +public struct CommandData { - public IServerPlayer? Sender { get; } - public string FullCommand { get; } - public bool IsPlayerCommand { get; } - public bool Cancel { get; set; } + public readonly IServerPlayer? Sender; + public readonly string FullCommand; + public readonly bool IsPlayerCommand; + public bool Cancel; - - public CommandData(IServerPlayer sender, string fullCommand) + public CommandData(IServerPlayer? sender, string fullCommand) { - Sender = sender; - IsPlayerCommand = Sender != null; - FullCommand = fullCommand?.Trim() ?? string.Empty; - Cancel = false; + Sender = sender; + FullCommand = fullCommand.Length > 0 ? fullCommand.Trim() : string.Empty; + IsPlayerCommand = sender != null; + Cancel = false; } } diff --git a/CommandHook/CommandHookModSystem.cs b/CommandHook/CommandHookModSystem.cs index 2413ed5..191d800 100644 --- a/CommandHook/CommandHookModSystem.cs +++ b/CommandHook/CommandHookModSystem.cs @@ -1,20 +1,14 @@ -using Vintagestory.API.Server; +using Vintagestory.API.Server; using Vintagestory.API.Common; namespace CommandHook; public class CommandHookModSystem : ModSystem { - - public override bool ShouldLoad(EnumAppSide forSide) - { - return forSide == EnumAppSide.Server; - } - + public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server; public override void StartServerSide(ICoreServerAPI api) { - Mod.Logger.Notification("Loaded"); + Mod.Logger.Notification("[CommandHook] Loaded"); } - }