Class CommandPostRegistrationEvent<S extends CommandSource>

java.lang.Object
studio.mevera.imperat.events.CommandEvent<S>
studio.mevera.imperat.events.types.CommandPostRegistrationEvent<S>
Type Parameters:
S - the source type that this command supports
All Implemented Interfaces:
Event

public final class CommandPostRegistrationEvent<S extends CommandSource> extends CommandEvent<S>
Event fired after a command registration attempt completes, whether successful or failed.

This event is always fired following a CommandPreRegistrationEvent, and provides information about the outcome of the registration attempt. Unlike the pre-registration event, this event is not cancellable as the registration has already been attempted.

The event can indicate either success or failure:

Common Use Cases

  • Logging successful command registrations for audit trails
  • Handling and reporting registration failures gracefully
  • Tracking command registration metrics and statistics
  • Performing post-registration setup or initialization
  • Notifying external systems of new command availability
  • Debugging registration issues with detailed error information

Event Lifecycle

  1. CommandPreRegistrationEvent is fired (cancellable)
  2. If not cancelled, command registration is attempted
  3. CommandPostRegistrationEvent is fired with the result

Example: Success/Failure Logging


 eventBus.register(CommandPostRegistrationEvent.class, event -> {
     RootCommand<?> command = event.getCommand();

     if (event.isSuccessful()) {
         logger.info("Successfully registered command: " + command.getName());
     } else {
         logger.error("Failed to register command: " + command.getName(),
                      event.getFailureCause());
     }
 });
 

Example: Registration Metrics


 eventBus.register(CommandPostRegistrationEvent.class, event -> {
     if (event.isSuccessful()) {
         metrics.incrementSuccessfulRegistrations();
         metrics.recordCommandRegistered(event.getCommand().getName());
     } else {
         metrics.incrementFailedRegistrations();
         metrics.recordRegistrationError(event.getCommand().getName(),
                                         event.getFailureCause());
     }
 });
 

Example: Post-Registration Setup


 eventBus.register(CommandPostRegistrationEvent.class, event -> {
     if (event.isSuccessful()) {
         RootCommand<?> command = event.getCommand();

         // Perform additional setup after successful registration
         registerCommandAliases(command);
         setupCommandPermissions(command);
         notifyAdmins("New command available: " + command.getName());
     }
 });
 

Example: Error Recovery


 eventBus.register(CommandPostRegistrationEvent.class, event -> {
     if (event.isFailed()) {
         RootCommand<?> command = event.getCommand();
         Throwable cause = event.getFailureCause();

         // Attempt recovery strategies
         if (cause instanceof CommandConflictException) {
             logger.warn("RootCommand conflict for: " + command.getName() +
                         ", attempting to register with prefix");
             registerWithPrefix(command);
         } else {
             logger.error("Unrecoverable registration error", cause);
             alertAdministrators(command, cause);
         }
     }
 });
 

Example: Notification System


 eventBus.register(CommandPostRegistrationEvent.class, event -> {
     RootCommand<?> command = event.getCommand();

     if (event.isSuccessful()) {
         // Notify monitoring system
         monitoringService.recordEvent(
             "command.registered",
             Map.of(
                 "command", command.getName(),
                 "aliases", String.join(",", command.getAliases()),
                 "permission", command.getPermission()
             )
         );
     }
 }, Priority.LOWEST, ExecutionStrategy.ASYNC);
 
Since:
1.0
See Also:
  • Constructor Details

    • CommandPostRegistrationEvent

      public CommandPostRegistrationEvent(Command<S> command, @Nullable @Nullable Throwable failureCause)
      Constructs a new command post-registration event.
      Parameters:
      command - the command that was attempted to be registered
      failureCause - the exception that caused the failure, or null if successful
  • Method Details

    • isSuccessful

      public boolean isSuccessful()
      Checks if the command registration was successful.
      Returns:
      true if the command was registered successfully, false if it failed
    • isFailed

      public boolean isFailed()
      Checks if the command registration failed.
      Returns:
      true if the command registration failed, false if it was successful
    • setFailureCause

      public void setFailureCause(@Nullable @Nullable Throwable failureCause)
      Sets the exception that caused the registration to fail.
      Parameters:
      failureCause - the failure cause, or null if the registration was successful
    • getFailureCause

      @Nullable public @Nullable Throwable getFailureCause()
      Gets the exception that caused the registration to fail.
      Returns:
      the failure cause, or null if the registration was successful