Search in sources :

Example 1 with FileUtils

use of fr.xephi.authme.util.FileUtils 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)

Aggregations

LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)1 FileUtils (fr.xephi.authme.util.FileUtils)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1