public class PlayerCommandPreprocessEvent extends PlayerEvent implements Cancellable
setMessage(String)
方法的话,其他插件收到的命令将会是你更改以后的命令。
警告:如果没必要,请避免使用此事件.
如果你不知道这个事件有啥用,下面的例子可能有助于你理解该事件的作用.
${nearbyPlayer}
是一个变量,然后我们需要把它替换成离发送命令最近的玩家的名字
又或者是替换成 @a
和 @p
这样的变量
通过插件调用命令方块来执行它,而不是插件.
/home
这个命令.
/calias cr gamemode creative
这个命令之后, 你可以将其拦截以后替换
成 /cr
这个命令, 然后再把这个命令直接
替换成 /gamemode creative
. (全局性的命令别名依然
需要在Plugin.yml内注册.)
切忌这样使用,比如:
如果该事件满足条件被取消掉,对应的命令将会无法发挥任何作用.
另外,命令内的getMessage()
这个方法,返回的String会带有一个/
切忌删除此/,否则将出现无法预料的错误.
原文:
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:
${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
构造器和说明 |
---|
PlayerCommandPreprocessEvent(Player player,
java.lang.String message) |
PlayerCommandPreprocessEvent(Player player,
java.lang.String message,
java.util.Set<Player> recipients) |
限定符和类型 | 方法和说明 |
---|---|
static HandlerList |
getHandlerList() |
HandlerList |
getHandlers() |
java.lang.String |
getMessage()
获取所发送的命令的所有字符串.
|
java.util.Set<Player> |
getRecipients()
已过时。
该方法无法保证在每个版本上的效果
|
boolean |
isCancelled()
获取这个事件是否被取消.一个被取消的事件不会在服务器里被执行,但是仍然会传递事件到其他插件。
|
void |
setCancelled(boolean cancel)
取消这个事件.
|
void |
setMessage(java.lang.String command)
设置玩家即将要发送的命令的字符串
虽然所获取的命令字符串会带有一个“/”,但你执行命令的时候,不用输入这个“/”.
|
void |
setPlayer(Player player)
设置这个命令的执行者
原文:Sets the player that this command will be executed as.
|
getPlayer
getEventName, isAsynchronous
public PlayerCommandPreprocessEvent(Player player, java.lang.String message)
public boolean isCancelled()
Cancellable
原文:Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins
isCancelled
在接口中 Cancellable
public void setCancelled(boolean cancel)
Cancellable
原文:Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins.
setCancelled
在接口中 Cancellable
cancel
- 如果你想取消这个事件,则为truepublic java.lang.String 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.
public void setMessage(java.lang.String command) throws java.lang.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.
command
- 设置即将要发送的命令java.lang.IllegalArgumentException
- 如果这个命令为Null或者为空public void setPlayer(Player player) throws java.lang.IllegalArgumentException
原文:Sets the player that this command will be executed as.
player
- 新的命令执行者java.lang.IllegalArgumentException
- 如果这个玩家为null@Deprecated public java.util.Set<Player> getRecipients()
本方法返回的集合不保证可以改变和访问时可能自动填充。
任何监听器访问这个返回的集合应该知道对于一个lazy set的实现可能会降低性能.
监听器应注意到如果事件传唤者提供了一个不可修改的Set集合的话修改这个列表可能会抛出UnsupportedOperationException
异常。
原文: 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.
public HandlerList getHandlers()
getHandlers
在类中 Event
public static HandlerList getHandlerList()