Search in sources :

Example 6 with PlayerCommandPreprocessEvent

use of org.bukkit.event.player.PlayerCommandPreprocessEvent in project AuthMeReloaded by AuthMe.

the class PlayerListenerTest method shouldNotCancelEventForAuthenticatedPlayer.

@Test
public void shouldNotCancelEventForAuthenticatedPlayer() {
    // given
    given(settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)).willReturn(false);
    given(settings.getProperty(RestrictionSettings.ALLOW_COMMANDS)).willReturn(Collections.emptyList());
    Player player = playerWithMockedServer();
    // PlayerCommandPreprocessEvent#getPlayer is final, so create a spy instead of a mock
    PlayerCommandPreprocessEvent event = spy(new PlayerCommandPreprocessEvent(player, "/hub"));
    given(listenerService.shouldCancelEvent(player)).willReturn(false);
    // when
    listener.onPlayerCommandPreprocess(event);
    // then
    verify(event).getMessage();
    verifyNoMoreInteractions(event);
    verify(listenerService).shouldCancelEvent(player);
    verifyZeroInteractions(messages);
}
Also used : PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) Player(org.bukkit.entity.Player) Test(org.junit.Test)

Aggregations

PlayerCommandPreprocessEvent (org.bukkit.event.player.PlayerCommandPreprocessEvent)6 Test (org.junit.Test)4 Player (org.bukkit.entity.Player)3 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 PlayerHelper (net.aufdemrand.denizen.nms.interfaces.PlayerHelper)1 Element (net.aufdemrand.denizencore.objects.Element)1 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)1 ServerCommandEvent (org.bukkit.event.server.ServerCommandEvent)1