Search in sources :

Example 1 with UserCacheVersionNode

use of io.github.nucleuspowered.nucleus.configurate.datatypes.UserCacheVersionNode in project Nucleus by NucleusPowered.

the class UserCacheService method fileWalk.

public boolean fileWalk() {
    synchronized (lockingObject) {
        if (isWalking) {
            return false;
        }
        isWalking = true;
    }
    try {
        Map<UUID, UserCacheDataNode> data = Maps.newHashMap();
        List<UUID> knownUsers = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).getAll().stream().map(Identifiable::getUniqueId).collect(Collectors.toList());
        int count = 0;
        UserDataManager manager = Nucleus.getNucleus().getUserDataManager();
        for (UUID user : knownUsers) {
            if (manager.has(user)) {
                manager.get(user).ifPresent(x -> data.put(user, new UserCacheDataNode(x)));
                if (++count >= 10) {
                    manager.removeOfflinePlayers();
                    count = 0;
                }
            }
        }
        this.data = new UserCacheVersionNode();
        this.data.getNode().putAll(data);
        save();
    } finally {
        isWalking = false;
    }
    return true;
}
Also used : UserDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager) UserCacheVersionNode(io.github.nucleuspowered.nucleus.configurate.datatypes.UserCacheVersionNode) UUID(java.util.UUID) UserCacheDataNode(io.github.nucleuspowered.nucleus.configurate.datatypes.UserCacheDataNode)

Aggregations

UserCacheDataNode (io.github.nucleuspowered.nucleus.configurate.datatypes.UserCacheDataNode)1 UserCacheVersionNode (io.github.nucleuspowered.nucleus.configurate.datatypes.UserCacheVersionNode)1 UserDataManager (io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager)1 UUID (java.util.UUID)1