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
+16 -6
View File
@@ -6,14 +6,24 @@ public struct CommandData
{ {
public readonly IServerPlayer? Sender; public readonly IServerPlayer? Sender;
public readonly string FullCommand; public readonly string FullCommand;
public readonly bool IsPlayerCommand; public readonly string CommandName;
public bool Cancel; 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) public CommandData(IServerPlayer? sender, string fullCommand)
{ {
Sender = sender; Sender = sender;
FullCommand = fullCommand.Length > 0 ? fullCommand.Trim() : string.Empty; FullCommand = fullCommand.Length > 0 ? fullCommand.Trim() : string.Empty;
IsPlayerCommand = sender != null; CommandName = FullCommand.Length > 1 ? FullCommand[1..].Split(' ')[0] : string.Empty;
Cancel = false; _flags = sender != null ? FlagIsPlayerCommand : (byte)0;
} }
} }