use of org.bukkit.event.player.AsyncPlayerChatEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method newAsyncChatEvent.
private static AsyncPlayerChatEvent newAsyncChatEvent() {
Player player = mock(Player.class);
List<Player> recipients = Arrays.asList(mock(Player.class), mock(Player.class), mock(Player.class));
return spy(new AsyncPlayerChatEvent(true, player, "Test message", new HashSet<>(recipients)));
}
use of org.bukkit.event.player.AsyncPlayerChatEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldCancelChatForUnauthedPlayer.
@Test
public void shouldCancelChatForUnauthedPlayer() {
// given
given(settings.getProperty(RestrictionSettings.ALLOW_CHAT)).willReturn(false);
AsyncPlayerChatEvent event = newAsyncChatEvent();
given(listenerService.shouldCancelEvent(event.getPlayer())).willReturn(true);
// when
listener.onPlayerChat(event);
// then
verify(listenerService).shouldCancelEvent(event.getPlayer());
verify(event).setCancelled(true);
verify(messages).send(event.getPlayer(), MessageKey.DENIED_CHAT);
}
use of org.bukkit.event.player.AsyncPlayerChatEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldAllowChat.
@Test
public void shouldAllowChat() {
// given
given(settings.getProperty(RestrictionSettings.ALLOW_CHAT)).willReturn(true);
AsyncPlayerChatEvent event = mock(AsyncPlayerChatEvent.class);
// when
listener.onPlayerChat(event);
// then
verifyZeroInteractions(event, listenerService, messages);
}
use of org.bukkit.event.player.AsyncPlayerChatEvent in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldHideChatFromUnauthed.
@Test
public void shouldHideChatFromUnauthed() {
// 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(true);
List<Player> recipients = new ArrayList<>(event.getRecipients());
given(listenerService.shouldCancelEvent(recipients.get(0))).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, never()).setCancelled(anyBoolean());
assertThat(event.getRecipients(), contains(recipients.get(1), recipients.get(2)));
}
use of org.bukkit.event.player.AsyncPlayerChatEvent in project Essentials by drtshock.
the class EssentialsChat method onEnable.
@Override
public void onEnable() {
final PluginManager pluginManager = getServer().getPluginManager();
final IEssentials ess = (IEssentials) pluginManager.getPlugin("Essentials");
if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
LOGGER.log(Level.WARNING, tl("versionMismatchAll"));
}
if (!ess.isEnabled()) {
this.setEnabled(false);
return;
}
final Map<AsyncPlayerChatEvent, ChatStore> chatStore = Collections.synchronizedMap(new HashMap<AsyncPlayerChatEvent, ChatStore>());
final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatStore);
final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatStore);
final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatStore);
pluginManager.registerEvents(playerListenerLowest, this);
pluginManager.registerEvents(playerListenerNormal, this);
pluginManager.registerEvents(playerListenerHighest, this);
}
Aggregations