Search in sources :

Example 1 with AsyncPlayerChatEvent

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)));
}
Also used : Player(org.bukkit.entity.Player) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) HashSet(java.util.HashSet)

Example 2 with AsyncPlayerChatEvent

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);
}
Also used : AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) Test(org.junit.Test)

Example 3 with AsyncPlayerChatEvent

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);
}
Also used : AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) Test(org.junit.Test)

Example 4 with AsyncPlayerChatEvent

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)));
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) Test(org.junit.Test)

Example 5 with AsyncPlayerChatEvent

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);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) IEssentials(net.ess3.api.IEssentials) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent)

Aggregations

AsyncPlayerChatEvent (org.bukkit.event.player.AsyncPlayerChatEvent)8 Test (org.junit.Test)5 Player (org.bukkit.entity.Player)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 FutureTask (java.util.concurrent.FutureTask)1 IEssentials (net.ess3.api.IEssentials)1 EventHandler (org.bukkit.event.EventHandler)1 PlayerChatEvent (org.bukkit.event.player.PlayerChatEvent)1 PluginManager (org.bukkit.plugin.PluginManager)1