BroadcastMessageEvent
BroadcastMessageEvent
=> org.bukkit.event.Event
=> org.bukkit.event.server.ServerEvent
=> org.bukkit.event.server.BroadcastMessageEvent
Event triggered for server broadcast messages such as from{@link org.bukkit.Server#broadcast(String, String)}.This event behaves similarly to {@link AsyncPlayerChatEvent} in that itshould be async if fired from an async thread. Please see that event forfurther information.当服务器内有广播消息时触发,如插件调用org.bukkit.Server#broadcast(String, String)
方法时。本事件与AsyncPlayerChatEvent
类似。当本事件在异步线程内被触发时,监听器就在异步线程中被调用。详情请参见AsyncPlayerChatEvent
文档。译注:参见AsyncPlayerChatEvent
。
方法声明: public String getMessage()
方法签名: ()Ljava/lang/String;
Get the message to broadcast.@return Message to broadcast该方法用于获取将要被广播的消息。@return 将要被广播的消息。
方法声明: public void setMessage(@NotNull String message)
方法签名: (Ljava/lang/String;)V
Set the message to broadcast.@param message New message to broadcast该方法用于设置将要被广播的消息。@param message 将要被广播的消息。
方法声明: public Set getRecipients()
方法签名: ()Ljava/util/Set;
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-populateon access. Any listener accessing the returned set should be aware thatit may reduce performance for a lazy set implementation.Listeners should be aware that modifying the list may throw {@linkUnsupportedOperationException} if the event caller provides anunmodifiable set.@return All CommandSenders who will see this chat message该方法用于获取一个Set
,其间存储有全部将要接收该条广播消息的对象。本方法返回的Set
不一定是可以修改的,而且有可能在用户从其间取出值时进行自动填充。使用本方法返回的Set
时需要注意,如果该Set
实现类采用某种Lazy Set
实现,则监听器的性能可能会受影响。使用时还需要注意,如果触发本事件的开发者提供了一个不可修改的集合,则对返回的Set
作修改会抛出UnsupportedOperationException
。@return 全部将要接收该条广播消息的CommandSender
对象。译注:文档字里行间强调的核心内容只有一点,即本事件很有可能不是由服务端所触发,而是被插件所触发。如果本 事件并非服务端所触发,而是插件所触发,则就本方法返回的集合而言,Bukkit API
只能保证其实现类是java.util.Set
的子类,但不能保证它可否修改,也不能保证它是不是Lazy Set
。所谓不可修改集合,即不能向其中添加删除元素。监听器只能遍历其中元素,不能通过修改Set
的方式添加或删除一个接收广播消息的对象,否则会抛出UnsupportedOperationException
。所谓Lazy Set
,指的是该Set
对于性能低、开销大的方法尽可能地推迟运行。比如向Set
中添加元素的方法(假设它名为add
方法),开销比较大(有时候集合元素已满,需要对集合进行扩容才能装得下新元素,这种操作开销非常大)。那么 在调用add
方法时,不去立刻添加元素,而是先暂存新元素,推迟运行添加操作。等到要遍历集合的时候,由于再作推迟会影响读取结果,所以不得不把元素添加进集合。因此,文档中说读取集合会影响性能,就是指Lazy Set
把添加元素的方法一直推迟,直到监听器内读取Set
中的元素时才将元素添加进去。那么读取时就产生了比较大的开销。可参见AsyncPlayerChatEvent#getRecipients()
方法的译注,其内介绍了Bukkit
系列服务端中的一种LazySet
实现。
方法声明: public boolean isCancelled()
方法签名: ()Z
方法声明: public void setCancelled(boolean cancelled)
方法签名: (Z)V
方法声明: public HandlerList getHandlers()
方法签名: ()Lorg/bukkit/event/HandlerList;
方法声明: public static HandlerList getHandlerList()
方法签名: ()Lorg/bukkit/event/HandlerList;
Last modified 1mo ago