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