001 package org.bukkit.event.server; 002 003 import org.bukkit.command.CommandSender; 004 import org.bukkit.event.HandlerList; 005 006 /** 007 * This event is called when a command is run from the server console. It is 008 * called early in the command handling process, and modifications in this 009 * event (via {@link #setCommand(String)}) will be shown in the behavior. 010 * <p> 011 * Many plugins will have <b>no use for this event</b>, and you should 012 * attempt to avoid using it if it is not necessary. 013 * <p> 014 * Some examples of valid uses for this event are: 015 * <ul> 016 * <li>Logging executed commands to a separate file 017 * <li>Variable substitution. For example, replacing <code>${ip:Steve}</code> 018 * with the connection IP of the player named Steve, or simulating the 019 * <code>@a</code> and <code>@p</code> decorators used by Command Blocks 020 * for plugins that do not handle it. 021 * <li>Conditionally blocking commands belonging to other plugins. 022 * <li>Per-sender command aliases. For example, after the console runs the 023 * command <code>/calias cr gamemode creative</code>, the next time they 024 * run <code>/cr</code>, it gets replaced into 025 * <code>/gamemode creative</code>. (Global command aliases should be 026 * done by registering the alias.) 027 * </ul> 028 * <p> 029 * Examples of incorrect uses are: 030 * <ul> 031 * <li>Using this event to run command logic 032 * </ul> 033 * <p> 034 * If the event is cancelled, processing of the command will halt. 035 * <p> 036 * The state of whether or not there is a slash (<code>/</code>) at the 037 * beginning of the message should be preserved. If a slash is added or 038 * removed, unexpected behavior may result. 039 */ 040 public class ServerCommandEvent extends ServerEvent { 041 private static final HandlerList handlers = new HandlerList(); 042 private String command; 043 private final CommandSender sender; 044 045 public ServerCommandEvent(final CommandSender sender, final String command) { 046 this.command = command; 047 this.sender = sender; 048 } 049 050 /** 051 * Gets the command that the user is attempting to execute from the 052 * console 053 * 054 * @return Command the user is attempting to execute 055 */ 056 public String getCommand() { 057 return command; 058 } 059 060 /** 061 * Sets the command that the server will execute 062 * 063 * @param message New message that the server will execute 064 */ 065 public void setCommand(String message) { 066 this.command = message; 067 } 068 069 /** 070 * Get the command sender. 071 * 072 * @return The sender 073 */ 074 public CommandSender getSender() { 075 return sender; 076 } 077 078 @Override 079 public HandlerList getHandlers() { 080 return handlers; 081 } 082 083 public static HandlerList getHandlerList() { 084 return handlers; 085 } 086 }