Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
ServerCommandEvent.java
1 package org.bukkit.event.server;
2 
5 
6 /**
7  * This event is called when a command is run from the server console. It is
8  * called early in the command handling process, and modifications in this
9  * event (via {@link #setCommand(String)}) will be shown in the behavior.
10  * <p>
11  * Many plugins will have <b>no use for this event</b>, and you should
12  * attempt to avoid using it if it is not necessary.
13  * <p>
14  * Some examples of valid uses for this event are:
15  * <ul>
16  * <li>Logging executed commands to a separate file
17  * <li>Variable substitution. For example, replacing <code>${ip:Steve}</code>
18  * with the connection IP of the player named Steve, or simulating the
19  * <code>@a</code> and <code>@p</code> decorators used by Command Blocks
20  * for plugins that do not handle it.
21  * <li>Conditionally blocking commands belonging to other plugins.
22  * <li>Per-sender command aliases. For example, after the console runs the
23  * command <code>/calias cr gamemode creative</code>, the next time they
24  * run <code>/cr</code>, it gets replaced into
25  * <code>/gamemode creative</code>. (Global command aliases should be
26  * done by registering the alias.)
27  * </ul>
28  * <p>
29  * Examples of incorrect uses are:
30  * <ul>
31  * <li>Using this event to run command logic
32  * </ul>
33  * <p>
34  * If the event is cancelled, processing of the command will halt.
35  * <p>
36  * The state of whether or not there is a slash (<code>/</code>) at the
37  * beginning of the message should be preserved. If a slash is added or
38  * removed, unexpected behavior may result.
39  */
40 public class ServerCommandEvent extends ServerEvent {
41  private static final HandlerList handlers = new HandlerList();
42  private String command;
43  private final CommandSender sender;
44 
45  public ServerCommandEvent(final CommandSender sender, final String command) {
46  this.command = command;
47  this.sender = sender;
48  }
49 
50  /**
51  * Gets the command that the user is attempting to execute from the
52  * console
53  *
54  * @return Command the user is attempting to execute
55  */
56  public String getCommand() {
57  return command;
58  }
59 
60  /**
61  * Sets the command that the server will execute
62  *
63  * @param message New message that the server will execute
64  */
65  public void setCommand(String message) {
66  this.command = message;
67  }
68 
69  /**
70  * Get the command sender.
71  *
72  * @return The sender
73  */
75  return sender;
76  }
77 
78  @Override
79  public HandlerList getHandlers() {
80  return handlers;
81  }
82 
83  public static HandlerList getHandlerList() {
84  return handlers;
85  }
86 }