package org.bukkit.event.player; import java.util.IllegalFormatException; import java.util.Set; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; /** * This event will sometimes fire synchronously, depending on how it was * triggered. *
* 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, but the main thread, and has limited access to the * API. *
* If a player is the direct cause of this event by 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 {@link #isAsynchronous()} and treat the event
* appropriately.
*/
public class AsyncPlayerChatEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private String message;
private String format = "<%1$s> %2$s";
private final Set
* When this event finishes execution, the first format parameter is the
* {@link Player#getDisplayName()} and the second parameter is {@link
* #getMessage()}
*
* @return {@link String#format(String, Object...)} compatible format
* string
*/
public String getFormat() {
return format;
}
/**
* Sets the format to use to display this chat message.
*
* When this event finishes execution, the first format parameter is the
* {@link Player#getDisplayName()} and the second parameter is {@link
* #getMessage()}
*
* @param format {@link String#format(String, Object...)} compatible
* format string
* @throws IllegalFormatException if the underlying API throws the
* exception
* @throws NullPointerException if format is null
* @see String#format(String, Object...)
*/
public void setFormat(final String format) throws IllegalFormatException, NullPointerException {
// Oh for a better way to do this!
try {
String.format(format, player, message);
} catch (RuntimeException ex) {
ex.fillInStackTrace();
throw ex;
}
this.format = format;
}
/**
* 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 {@link
* UnsupportedOperationException} if the event caller provides an
* unmodifiable set.
*
* @return All Players who will see this chat message
*/
public Set