use of org.bukkit.event.player.PlayerChatEvent in project Denizen-For-Bukkit by DenizenScript.
the class ChatTrigger method asyncChatTrigger.
@EventHandler
public void asyncChatTrigger(final AsyncPlayerChatEvent event) {
if (HyperDebug) {
dB.log("Chat trigger seen, cancelled: " + event.isCancelled() + ", chatasync: " + Settings.chatAsynchronous());
}
if (event.isCancelled()) {
return;
}
// Return if "Use asynchronous event" is false in config file
if (!Settings.chatAsynchronous()) {
return;
}
if (!event.isAsynchronous()) {
syncChatTrigger(new PlayerChatEvent(event.getPlayer(), event.getMessage(), event.getFormat(), event.getRecipients()));
return;
}
FutureTask<ChatContext> futureTask = new FutureTask<ChatContext>(new Callable<ChatContext>() {
@Override
public ChatContext call() {
return process(event.getPlayer(), event.getMessage());
}
});
Bukkit.getScheduler().runTask(DenizenAPI.getCurrentInstance(), futureTask);
try {
ChatContext context = futureTask.get();
if (context.wasTriggered()) {
event.setCancelled(true);
}
if (context.hasChanges()) {
event.setMessage(context.getChanges());
}
} catch (Exception e) {
dB.echoError(e);
}
}
Aggregations