Search in sources :

Example 21 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class IndividualFilesPersistenceHandlerTest method shouldReadDataFromFile.

@Test
public void shouldReadDataFromFile() {
    // given
    Player player = mock(Player.class);
    given(player.getUniqueId()).willReturn(SAMPLE_UUID);
    World world = mock(World.class);
    given(bukkitService.getWorld("nether")).willReturn(world);
    // when
    LimboPlayer data = handler.getLimboPlayer(player);
    // then
    assertThat(data, not(nullValue()));
    assertThat(data.isOperator(), equalTo(true));
    assertThat(data.isCanFly(), equalTo(true));
    assertThat(data.getWalkSpeed(), equalTo(0.2f));
    assertThat(data.getFlySpeed(), equalTo(0.1f));
    assertThat(data.getGroup(), equalTo("players"));
    Location location = data.getLocation();
    assertThat(location.getX(), equalTo(-113.219));
    assertThat(location.getY(), equalTo(72.0));
    assertThat(location.getZ(), equalTo(130.637));
    assertThat(location.getWorld(), equalTo(world));
    assertThat(location.getPitch(), equalTo(24.15f));
    assertThat(location.getYaw(), equalTo(-292.484f));
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) World(org.bukkit.World) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) Test(org.junit.Test)

Example 22 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class LimboServiceTest method shouldCreateLimboPlayer.

@Test
public void shouldCreateLimboPlayer() {
    // given
    Player player = newPlayer("Bobby", true, 0.3f, false, 0.2f);
    Location playerLoc = mock(Location.class);
    given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(playerLoc);
    given(permissionsManager.hasGroupSupport()).willReturn(true);
    given(permissionsManager.getPrimaryGroup(player)).willReturn("permgrwp");
    // when
    limboService.createLimboPlayer(player, true);
    // then
    verify(taskManager).registerMessageTask(eq(player), any(LimboPlayer.class), eq(true));
    verify(taskManager).registerTimeoutTask(eq(player), any(LimboPlayer.class));
    verify(player).setAllowFlight(false);
    verify(player).setFlySpeed(0.0f);
    verify(player).setWalkSpeed(0.0f);
    assertThat(limboService.hasLimboPlayer("Bobby"), equalTo(true));
    LimboPlayer limbo = limboService.getLimboPlayer("Bobby");
    verify(authGroupHandler).setGroup(player, limbo, AuthGroupType.REGISTERED_UNAUTHENTICATED);
    assertThat(limbo, not(nullValue()));
    assertThat(limbo.isOperator(), equalTo(true));
    assertThat(limbo.getWalkSpeed(), equalTo(0.3f));
    assertThat(limbo.isCanFly(), equalTo(false));
    assertThat(limbo.getFlySpeed(), equalTo(0.2f));
    assertThat(limbo.getLocation(), equalTo(playerLoc));
    assertThat(limbo.getGroup(), equalTo("permgrwp"));
}
Also used : Player(org.bukkit.entity.Player) Location(org.bukkit.Location) Test(org.junit.Test)

Example 23 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class SpawnLoader method getSpawnLocation.

/**
     * Return the spawn location for the given player. The source of the spawn location varies
     * depending on the spawn priority setting.
     *
     * @param player The player to retrieve the spawn point for
     *
     * @return The spawn location, or the default spawn location upon failure
     *
     * @see RestrictionSettings#SPAWN_PRIORITY
     */
public Location getSpawnLocation(Player player) {
    if (player == null || player.getWorld() == null) {
        return null;
    }
    World world = player.getWorld();
    Location spawnLoc = null;
    for (String priority : spawnPriority) {
        switch(priority.toLowerCase().trim()) {
            case "default":
                if (world.getSpawnLocation() != null) {
                    spawnLoc = world.getSpawnLocation();
                }
                break;
            case "multiverse":
                if (settings.getProperty(HooksSettings.MULTIVERSE)) {
                    spawnLoc = pluginHookService.getMultiverseSpawn(world);
                }
                break;
            case "essentials":
                spawnLoc = essentialsSpawn;
                break;
            case "authme":
                spawnLoc = getSpawn();
                break;
            default:
        }
        if (spawnLoc != null) {
            return spawnLoc;
        }
    }
    // return default location
    return world.getSpawnLocation();
}
Also used : World(org.bukkit.World) Location(org.bukkit.Location)

Example 24 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class AsynchronousQuit method processQuit.

/**
     * Processes that the given player has quit the server.
     *
     * @param player the player who left
     */
public void processQuit(Player player) {
    if (player == null || validationService.isUnrestricted(player.getName())) {
        return;
    }
    final String name = player.getName().toLowerCase();
    final boolean wasLoggedIn = playerCache.isAuthenticated(name);
    if (wasLoggedIn) {
        if (service.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION)) {
            Location loc = spawnLoader.getPlayerLocationOrSpawn(player);
            PlayerAuth auth = PlayerAuth.builder().name(name).location(loc).realName(player.getName()).build();
            database.updateQuitLoc(auth);
        }
        final String ip = PlayerUtils.getPlayerIp(player);
        PlayerAuth auth = PlayerAuth.builder().name(name).realName(player.getName()).ip(ip).lastLogin(System.currentTimeMillis()).build();
        database.updateSession(auth);
        sessionManager.addSession(name);
    }
    //always unauthenticate the player - use session only for auto logins on the same ip
    playerCache.removePlayer(name);
    //always update the database when the player quit the game
    database.setUnlogged(name);
    if (plugin.isEnabled()) {
        syncProcessManager.processSyncPlayerQuit(player, wasLoggedIn);
    }
    // remove player from cache
    if (database instanceof CacheDataSource) {
        ((CacheDataSource) database).getCachedAuths().invalidate(name);
    }
}
Also used : CacheDataSource(fr.xephi.authme.datasource.CacheDataSource) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Location(org.bukkit.Location)

Example 25 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class TeleportationService method teleportToSpawn.

private void teleportToSpawn(final Player player, final boolean isAuthenticated) {
    final Location spawnLoc = spawnLoader.getSpawnLocation(player);
    performTeleportation(player, new SpawnTeleportEvent(player, spawnLoc, isAuthenticated));
}
Also used : FirstSpawnTeleportEvent(fr.xephi.authme.events.FirstSpawnTeleportEvent) SpawnTeleportEvent(fr.xephi.authme.events.SpawnTeleportEvent) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)351 Player (org.bukkit.entity.Player)90 World (org.bukkit.World)56 EventHandler (org.bukkit.event.EventHandler)43 Test (org.junit.Test)43 Vector (org.bukkit.util.Vector)38 ArrayList (java.util.ArrayList)29 Block (org.bukkit.block.Block)18 Entity (org.bukkit.entity.Entity)17 User (com.earth2me.essentials.User)16 ItemStack (org.bukkit.inventory.ItemStack)15 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)14 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)14 List (java.util.List)12 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)11 BlockState (org.bukkit.block.BlockState)11 UUID (java.util.UUID)10 LivingEntity (org.bukkit.entity.LivingEntity)10 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)9