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
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:
- Success:
isSuccessful()returnstrue,getFailureCause()returnsnull - Failure:
isFailed()returnstrue,getFailureCause()contains the exception
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
CommandPreRegistrationEventis fired (cancellable)- If not cancelled, command registration is attempted
CommandPostRegistrationEventis 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:
-
Field Summary
Fields inherited from class studio.mevera.imperat.events.CommandEvent
command -
Constructor Summary
ConstructorsConstructorDescriptionCommandPostRegistrationEvent(Command<S> command, @Nullable Throwable failureCause) Constructs a new command post-registration event. -
Method Summary
Modifier and TypeMethodDescription@Nullable ThrowableGets the exception that caused the registration to fail.booleanisFailed()Checks if the command registration failed.booleanChecks if the command registration was successful.voidsetFailureCause(@Nullable Throwable failureCause) Sets the exception that caused the registration to fail.Methods inherited from class studio.mevera.imperat.events.CommandEvent
getCommand
-
Constructor Details
-
CommandPostRegistrationEvent
Constructs a new command post-registration event.- Parameters:
command- the command that was attempted to be registeredfailureCause- the exception that caused the failure, ornullif successful
-
-
Method Details
-
isSuccessful
public boolean isSuccessful()Checks if the command registration was successful.- Returns:
trueif the command was registered successfully,falseif it failed
-
isFailed
public boolean isFailed()Checks if the command registration failed.- Returns:
trueif the command registration failed,falseif it was successful
-
setFailureCause
Sets the exception that caused the registration to fail.- Parameters:
failureCause- the failure cause, ornullif the registration was successful
-
getFailureCause
Gets the exception that caused the registration to fail.- Returns:
- the failure cause, or
nullif the registration was successful
-