Skip to content

Add Commands.runIf(...) as command factory method to Commands #7808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ public static Command either(Command onTrue, Command onFalse, BooleanSupplier se
return new ConditionalCommand(onTrue, onFalse, selector);
}

/**
* Runs a command if the boolean condition function is true otherwise it does nothing and exits.
*
* @param condition the condition function
* @param onTrue the command to run if the condition function returns true
* @return the command
* @see ConditionalCommand
* @see {@link Commands#none()}
*/
public static Command runIf(BooleanSupplier condition, Command onTrue) {
return onTrue.onlyIf(condition);
}

/**
* Runs one of several commands, based on the selector function.
*
Expand Down