feat: command args feature#849
Conversation
|
I actually like this, I hate creating commands cause I always have to do the checks and that what takes the most ammount of time |
|
All we really need is somebody to test this b4 we merge this |
|
The idea of //Inside a command
var cargs = CommandArguments.Parse(args); //turns ArraySegment<string> into CommandArguments instance
Player Target = cargs.GetPlayerAt(0); //Gets a player by id/name from the argument 0 or null.
int Health = cargs.GetIntAt(1); // gets and parses an int from argument 1 or null
if(!cargs.Ensure(out response)) // will make sure that all arguments that are retrieved through GetPlayerAt, GetIntAt, GetFloatAt, ect are valid and not null. If they arent, it returns false and sets response to something like:
//"Argument {x} should be a {type}"
return false;
//Then we can use the arguments normally
Target.Health = Health; |
|
If we implement original suggestion, we'll have to store internally types and indexes. I assume it might be easier for devs to just run one function which will just return response if one of the arguments is incorrect. But current implementation allows devs to use |
|
I'm with Valera on this one, I think having the Try methods is good enough, if you want, write your own state machine on top of CommandArgs in your own plugins. But as it is right now, devs can just return their own error messages if TryGetX fails |
Description
Describe the changes
Adds a new class (
CommandArgs) which provides easy access to all command's args with conversions and stuffWhat is the current behavior? (You can also link to an open issue here)
What is the new behavior? (if this is a feature change)
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
Other information:
Regex is written with AI cuz I'm a dumb-dumb, thus requires testing
Also I'm planning to add some more cool features to this class but as for now backbone of it is already done
Types of changes
Submission checklist
Patches (if there are any changes related to Harmony patches)
Other