Class CommandConfirmationManager<C>

  • Type Parameters:
    C - Command sender type

    public class CommandConfirmationManager<C>
    extends java.lang.Object
    Manager for the command confirmation system that enables the ability to add "confirmation" requirements to commands, such that they need to be confirmed in order to be executed.

    To use the confirmation system, the confirmation post processor needs to be added. To to this, use registerConfirmationProcessor(CommandManager). After this is done, a confirmation command has been added. To do this, create a command builder and attach createConfirmationExecutionHandler().

    To require a command to be confirmed, use decorate(SimpleCommandMeta.Builder) on the command meta builder.

    • Field Detail

      • CONFIRMATION_REQUIRED_META

        public static final java.lang.String CONFIRMATION_REQUIRED_META
        Meta data stored for commands that require confirmation
        See Also:
        Constant Field Values
    • Constructor Detail

      • CommandConfirmationManager

        public CommandConfirmationManager​(long timeout,
                                          @NonNull java.util.concurrent.TimeUnit timeoutTimeUnit,
                                          @NonNull java.util.function.Consumer<@NonNull CommandPostprocessingContext<C>> notifier,
                                          @NonNull java.util.function.Consumer<@NonNull C> errorNotifier)
        Create a new confirmation manager instance
        Parameters:
        timeout - Timeout value
        timeoutTimeUnit - Timeout time unit
        notifier - Notifier that gets called when a command gets added to the queue
        errorNotifier - Notifier that gets called when someone tries to confirm a command with nothing in the queue
    • Method Detail

      • getPending

        public @NonNull java.util.Optional<CommandPostprocessingContext<C>> getPending​(@NonNull C sender)
        Get a pending context if one is stored for the sender
        Parameters:
        sender - Sender
        Returns:
        Optional containing the post processing context if one has been stored, else Optional.empty()
      • decorate

        public @NonNull SimpleCommandMeta.Builder decorate​(@NonNull SimpleCommandMeta.Builder builder)
        Decorate a simple command meta builder, to require confirmation for a command
        Parameters:
        builder - Command meta builder
        Returns:
        Builder instance
      • registerConfirmationProcessor

        public void registerConfirmationProcessor​(@NonNull CommandManager<C> manager)
        Register the confirmation processor in the command manager
        Parameters:
        manager - Command manager
      • createConfirmationExecutionHandler

        public @NonNull CommandExecutionHandler<C> createConfirmationExecutionHandler()
        Create an execution handler for a confirmation command
        Returns:
        Handler for a confirmation command