Cancellable
public class AsyncPlayerChatEvent extends PlayerEvent implements Cancellable
The constructor provides a boolean to indicate if the event was fired synchronously or asynchronously. When asynchronous, this event can be called from any thread, sans the main thread, and has limited access to the API.
If a player is the direct cause of this event by an incoming packet, this event will be asynchronous. If a plugin triggers this event by compelling a player to chat, this event will be synchronous.
Care should be taken to check Event.isAsynchronous()
and treat the event
appropriately.
Event.Result
player
Constructor | Description |
---|---|
AsyncPlayerChatEvent(boolean async,
@NotNull Player who,
@NotNull String message,
@NotNull Set<Player> players) |
Modifier and Type | Method | Description |
---|---|---|
@NotNull String |
getFormat() |
Gets the format to use to display this chat message.
|
static @NotNull HandlerList |
getHandlerList() |
|
@NotNull HandlerList |
getHandlers() |
|
@NotNull String |
getMessage() |
Gets the message that the player is attempting to send.
|
@NotNull Set<Player> |
getRecipients() |
Gets a set of recipients that this chat message will be displayed to.
|
boolean |
isCancelled() |
Gets the cancellation state of this event.
|
void |
setCancelled(boolean cancel) |
Sets the cancellation state of this event.
|
void |
setFormat(@NotNull String format) |
Sets the format to use to display this chat message.
|
void |
setMessage(@NotNull String message) |
Sets the message that the player will send.
|
callEvent, getEventName, isAsynchronous
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getPlayer
public AsyncPlayerChatEvent(boolean async, @NotNull @NotNull Player who, @NotNull @NotNull String message, @NotNull @NotNull Set<Player> players)
async
- This changes the event to a synchronous state.who
- the chat sendermessage
- the message sentplayers
- the players to receive the message. This may be a lazy
or unmodifiable collection.@NotNull public @NotNull String getMessage()
getFormat()
.public void setMessage(@NotNull @NotNull String message)
getFormat()
.message
- New message that the player will send@NotNull public @NotNull String getFormat()
When this event finishes execution, the first format parameter is the
Player.getDisplayName()
and the second parameter is getMessage()
String.format(String, Object...)
compatible format
stringpublic void setFormat(@NotNull @NotNull String format) throws IllegalFormatException, NullPointerException
When this event finishes execution, the first format parameter is the
Player.getDisplayName()
and the second parameter is getMessage()
format
- String.format(String, Object...)
compatible
format stringIllegalFormatException
- if the underlying API throws the
exceptionNullPointerException
- if format is nullString.format(String, Object...)
@NotNull 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.
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 HandlerList getHandlers()
getHandlers
in class Event
@NotNull public static @NotNull HandlerList getHandlerList()
Copyright © 2020. All rights reserved.