From 7e47f8d40908e321ce8bef1a8847c45c6e76e935 Mon Sep 17 00:00:00 2001 From: anth64 Date: Tue, 2 Jun 2026 23:09:03 +0200 Subject: [PATCH] refactor: add CommandName parsing and pack flags into bitmask --- CommandHook/CommandData.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/CommandHook/CommandData.cs b/CommandHook/CommandData.cs index ac0652f..03bc5ec 100644 --- a/CommandHook/CommandData.cs +++ b/CommandHook/CommandData.cs @@ -6,14 +6,24 @@ public struct CommandData { public readonly IServerPlayer? Sender; public readonly string FullCommand; - public readonly bool IsPlayerCommand; - public bool Cancel; + public readonly string CommandName; + private byte _flags; + + private const byte FlagIsPlayerCommand = 1 << 0; + private const byte FlagCancel = 1 << 1; + + public bool IsPlayerCommand => (_flags & FlagIsPlayerCommand) != 0; + public bool Cancel + { + get => (_flags & FlagCancel) != 0; + set => _flags = value ? (byte)(_flags | FlagCancel) : (byte)(_flags & ~FlagCancel); + } public CommandData(IServerPlayer? sender, string fullCommand) { - Sender = sender; - FullCommand = fullCommand.Length > 0 ? fullCommand.Trim() : string.Empty; - IsPlayerCommand = sender != null; - Cancel = false; + Sender = sender; + FullCommand = fullCommand.Length > 0 ? fullCommand.Trim() : string.Empty; + CommandName = FullCommand.Length > 1 ? FullCommand[1..].Split(' ')[0] : string.Empty; + _flags = sender != null ? FlagIsPlayerCommand : (byte)0; } }