refactor: add CommandName parsing and pack flags into bitmask
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user