Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.event.player.PlayerCommandPreprocessEvent Class Reference
Inheritance diagram for org.bukkit.event.player.PlayerCommandPreprocessEvent:
org.bukkit.event.player.PlayerEvent org.bukkit.event.Cancellable org.bukkit.event.Event

Public Member Functions

 PlayerCommandPreprocessEvent (final Player player, final String message)
 
 PlayerCommandPreprocessEvent (final Player player, final String message, final Set< Player > recipients)
 
boolean isCancelled ()
 
void setCancelled (boolean cancel)
 
String getMessage ()
 
void setMessage (String command) throws IllegalArgumentException
 
void setPlayer (final Player player) throws IllegalArgumentException
 
String getFormat ()
 
void setFormat (final String format)
 
Set< PlayergetRecipients ()
 
HandlerList getHandlers ()
 
- Public Member Functions inherited from org.bukkit.event.player.PlayerEvent
 PlayerEvent (final Player who)
 
final Player getPlayer ()
 
- Public Member Functions inherited from org.bukkit.event.Event
 Event ()
 
 Event (boolean isAsync)
 
String getEventName ()
 
abstract HandlerList getHandlers ()
 
final boolean isAsynchronous ()
 

Static Public Member Functions

static HandlerList getHandlerList ()
 

Additional Inherited Members

- Protected Attributes inherited from org.bukkit.event.player.PlayerEvent
Player player
 

Detailed Description

This event is called whenever a player runs a command (by placing a slash at the start of their message). It is called early in the command handling process, and modifications in this event (via setMessage(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 ${nearbyPlayer} with the name of the nearest other player, or simulating the and decorators used by Command Blocks in plugins that do not handle it.
  • Conditionally blocking commands belonging to other plugins. For example, blocking the use of the /home command in a combat arena.
  • Per-sender command aliases. For example, after a player 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.

Definition at line 49 of file PlayerCommandPreprocessEvent.java.

Member Function Documentation

String org.bukkit.event.player.PlayerCommandPreprocessEvent.getFormat ( )

Gets the format to use to display this chat message

Deprecated:
This method is provided for backward compatibility with no guarantee to the use of the format.
Returns
String.Format compatible format string

Definition at line 122 of file PlayerCommandPreprocessEvent.java.

122  {
123  return format;
124  }
String org.bukkit.event.player.PlayerCommandPreprocessEvent.getMessage ( )

Gets the command that the player is attempting to send.

All commands begin with a special character; implementations do not consider the first character when executing the content.

Returns
Message the player is attempting to send

Definition at line 84 of file PlayerCommandPreprocessEvent.java.

84  {
85  return message;
86  }
Set<Player> org.bukkit.event.player.PlayerCommandPreprocessEvent.getRecipients ( )

Gets a set of recipients that this chat message will be displayed to.

The set returned is not guaranteed to be mutable and may auto-populate on access. Any listener accessing the returned set should be aware that it may reduce performance for a lazy set implementation. Listeners should be aware that modifying the list may throw UnsupportedOperationException if the event caller provides an unmodifiable set.

Deprecated:
This method is provided for backward compatibility with no guarantee to the effect of viewing or modifying the set.
Returns
All Players who will see this chat message

Definition at line 161 of file PlayerCommandPreprocessEvent.java.

161  {
162  return recipients;
163  }
boolean org.bukkit.event.player.PlayerCommandPreprocessEvent.isCancelled ( )

Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins

Returns
true if this event is cancelled

Implements org.bukkit.event.Cancellable.

Definition at line 68 of file PlayerCommandPreprocessEvent.java.

68  {
69  return cancel;
70  }
void org.bukkit.event.player.PlayerCommandPreprocessEvent.setCancelled ( boolean  cancel)

Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins.

Parameters
canceltrue if you wish to cancel this event

Implements org.bukkit.event.Cancellable.

Definition at line 72 of file PlayerCommandPreprocessEvent.java.

72  {
73  this.cancel = cancel;
74  }
void org.bukkit.event.player.PlayerCommandPreprocessEvent.setFormat ( final String  format)

Sets the format to use to display this chat message

Deprecated:
This method is provided for backward compatibility with no guarantee to the effect of modifying the format.
Parameters
formatString.Format compatible format string

Definition at line 134 of file PlayerCommandPreprocessEvent.java.

134  {
135  // Oh for a better way to do this!
136  try {
137  String.format(format, player, message);
138  } catch (RuntimeException ex) {
139  ex.fillInStackTrace();
140  throw ex;
141  }
142 
143  this.format = format;
144  }
void org.bukkit.event.player.PlayerCommandPreprocessEvent.setMessage ( String  command) throws IllegalArgumentException

Sets the command that the player will send.

All commands begin with a special character; implementations do not consider the first character when executing the content.

Parameters
commandNew message that the player will send
Exceptions
IllegalArgumentExceptionif command is null or empty

Definition at line 97 of file PlayerCommandPreprocessEvent.java.

97  {
98  Validate.notNull(command, "Command cannot be null");
99  Validate.notEmpty(command, "Command cannot be empty");
100  this.message = command;
101  }
void org.bukkit.event.player.PlayerCommandPreprocessEvent.setPlayer ( final Player  player) throws IllegalArgumentException

Sets the player that this command will be executed as.

Parameters
playerNew player which this event will execute as
Exceptions
IllegalArgumentExceptionif the player provided is null

Definition at line 109 of file PlayerCommandPreprocessEvent.java.

109  {
110  Validate.notNull(player, "Player cannot be null");
111  this.player = player;
112  }

The documentation for this class was generated from the following file: