use of org.bukkit.event.player.AsyncPlayerChatEvent 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);
}
}
use of org.bukkit.event.player.AsyncPlayerChatEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldCancelChatEventForNoRemainingRecipients.
@Test
public void shouldCancelChatEventForNoRemainingRecipients() {
// given
given(settings.getProperty(RestrictionSettings.ALLOW_CHAT)).willReturn(false);
AsyncPlayerChatEvent event = newAsyncChatEvent();
given(listenerService.shouldCancelEvent(any(Player.class))).willReturn(true);
given(listenerService.shouldCancelEvent(event.getPlayer())).willReturn(false);
given(settings.getProperty(RestrictionSettings.HIDE_CHAT)).willReturn(true);
// when
listener.onPlayerChat(event);
// then
verify(listenerService).shouldCancelEvent(event.getPlayer());
// message sender + 3 recipients = 4
verify(listenerService, times(4)).shouldCancelEvent(any(Player.class));
verify(event).setCancelled(true);
assertThat(event.getRecipients(), empty());
}
use of org.bukkit.event.player.AsyncPlayerChatEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldSendChatToEveryone.
@Test
public void shouldSendChatToEveryone() {
// given
given(settings.getProperty(RestrictionSettings.ALLOW_CHAT)).willReturn(false);
AsyncPlayerChatEvent event = newAsyncChatEvent();
given(listenerService.shouldCancelEvent(event.getPlayer())).willReturn(false);
given(settings.getProperty(RestrictionSettings.HIDE_CHAT)).willReturn(false);
// when
listener.onPlayerChat(event);
// then
verify(listenerService).shouldCancelEvent(event.getPlayer());
verifyZeroInteractions(event, messages);
}
Aggregations