Search in sources :

Example 21 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class IndividualFilesPersistenceHandlerTest method shouldSavePlayerData.

@Test
public void shouldSavePlayerData() {
    // given
    Player player = mock(Player.class);
    UUID uuid = UUID.nameUUIDFromBytes("New player".getBytes());
    given(player.getUniqueId()).willReturn(uuid);
    World world = mock(World.class);
    given(world.getName()).willReturn("player-world");
    Location location = new Location(world, 0.2, 102.25, -89.28, 3.02f, 90.13f);
    String group = "primary-grp";
    LimboPlayer limbo = new LimboPlayer(location, true, group, true, 1.2f, 0.8f);
    // when
    handler.saveLimboPlayer(player, limbo);
    // then
    File playerFile = new File(dataFolder, FileUtils.makePath("playerdata", uuid.toString(), "data.json"));
    assertThat(playerFile.exists(), equalTo(true));
// TODO ljacqu 20160711: Check contents of file
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) UUID(java.util.UUID) World(org.bukkit.World) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) File(java.io.File) Location(org.bukkit.Location) Test(org.junit.Test)

Example 22 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class LimboPersistenceTest method shouldDelegateToHandler.

@Test
public void shouldDelegateToHandler() {
    // given
    Player player = mock(Player.class);
    LimboPersistenceHandler handler = getHandler();
    LimboPlayer limbo = mock(LimboPlayer.class);
    given(handler.getLimboPlayer(player)).willReturn(limbo);
    // when
    LimboPlayer result = limboPersistence.getLimboPlayer(player);
    limboPersistence.saveLimboPlayer(player, mock(LimboPlayer.class));
    limboPersistence.removeLimboPlayer(mock(Player.class));
    // then
    assertThat(result, equalTo(limbo));
    verify(handler).getLimboPlayer(player);
    verify(handler).saveLimboPlayer(eq(player), argThat(notNullAndDifferentFrom(limbo)));
    verify(handler).removeLimboPlayer(argThat(notNullAndDifferentFrom(player)));
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Test(org.junit.Test)

Example 23 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class TeleportationServiceTest method shouldTeleportAccordingToPlayerAuthAndPlayerWorldAsFallback.

@Test
public void shouldTeleportAccordingToPlayerAuthAndPlayerWorldAsFallback() {
    // given
    given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)).willReturn(true);
    PlayerAuth auth = createAuthWithLocation();
    auth.setWorld("myWorld");
    given(bukkitService.getWorld("myWorld")).willReturn(null);
    Player player = mock(Player.class);
    given(player.isOnline()).willReturn(true);
    World world = mock(World.class);
    given(player.getWorld()).willReturn(world);
    LimboPlayer limbo = mock(LimboPlayer.class);
    Location limboLocation = mockLocation();
    given(limbo.getLocation()).willReturn(limboLocation);
    // when
    teleportationService.teleportOnLogin(player, auth, limbo);
    runSyncDelayedTask(bukkitService);
    // then
    ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);
    verify(player).teleport(locationCaptor.capture());
    assertCorrectLocation(locationCaptor.getValue(), auth, world);
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) World(org.bukkit.World) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) Test(org.junit.Test)

Example 24 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class TeleportationServiceTest method shouldNotTeleportToSpawnForOtherCaseInWorld.

@Test
public // Check that the worlds for "force spawn loc after login" are case-sensitive
void shouldNotTeleportToSpawnForOtherCaseInWorld() {
    // given
    given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(false);
    Player player = mock(Player.class);
    Location spawn = mockLocation();
    PlayerAuth auth = mock(PlayerAuth.class);
    LimboPlayer limbo = mock(LimboPlayer.class);
    Location limboLocation = mockLocation();
    // different case
    given(limboLocation.getWorld().getName()).willReturn("Forced1");
    given(limbo.getLocation()).willReturn(limboLocation);
    // when
    teleportationService.teleportOnLogin(player, auth, limbo);
    // then
    verify(player, never()).teleport(spawn);
    verifyZeroInteractions(bukkitService, spawnLoader);
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) Test(org.junit.Test)

Example 25 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class TeleportationServiceTest method shouldTeleportWithLimboPlayerIfSaveQuitLocIsDisabled.

@Test
public void shouldTeleportWithLimboPlayerIfSaveQuitLocIsDisabled() {
    // given
    given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true);
    given(settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)).willReturn(false);
    PlayerAuth auth = createAuthWithLocation();
    Player player = mock(Player.class);
    given(player.isOnline()).willReturn(true);
    LimboPlayer limbo = mock(LimboPlayer.class);
    Location location = mockLocation();
    given(limbo.getLocation()).willReturn(location);
    // when
    teleportationService.teleportOnLogin(player, auth, limbo);
    runSyncDelayedTask(bukkitService);
    // then
    verify(player).teleport(location);
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) Test(org.junit.Test)

Aggregations

LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)25 Test (org.junit.Test)17 Player (org.bukkit.entity.Player)16 Location (org.bukkit.Location)10 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)9 File (java.io.File)7 World (org.bukkit.World)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 LimboService (fr.xephi.authme.data.limbo.LimboService)2 Logger (java.util.logging.Logger)2 JsonObject (com.google.gson.JsonObject)1 DebugSectionUtils.applyToLimboPlayersMap (fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.applyToLimboPlayersMap)1 DebugSectionUtils.formatLocation (fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.formatLocation)1 LimboPlayerMatchers.hasLocation (fr.xephi.authme.data.limbo.LimboPlayerMatchers.hasLocation)1 LimboPersistence (fr.xephi.authme.data.limbo.persistence.LimboPersistence)1 LoginEvent (fr.xephi.authme.events.LoginEvent)1 DebugSectionPermissions (fr.xephi.authme.permission.DebugSectionPermissions)1 PermissionNode (fr.xephi.authme.permission.PermissionNode)1 PermissionsManager (fr.xephi.authme.permission.PermissionsManager)1