Package studio.mevera.imperat.events
Class CommandEvent<S extends CommandSource>
java.lang.Object
studio.mevera.imperat.events.CommandEvent<S>
- Type Parameters:
S- the source type that this command supports
- All Implemented Interfaces:
Event
- Direct Known Subclasses:
CommandPostProcessEvent,CommandPostRegistrationEvent,CommandPreProcessEvent,CommandPreRegistrationEvent
Base class for all command-related events in the Imperat framework.
This abstract class provides a common foundation for events that are
associated with a specific Command instance. All command lifecycle
events (registration, execution, etc.) extend this class.
Events extending this class are guaranteed to have access to the command that triggered the event, enabling handlers to inspect command metadata, permissions, usage patterns, and other command-specific information.
Common Subclasses
CommandPreRegistrationEvent- Before command registrationCommandPostRegistrationEvent- After command registration
Example Usage
// Create a custom command event
public class CommandExecutionEvent<S extends CommandSource> extends CommandEvent<S> {
private final ExecutionContext<S> context;
public CommandExecutionEvent(RootCommand<S> command, ExecutionContext<S> context) {
super(command);
this.context = context;
}
public ExecutionContext<S> getContext() {
return context;
}
}
// Register a handler that works with any command event
eventBus.register(CommandEvent.class, event -> {
RootCommand<?> command = event.getCommand();
logger.info("RootCommand event fired for: " + command.getName());
});
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCommandEvent(Command<S> command) Constructs a new command event. -
Method Summary
Modifier and TypeMethodDescriptionGets the command associated with this event.
-
Field Details
-
command
The command associated with this event.
-
-
Constructor Details
-
CommandEvent
Constructs a new command event.- Parameters:
command- the command associated with this event
-
-
Method Details
-
getCommand
Gets the command associated with this event.- Returns:
- the command instance
-