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,18 @@ public static Command either(Command onTrue, Command onFalse, BooleanSupplier se
return new ConditionalCommand(onTrue, onFalse, selector);
}

/**
* Runs a command if the boolean selector function is true.
*
* @param selector the selector function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of selector I'd refer to this as a condition

Copy link
Author

@otter502 otter502 Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rzblue With this change should I move the command out of the Selector Commands section of the Commands.java file? If so where should it go instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can stay in the Selecting section (along with either etc)

* @param onTrue the command to run if the selector function returns true
* @return the command
* @see ConditionalCommand
*/
public static Command runIf(BooleanSupplier selector, Command onTrue){
return onTrue.onlyIf(selector);
}

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