Search in sources :

Example 1 with PlayerLoginEvent

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

the class OnJoinVerifierTest method shouldKickNonVipForJoiningVipPlayer.

@Test
public void shouldKickNonVipForJoiningVipPlayer() {
    // given
    Player player = mock(Player.class);
    PlayerLoginEvent event = new PlayerLoginEvent(player, "hostname", null);
    event.setResult(PlayerLoginEvent.Result.KICK_FULL);
    given(permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)).willReturn(true);
    List<Player> onlinePlayers = Arrays.asList(mock(Player.class), mock(Player.class));
    given(permissionsManager.hasPermission(onlinePlayers.get(0), PlayerStatePermission.IS_VIP)).willReturn(true);
    given(permissionsManager.hasPermission(onlinePlayers.get(1), PlayerStatePermission.IS_VIP)).willReturn(false);
    returnOnlineListFromBukkitServer(onlinePlayers);
    given(server.getMaxPlayers()).willReturn(onlinePlayers.size());
    given(messages.retrieveSingle(MessageKey.KICK_FOR_VIP)).willReturn("kick for vip");
    // when
    boolean result = onJoinVerifier.refusePlayerForFullServer(event);
    // then
    assertThat(result, equalTo(false));
    assertThat(event.getResult(), equalTo(PlayerLoginEvent.Result.ALLOWED));
    // First player is VIP, so expect no interactions there and second player to have been kicked
    verifyZeroInteractions(onlinePlayers.get(0));
    verify(onlinePlayers.get(1)).kickPlayer("kick for vip");
}
Also used : Player(org.bukkit.entity.Player) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) Test(org.junit.Test)

Example 2 with PlayerLoginEvent

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

the class OnJoinVerifierTest method shouldKickVipPlayerIfNoPlayerCanBeKicked.

@Test
public void shouldKickVipPlayerIfNoPlayerCanBeKicked() {
    // given
    Player player = mock(Player.class);
    PlayerLoginEvent event = new PlayerLoginEvent(player, "hostname", null);
    event.setResult(PlayerLoginEvent.Result.KICK_FULL);
    given(permissionsManager.hasPermission(player, PlayerStatePermission.IS_VIP)).willReturn(true);
    List<Player> onlinePlayers = Collections.singletonList(mock(Player.class));
    given(permissionsManager.hasPermission(onlinePlayers.get(0), PlayerStatePermission.IS_VIP)).willReturn(true);
    returnOnlineListFromBukkitServer(onlinePlayers);
    given(server.getMaxPlayers()).willReturn(onlinePlayers.size());
    given(messages.retrieveSingle(MessageKey.KICK_FULL_SERVER)).willReturn("kick full server");
    // when
    boolean result = onJoinVerifier.refusePlayerForFullServer(event);
    // then
    assertThat(result, equalTo(true));
    assertThat(event.getResult(), equalTo(PlayerLoginEvent.Result.KICK_FULL));
    assertThat(event.getKickMessage(), equalTo("kick full server"));
    verifyZeroInteractions(onlinePlayers.get(0));
}
Also used : Player(org.bukkit.entity.Player) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) Test(org.junit.Test)

Example 3 with PlayerLoginEvent

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

the class PlayerListenerTest method shouldNotInterfereWithUnrestrictedUser.

@Test
public void shouldNotInterfereWithUnrestrictedUser() {
    // given
    String name = "Player01";
    Player player = mockPlayerWithName(name);
    PlayerLoginEvent event = spy(new PlayerLoginEvent(player, "", null));
    given(validationService.isUnrestricted(name)).willReturn(true);
    // when
    listener.onPlayerLogin(event);
    // then
    verify(validationService).isUnrestricted(name);
    verifyNoModifyingCalls(event);
    verifyZeroInteractions(onJoinVerifier);
}
Also used : Player(org.bukkit.entity.Player) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with PlayerLoginEvent

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

the class PlayerListenerTest method shouldStopHandlingForFullServer.

@Test
public void shouldStopHandlingForFullServer() {
    // given
    String name = "someone";
    Player player = mockPlayerWithName(name);
    PlayerLoginEvent event = spy(new PlayerLoginEvent(player, "", null));
    given(validationService.isUnrestricted(name)).willReturn(false);
    given(onJoinVerifier.refusePlayerForFullServer(event)).willReturn(true);
    // when
    listener.onPlayerLogin(event);
    // then
    verify(validationService).isUnrestricted(name);
    verify(onJoinVerifier, only()).refusePlayerForFullServer(event);
    verifyNoModifyingCalls(event);
}
Also used : Player(org.bukkit.entity.Player) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 5 with PlayerLoginEvent

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

the class PlayerListenerTest method shouldStopHandlingEventForBadResult.

@Test
public void shouldStopHandlingEventForBadResult() {
    // given
    String name = "someone";
    Player player = mockPlayerWithName(name);
    PlayerLoginEvent event = new PlayerLoginEvent(player, "", null);
    event.setResult(PlayerLoginEvent.Result.KICK_BANNED);
    event = spy(event);
    given(validationService.isUnrestricted(name)).willReturn(false);
    given(onJoinVerifier.refusePlayerForFullServer(event)).willReturn(false);
    // when
    listener.onPlayerLogin(event);
    // then
    verify(validationService).isUnrestricted(name);
    verify(onJoinVerifier, only()).refusePlayerForFullServer(event);
    verifyNoModifyingCalls(event);
}
Also used : Player(org.bukkit.entity.Player) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

PlayerLoginEvent (org.bukkit.event.player.PlayerLoginEvent)11 Test (org.junit.Test)9 Player (org.bukkit.entity.Player)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 GlowPlayer (net.glowstone.entity.GlowPlayer)2 UserListItemMessage (net.glowstone.net.message.play.game.UserListItemMessage)2 AsyncableMessage (com.flowpowered.network.AsyncableMessage)1 Message (com.flowpowered.network.Message)1 Message (com.flowpowered.networking.Message)1 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)1 ArrayList (java.util.ArrayList)1 PlayerDataService (net.glowstone.io.PlayerDataService)1 PlayerReader (net.glowstone.io.PlayerDataService.PlayerReader)1 KickMessage (net.glowstone.net.message.KickMessage)1 SetCompressionMessage (net.glowstone.net.message.SetCompressionMessage)1 LoginSuccessMessage (net.glowstone.net.message.login.LoginSuccessMessage)1 DestroyEntitiesMessage (net.glowstone.net.message.play.entity.DestroyEntitiesMessage)1 PingMessage (net.glowstone.net.message.play.game.PingMessage)1 Entry (net.glowstone.net.message.play.game.UserListItemMessage.Entry)1 BlockPlacementMessage (net.glowstone.net.message.play.player.BlockPlacementMessage)1