@@ -548,14 +548,14 @@ export function register(commands:Record<string, FishCommandData<string, any> |
548
548
}
549
549
550
550
//Recursively resolve unresolved args (such as players that need to be determined through a menu)
551
- resolveArgsRecursive ( output . processedArgs , output . unresolvedArgs , fishSender , ( ) => {
551
+ resolveArgsRecursive ( output . processedArgs , output . unresolvedArgs , fishSender ) . then ( async ( resolvedArgs ) => {
552
552
//Run the command handler
553
553
const usageData = fishSender . getUsageData ( name ) ;
554
554
let failed = false ;
555
555
try {
556
556
const args :FishCommandHandlerData < string , any > & FishCommandHandlerUtils = {
557
557
rawArgs,
558
- args : output . processedArgs ,
558
+ args : resolvedArgs ,
559
559
sender : fishSender ,
560
560
data : data . data ,
561
561
outputFail : message => { outputFail ( message , sender ) ; failed = true ; } ,
@@ -577,11 +577,11 @@ export function register(commands:Record<string, FishCommandData<string, any> |
577
577
fishSender . tapInfo . commandName = name ;
578
578
fishSender . tapInfo . mode = mode ;
579
579
}
580
- fishSender . tapInfo . lastArgs = output . processedArgs ;
580
+ fishSender . tapInfo . lastArgs = resolvedArgs ;
581
581
} ,
582
582
} ;
583
583
data . requirements ?. forEach ( r => r ( args ) ) ;
584
- data . handler ( args ) ;
584
+ await data . handler ( args ) ;
585
585
//Update usage data
586
586
if ( ! failed ) {
587
587
usageData . lastUsedSuccessfully = globalUsageData [ name ] . lastUsedSuccessfully = Date . now ( ) ;
@@ -665,9 +665,9 @@ export function registerConsole(commands:Record<string, FishConsoleCommandData<s
665
665
}
666
666
667
667
/** Recursively resolves args. This function is necessary to handle cases such as a command that accepts multiple players that all need to be selected through menus. */
668
- function resolveArgsRecursive ( processedArgs : Record < string , FishCommandArgType > , unresolvedArgs :CommandArg [ ] , sender :FishPlayer , callback : ( args : Record < string , FishCommandArgType > ) => void ) {
668
+ async function resolveArgsRecursive ( processedArgs : Record < string , FishCommandArgType > , unresolvedArgs :CommandArg [ ] , sender :FishPlayer ) {
669
669
if ( unresolvedArgs . length == 0 ) {
670
- callback ( processedArgs ) ;
670
+ return processedArgs ;
671
671
} else {
672
672
const argToResolve = unresolvedArgs . shift ( ) ! ;
673
673
let optionsList :mindustryPlayer [ ] = [ ] ;
@@ -676,18 +676,15 @@ function resolveArgsRecursive(processedArgs: Record<string, FishCommandArgType>,
676
676
case "player" : Groups . player . each ( player => optionsList . push ( player ) ) ; break ;
677
677
default : crash ( `Unable to resolve arg of type ${ argToResolve . type } ` ) ;
678
678
}
679
- Menu . menu ( `Select a player` , `Select a player for the argument "${ argToResolve . name } "` , optionsList , sender , {
679
+ const option = await Menu . menu ( `Select a player` , `Select a player for the argument "${ argToResolve . name } "` , optionsList , sender , {
680
680
includeCancel : true ,
681
681
optionStringifier : player => Strings . stripColors ( player . name ) . length >= 3 ?
682
682
Strings . stripColors ( player . name )
683
683
: escapeStringColorsClient ( player . name )
684
- } ) . then ( ( option ) => {
685
- processedArgs [ argToResolve . name ] = FishPlayer . get ( option ) ;
686
- resolveArgsRecursive ( processedArgs , unresolvedArgs , sender , callback ) ;
687
684
} ) ;
688
-
685
+ processedArgs [ argToResolve . name ] = FishPlayer . get ( option ) ;
686
+ return await resolveArgsRecursive ( processedArgs , unresolvedArgs , sender ) ;
689
687
}
690
-
691
688
}
692
689
693
690
export function initialize ( ) {
0 commit comments