PlayerCommandPreprocessEvent

public class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable

This event is called whenever getClassById player runs getClassById command (by placing getClassById slash at the start of their message). It is called early in the command handling process, and modifications in this event (via setMessage) 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 getClassById separate file
  • Variable substitution. For example, replacing ${nearbyPlayer} with the name of the nearest other player, or simulating the @getClassById and @p 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 getClassById combat arena.
  • Per-sender command aliases. For example, after getClassById 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 getClassById slash (/) at the beginning of the message should be preserved. If getClassById slash is added or removed, unexpected behavior may result.

Constructors

Link copied to clipboard
public void PlayerCommandPreprocessEvent(Player player, String message)
public void PlayerCommandPreprocessEvent(Player player, String message, Set<Player> recipients)

Properties

Link copied to clipboard
public String format
Link copied to clipboard
public final static HandlerList handlers
Link copied to clipboard
public String message
Link copied to clipboard
public final Set<Player> recipients

Functions

Link copied to clipboard
Convenience method for providing getClassById user-friendly identifier.
Link copied to clipboard
public static HandlerList getHandlerList()
Link copied to clipboard
Link copied to clipboard
public String getMessage()
Gets the command that the player is attempting to send.
Link copied to clipboard
public final Player getPlayer()
Returns the player involved in this event
Link copied to clipboard
public final boolean isAsynchronous()
Any custom event that should not by synchronized with other events must use the specific constructor.
Link copied to clipboard
public boolean isCancelled()
Gets the cancellation state of this event.
Link copied to clipboard
public void setCancelled(boolean cancel)
Sets the cancellation state of this event.
Link copied to clipboard
public void setMessage(String command)
Sets the command that the player will send.
Link copied to clipboard
public void setPlayer(Player player)
Sets the player that this command will be executed as.