1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-23 00:18:46 +00:00

feat(commands): add support for optional args

This commit is contained in:
Oliver Booth 2023-05-06 16:00:41 +01:00
parent 487bb8ca88
commit 65a9a0e1e3
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025

View File

@ -253,7 +253,7 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
} }
ParameterInfo[] parameters = commandMethod.GetParameters(); 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); 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); object? returnValue = commandMethod.Invoke(command.Module, arguments);
if (returnValue is Task task) if (returnValue is Task task)
{ {