Search in sources :

Example 16 with LimboPlayer

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

the class DistributedFilesPersistenceHandler method convertOldDataToCurrentSegmentScheme.

/**
     * Loads segment files in the cache folder that don't correspond to the current segmenting scheme
     * and migrates the data into files of the current segments. This allows a player to change the
     * segment size without any loss of data.
     */
private void convertOldDataToCurrentSegmentScheme() {
    String currentPrefix = segmentNameBuilder.getPrefix();
    File[] files = listFiles(cacheFolder);
    Map<String, LimboPlayer> allLimboPlayers = new HashMap<>();
    List<File> migratedFiles = new ArrayList<>();
    for (File file : files) {
        if (isLimboJsonFile(file) && !file.getName().startsWith(currentPrefix)) {
            Map<String, LimboPlayer> data = readLimboPlayers(file);
            if (data != null) {
                allLimboPlayers.putAll(data);
                migratedFiles.add(file);
            }
        }
    }
    if (!allLimboPlayers.isEmpty()) {
        saveToNewSegments(allLimboPlayers);
        migratedFiles.forEach(FileUtils::delete);
    }
}
Also used : HashMap(java.util.HashMap) FileUtils(fr.xephi.authme.util.FileUtils) ArrayList(java.util.ArrayList) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) File(java.io.File)

Example 17 with LimboPlayer

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

the class LimboPlayerViewer method execute.

@Override
public void execute(CommandSender sender, List<String> arguments) {
    if (arguments.isEmpty()) {
        sender.sendMessage("/authme debug limbo <player>: show a player's limbo info");
        sender.sendMessage("Available limbo records: " + applyToLimboPlayersMap(limboService, Map::keySet));
        return;
    }
    LimboPlayer memoryLimbo = limboService.getLimboPlayer(arguments.get(0));
    Player player = bukkitService.getPlayerExact(arguments.get(0));
    LimboPlayer diskLimbo = player != null ? limboPersistence.getLimboPlayer(player) : null;
    if (memoryLimbo == null && player == null) {
        sender.sendMessage("No limbo info and no player online with name '" + arguments.get(0) + "'");
        return;
    }
    sender.sendMessage(ChatColor.GOLD + "Showing disk limbo / limbo / player info for '" + arguments.get(0) + "'");
    new InfoDisplayer(sender, diskLimbo, memoryLimbo, player).sendEntry("Is op", LimboPlayer::isOperator, Player::isOp).sendEntry("Walk speed", LimboPlayer::getWalkSpeed, Player::getWalkSpeed).sendEntry("Can fly", LimboPlayer::isCanFly, Player::getAllowFlight).sendEntry("Fly speed", LimboPlayer::getFlySpeed, Player::getFlySpeed).sendEntry("Location", l -> formatLocation(l.getLocation()), p -> formatLocation(p.getLocation())).sendEntry("Group", LimboPlayer::getGroup, permissionsManager::getPrimaryGroup);
}
Also used : PermissionNode(fr.xephi.authme.permission.PermissionNode) LimboService(fr.xephi.authme.data.limbo.LimboService) CommandSender(org.bukkit.command.CommandSender) BukkitService(fr.xephi.authme.service.BukkitService) Player(org.bukkit.entity.Player) LimboPersistence(fr.xephi.authme.data.limbo.persistence.LimboPersistence) Function(java.util.function.Function) Inject(javax.inject.Inject) List(java.util.List) DebugSectionUtils.formatLocation(fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.formatLocation) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) PermissionsManager(fr.xephi.authme.permission.PermissionsManager) Map(java.util.Map) Optional(java.util.Optional) DebugSectionPermissions(fr.xephi.authme.permission.DebugSectionPermissions) ChatColor(org.bukkit.ChatColor) DebugSectionUtils.applyToLimboPlayersMap(fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.applyToLimboPlayersMap) Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Map(java.util.Map) DebugSectionUtils.applyToLimboPlayersMap(fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.applyToLimboPlayersMap)

Example 18 with LimboPlayer

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

the class DebugSectionUtilsTest method shouldFetchMapInLimboService.

@Test
public void shouldFetchMapInLimboService() {
    // given
    LimboService limboService = mock(LimboService.class);
    Map<String, LimboPlayer> limboMap = new HashMap<>();
    ReflectionTestUtils.setField(LimboService.class, limboService, "entries", limboMap);
    // when
    Map map = DebugSectionUtils.applyToLimboPlayersMap(limboService, Function.identity());
    // then
    assertThat(map, sameInstance(limboMap));
}
Also used : HashMap(java.util.HashMap) LimboService(fr.xephi.authme.data.limbo.LimboService) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 19 with LimboPlayer

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

the class ProcessSyncPlayerLogin method processPlayerLogin.

public void processPlayerLogin(Player player) {
    final String name = player.getName().toLowerCase();
    final LimboPlayer limbo = limboService.getLimboPlayer(name);
    // Limbo contains the State of the Player before /login
    if (limbo != null) {
        limboService.restoreData(player);
    }
    if (commonService.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
        restoreInventory(player);
    }
    final PlayerAuth auth = dataSource.getAuth(name);
    teleportationService.teleportOnLogin(player, auth, limbo);
    // We can now display the join message (if delayed)
    joinMessageService.sendMessage(name);
    if (commonService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
        player.removePotionEffect(PotionEffectType.BLINDNESS);
    }
    // The Login event now fires (as intended) after everything is processed
    bukkitService.callEvent(new LoginEvent(player));
    player.saveData();
    // Login is done, display welcome message
    List<String> welcomeMessage = welcomeMessageConfiguration.getWelcomeMessage(player);
    if (commonService.getProperty(RegistrationSettings.USE_WELCOME_MESSAGE)) {
        if (commonService.getProperty(RegistrationSettings.BROADCAST_WELCOME_MESSAGE)) {
            welcomeMessage.forEach(bukkitService::broadcastMessage);
        } else {
            welcomeMessage.forEach(player::sendMessage);
        }
    }
    // Login is now finished; we can force all commands
    commandManager.runCommandsOnLogin(player);
    // Send Bungee stuff. The service will check if it is enabled or not.
    bungeeService.connectPlayer(player);
}
Also used : LoginEvent(fr.xephi.authme.events.LoginEvent) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 20 with LimboPlayer

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

the class IndividualFilesPersistenceHandlerTest method shouldReturnNullForUnavailablePlayer.

@Test
public void shouldReturnNullForUnavailablePlayer() {
    // given
    Player player = mock(Player.class);
    given(player.getUniqueId()).willReturn(UUID.nameUUIDFromBytes("other-player".getBytes()));
    // when
    LimboPlayer data = handler.getLimboPlayer(player);
    // then
    assertThat(data, nullValue());
}
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)

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