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");
}
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));
}
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);
}
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);
}
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);
}
Aggregations