Class ServerCommandEvent

All Implemented Interfaces:
Cancellable
Direct Known Subclasses:
RemoteServerCommandEvent

public class ServerCommandEvent extends ServerEvent implements Cancellable
This event is called when a command is run by a non-player. It is called early in the command handling process, and modifications in this event (via setCommand(String)) will be shown in the behavior.

Many plugins will have no use for this event, and you should attempt to avoid using it if it is not necessary.

Some examples of valid uses for this event are:

  • Logging executed commands to a separate file
  • Variable substitution. For example, replacing ${ip:Steve} with the connection IP of the player named Steve, or simulating the @a and @p decorators used by Command Blocks for plugins that do not handle it.
  • Conditionally blocking commands belonging to other plugins.
  • Per-sender command aliases. For example, after the console runs the command /calias cr gamemode creative, the next time they run /cr, it gets replaced into /gamemode creative. (Global command aliases should be done by registering the alias.)

Examples of incorrect uses are:

  • Using this event to run command logic

If the event is cancelled, processing of the command will halt.

The state of whether or not there is a slash (/) at the beginning of the message should be preserved. If a slash is added or removed, unexpected behavior may result.

  • Constructor Details

  • Method Details

    • getCommand

      @NotNull public @NotNull String getCommand()
      Gets the command that the user is attempting to execute from the console
      Returns:
      Command the user is attempting to execute
    • setCommand

      public void setCommand(@NotNull @NotNull String message)
      Sets the command that the server will execute
      Parameters:
      message - New message that the server will execute
    • getSender

      @NotNull public @NotNull CommandSender getSender()
      Get the command sender.
      Returns:
      The sender
    • getHandlers

      @NotNull public @NotNull HandlerList getHandlers()
      Specified by:
      getHandlers in class Event
    • getHandlerList

      @NotNull public static @NotNull HandlerList getHandlerList()
    • isCancelled

      public boolean isCancelled()
      Description copied from interface: Cancellable
      Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins
      Specified by:
      isCancelled in interface Cancellable
      Returns:
      true if this event is cancelled
    • setCancelled

      public void setCancelled(boolean cancel)
      Description copied from interface: Cancellable
      Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins.
      Specified by:
      setCancelled in interface Cancellable
      Parameters:
      cancel - true if you wish to cancel this event