Cancellable
public class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable
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:
${nearbyPlayer}
with the name of the nearest other
player, or simulating the @a
and @p
decorators used by Command Blocks in plugins that do not handle it.
/home
command in a
combat arena.
/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:
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.
Event.Result
player
Constructor | Description |
---|---|
PlayerCommandPreprocessEvent(@NotNull Player player,
@NotNull String message) |
|
PlayerCommandPreprocessEvent(@NotNull Player player,
@NotNull String message,
@NotNull Set<Player> recipients) |
Modifier and Type | Method | Description |
---|---|---|
static @NotNull HandlerList |
getHandlerList() |
|
@NotNull HandlerList |
getHandlers() |
|
@NotNull String |
getMessage() |
Gets the command that the player is attempting to send.
|
@NotNull Set<Player> |
getRecipients() |
Deprecated.
This method is provided for backward compatibility with no
guarantee to the effect of viewing or modifying the set.
|
boolean |
isCancelled() |
Gets the cancellation state of this event.
|
void |
setCancelled(boolean cancel) |
Sets the cancellation state of this event.
|
void |
setMessage(@NotNull String command) |
Sets the command that the player will send.
|
void |
setPlayer(@NotNull Player player) |
Sets the player that this command will be executed as.
|
getEventName, isAsynchronous
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getPlayer
public PlayerCommandPreprocessEvent(@NotNull @NotNull Player player, @NotNull @NotNull String message)
public boolean isCancelled()
Cancellable
isCancelled
in interface Cancellable
public void setCancelled(boolean cancel)
Cancellable
setCancelled
in interface Cancellable
cancel
- true if you wish to cancel this event@NotNull public @NotNull String getMessage()
All commands begin with a special character; implementations do not consider the first character when executing the content.
public void setMessage(@NotNull @NotNull String command) throws IllegalArgumentException
All commands begin with a special character; implementations do not consider the first character when executing the content.
command
- New message that the player will sendIllegalArgumentException
- if command is null or emptypublic void setPlayer(@NotNull @NotNull Player player) throws IllegalArgumentException
player
- New player which this event will execute asIllegalArgumentException
- if the player provided is null@NotNull @Deprecated public @NotNull Set<Player> getRecipients()
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.
@NotNull public @NotNull HandlerList getHandlers()
getHandlers
in class Event
@NotNull public static @NotNull HandlerList getHandlerList()
Copyright © 2020. All rights reserved.