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 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user