Class DelayedCommand<T>
- Direct Known Subclasses:
AddOwnerDelayed, RemoveOwnerDelayed, SetBlocksToMoveDelayed, SetOpenDirectionDelayed, SetOpenStatusDelayed
A delayed command allows "starting" the command while only knowing the target structure. This is useful when the structure is already known (e.g. after having been selected in a GUI), but the other specific data is not.
An example usage of this system could be changing the name of a structure via a GUI. Using the GUI, the user has to select a structure to apply the change to, but we'll need to wait for user input to update the name. For a user, having to use specify the structure they would need to change in a command or something would be rather awkward, so this way we can remember that information and not require the user to input duplicate data.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classProvides context for creating delayed commands with all required dependencies. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final jakarta.inject.Provider<CommandFactory> Provider for the command factory to create new commands.protected final DelayedCommandInputManagerManager responsible for keeping track of active delayed command input requests.protected final DelayedCommandInputRequest.IFactory<T> Factory for creating delayed command input requests. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDelayedCommand(DelayedCommand.Context context, DelayedCommandInputRequest.IFactory<T> inputRequestFactory, Class<T> delayedInputClz) Constructs a new DelayedCommand. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract CompletableFuture<?> delayedInputExecutor(ICommandSender commandSender, StructureRetriever structureRetriever, T delayedInput) The method that is run once delayed input is received.protected abstract CommandDefinitionGets the command definition for this delayed command.protected abstract StringinputRequestMessage(ICommandSender commandSender, StructureRetriever structureRetriever) Retrieves the message that will be sent to the command sender after initialization of a delayed input request.provideDelayedInput(ICommandSender commandSender, T data) Provides the delayed input if there is currently an activeDelayedCommandInputRequestfor theICommandSender.runDelayed(ICommandSender commandSender, StructureRetriever structureRetriever) Starts the (new)DelayedInputRequestfor this delayed command.runDelayed(ICommandSender commandSender, Creator creator, Function<T, CompletableFuture<?>> executor, @Nullable Supplier<String> initMessageSupplier) Starts the (new)DelayedInputRequestfor this delayed command.@NonNull StringtoString()
-
Field Details
-
delayedCommandInputManager
Manager responsible for keeping track of active delayed command input requests. -
commandFactory
Provider for the command factory to create new commands. -
inputRequestFactory
Factory for creating delayed command input requests.
-
-
Constructor Details
-
DelayedCommand
protected DelayedCommand(DelayedCommand.Context context, DelayedCommandInputRequest.IFactory<T> inputRequestFactory, Class<T> delayedInputClz) Constructs a new DelayedCommand.- Parameters:
context- The context containing required dependencies.inputRequestFactory- Factory for creating delayed command input requests.delayedInputClz- The class representing the type of delayed input this command expects.
-
-
Method Details
-
runDelayed
public CompletableFuture<?> runDelayed(ICommandSender commandSender, Creator creator, Function<T, CompletableFuture<?>> executor, @Nullable Supplier<String> initMessageSupplier) Starts the (new)DelayedInputRequestfor this delayed command.The
DelayedCommandInputRequestwill be used to retrieve the values that are required to execute the command. The player will be asked to use the command (again, if needed) to supply the missing data.These missing data can be supplied using
provideDelayedInput(ICommandSender, T). Once the data are supplied, the command will be executed.- Parameters:
commandSender- The entity that sent the command and is held responsible (i.e. permissions, communication) for its execution.creator- ACreatorthat will wait for the input.executor- Function to execute with the delayed input.initMessageSupplier- Supplier for the initial message to show to the user.- Returns:
- A CompletableFuture representing the result of the command.
-
runDelayed
public CompletableFuture<?> runDelayed(ICommandSender commandSender, StructureRetriever structureRetriever) Starts the (new)DelayedInputRequestfor this delayed command.The
DelayedCommandInputRequestwill be used to retrieve the values that are required to execute the command. The player will be asked to use the command (again, if needed) to supply the missing data.These missing data can be supplied using
provideDelayedInput(ICommandSender, T). Once the data are supplied, the command will be executed.- Parameters:
commandSender- The entity that sent the command and is held responsible (i.e. permissions, communication) for its execution.structureRetriever- AStructureRetrieverFactorythat references the target structure.- Returns:
- See
BaseCommand.run().
-
provideDelayedInput
Provides the delayed input if there is currently an activeDelayedCommandInputRequestfor theICommandSender. After processing the input, the new command will be executed immediately.If no active
DelayedCommandInputRequestcan be found for the command sender, the command sender will be informed about it (e.g. "We are not waiting for a command!").- Parameters:
commandSender- TheICommandSenderfor which to look for an activeDelayedCommandInputRequestthat can be fulfilled.data- The data specified by the user.- Returns:
- See
ToolUser.handleInput(Object).
-
getCommandDefinition
Gets the command definition for this delayed command.- Returns:
- The command definition.
-
delayedInputExecutor
protected abstract CompletableFuture<?> delayedInputExecutor(ICommandSender commandSender, StructureRetriever structureRetriever, T delayedInput) The method that is run once delayed input is received.It processes the new input and executes the command using the previously-provided data (see
runDelayed(ICommandSender, StructureRetriever)).- Parameters:
commandSender- The entity that sent the command and is held responsible (i.e. permissions, communication) for its execution.structureRetriever- AStructureRetrieverFactorythat references the target structure.delayedInput- The delayed input that was retrieved.- Returns:
- See
BaseCommand.run().
-
inputRequestMessage
protected abstract String inputRequestMessage(ICommandSender commandSender, StructureRetriever structureRetriever) Retrieves the message that will be sent to the command sender after initialization of a delayed input request.- Parameters:
commandSender- The user responsible for the delayed command.structureRetriever- The structure retriever as currently specified.- Returns:
- The init message for the delayed input request.
-
toString
-