Skip to content

Commit

Permalink
Update Command.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tides committed Feb 24, 2024
1 parent 2b0721a commit 9c3bb5b
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Obsidian/Commands/Framework/Entities/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task ExecuteAsync(CommandContext context, string[] args)
}

private bool TryFindExecutor(IEnumerable<IExecutor<CommandContext>> executors, string[] args, CommandContext context,
[NotNullWhen(true)]out IExecutor<CommandContext>? executor)
[NotNullWhen(true)] out IExecutor<CommandContext>? executor)
{
executor = null;

Expand All @@ -102,20 +102,14 @@ private bool TryFindExecutor(IEnumerable<IExecutor<CommandContext>> executors, s

foreach (var exec in executors)
{
executor = exec;

var methodParams = exec.GetParameters();
for (int i = 0; i < args.Length; i++)
{
var param = methodParams[i];
var arg = args[i];

if (!CommandHandler.IsValidArgumentType(param.ParameterType))
{
success = false;
executor = null;
return false;
}

var parser = CommandHandler.GetArgumentParser(param.ParameterType);
if (parser.TryParseArgument(arg, context, out _))
Expand All @@ -124,12 +118,14 @@ private bool TryFindExecutor(IEnumerable<IExecutor<CommandContext>> executors, s
continue;
}

success = false;
return false;
}

if (success)
{
executor = exec;
return true;
}
}

return false;
Expand Down

0 comments on commit 9c3bb5b

Please sign in to comment.