Package org.bukkit.event.server
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
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bukkit.event.Event
Event.Result
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGets the command that the user is attempting to execute from the consolestatic HandlerList
Get the command sender.boolean
Gets the cancellation state of this event.void
setCancelled
(boolean cancel) Sets the cancellation state of this event.void
setCommand
(String message) Sets the command that the server will executeMethods inherited from class org.bukkit.event.Event
getEventName, isAsynchronous
-
Constructor Details
-
ServerCommandEvent
-
-
Method Details
-
getCommand
Gets the command that the user is attempting to execute from the console- Returns:
- Command the user is attempting to execute
-
setCommand
Sets the command that the server will execute- Parameters:
message
- New message that the server will execute
-
getSender
Get the command sender.- Returns:
- The sender
-
getHandlers
- Specified by:
getHandlers
in classEvent
-
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 interfaceCancellable
- 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 interfaceCancellable
- Parameters:
cancel
- true if you wish to cancel this event
-