mirror of
https://github.com/oliverbooth/VpSharp
synced 2024-11-09 23:35:41 +00:00
feat(commands): add support for optional args
This commit is contained in:
parent
487bb8ca88
commit
65a9a0e1e3
@ -253,7 +253,7 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
|
||||
}
|
||||
|
||||
ParameterInfo[] parameters = commandMethod.GetParameters();
|
||||
if (parameters.Length != arguments.Length)
|
||||
if (parameters.Length != arguments.Length || parameters[arguments.Length..].Any(p => !p.IsOptional))
|
||||
{
|
||||
return base.OnMessageReceived(args);
|
||||
}
|
||||
@ -286,6 +286,11 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
|
||||
}
|
||||
}
|
||||
|
||||
for (int index = arguments.Length; index < parameters.Length; index++)
|
||||
{
|
||||
arguments[index] = parameters[index].DefaultValue;
|
||||
}
|
||||
|
||||
object? returnValue = commandMethod.Invoke(command.Module, arguments);
|
||||
if (returnValue is Task task)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user