Class ServerCommandEvent

java.lang.Object
org.bukkit.event.Event
org.bukkit.event.server.ServerEvent
org.bukkit.event.server.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 from the server console. 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.

  • Nested Class Summary

    Nested classes/interfaces inherited from class org.bukkit.event.Event

    Event.Result
  • Constructor Summary

    Constructors 
    Constructor Description
    ServerCommandEvent​(CommandSender sender, java.lang.String command)  
  • Method Summary

    Modifier and Type Method Description
    java.lang.String getCommand()
    Gets the command that the user is attempting to execute from the console
    static HandlerList getHandlerList()  
    HandlerList getHandlers()  
    CommandSender getSender()
    Get the command sender.
    boolean isCancelled()
    Gets the cancellation state of this event.
    void setCancelled​(boolean cancel)
    Sets the cancellation state of this event.
    void setCommand​(java.lang.String message)
    Sets the command that the server will execute

    Methods inherited from class org.bukkit.event.Event

    getEventName, isAsynchronous

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getCommand

      public java.lang.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​(java.lang.String message)
      Sets the command that the server will execute
      Parameters:
      message - New message that the server will execute
    • getSender

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

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

      public static 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