refactor: add CommandName parsing and pack flags into bitmask

This commit is contained in:
2026-06-02 23:09:03 +02:00
parent ce851148f0
commit 7e47f8d409
+14 -4
View File
@@ -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;
CommandName = FullCommand.Length > 1 ? FullCommand[1..].Split(' ')[0] : string.Empty;
_flags = sender != null ? FlagIsPlayerCommand : (byte)0;
}
}