[commands] Fix compose-while-scheduled issue and test all compositions (#5581)

This commit is contained in:
Ryan Blue
2023-12-23 15:12:13 -05:00
committed by GitHub
parent aeb1a4aa33
commit ef1cb3f41e
20 changed files with 146 additions and 83 deletions

View File

@@ -585,7 +585,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
*/
public void registerComposedCommands(Command... commands) {
var commandSet = Set.of(commands);
requireNotComposed(commandSet);
requireNotComposedOrScheduled(commandSet);
var exception = new Exception("Originally composed at:");
exception.fillInStackTrace();
for (var command : commands) {
@@ -617,7 +617,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
}
/**
* Requires that the specified command hasn't been already added to a composition.
* Requires that the specified command hasn't already been added to a composition.
*
* @param commands The commands to check
* @throws IllegalArgumentException if the given commands have already been composed.
@@ -635,7 +635,7 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
}
/**
* Requires that the specified commands not have been already added to a composition.
* Requires that the specified commands have not already been added to a composition.
*
* @param commands The commands to check
* @throws IllegalArgumentException if the given commands have already been composed.
@@ -644,6 +644,34 @@ public final class CommandScheduler implements Sendable, AutoCloseable {
requireNotComposed(commands.toArray(Command[]::new));
}
/**
* Requires that the specified command hasn't already been added to a composition, and is not
* currently scheduled.
*
* @param command The command to check
* @throws IllegalArgumentException if the given command has already been composed or scheduled.
*/
public void requireNotComposedOrScheduled(Command command) {
if (isScheduled(command)) {
throw new IllegalArgumentException(
"Commands that have been scheduled individually may not be added to a composition!");
}
requireNotComposed(command);
}
/**
* Requires that the specified commands have not already been added to a composition, and are not
* currently scheduled.
*
* @param commands The commands to check
* @throws IllegalArgumentException if the given commands have already been composed or scheduled.
*/
public void requireNotComposedOrScheduled(Collection<Command> commands) {
for (var command : commands) {
requireNotComposedOrScheduled(command);
}
}
/**
* Check if the given command has been composed.
*