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

public abstract class CommandEvent<S extends CommandSource> extends Object implements Event
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

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());
 });
 
Since:
1.0
See Also:
  • Field Details

    • command

      protected final Command<S extends CommandSource> command
      The command associated with this event.
  • Constructor Details

    • CommandEvent

      protected CommandEvent(Command<S> command)
      Constructs a new command event.
      Parameters:
      command - the command associated with this event
  • Method Details

    • getCommand

      public Command<S> getCommand()
      Gets the command associated with this event.
      Returns:
      the command instance