Çevrim dışı oyuncu verisi

It may be necessary for plugins to access player data even when the player is offline. You might think that Sponge.server().player() returning a ServerPlayer can be used for this. But since all Player objects only exist for online players, another solution must be used.

Some plugins store the relevant data themselves and associate the user by using the GameProfileManager. But writing different code for offline and online users is not necessary. The UserManager is capable of returning User instances for Players who are currently offline.

Örnek kod

Burada bir User ‘ın alınması için kullanılan yardımcı metodun örneği bulunmaktadır:

import java.util.Optional;
import java.util.UUID;
import java.util.concurrent;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.User;
import org.spongepowered.api.user.UserManager;

public CompletableFuture<Optional<User>> getUser(UUID uuid) {
    UserManager userManager = Sponge.server().userManager();
    return userManager.load(uuid);
}

This code will get the UserManager and then retrieve the User from there.

Not

The UserManager will use local cached versions of the user, however will contact Mojang servers if the user has not previously joined, hence why the load returns a CompletableFuture. If the user cannot be found in either cache or Mojang then the CompletableFuture will return Optional.empty

Not

You can check if the player is loaded in cache with the exists(UUID playerUuid) method found in UserManager