-
Notifications
You must be signed in to change notification settings - Fork 88
helper: Profiles
Luck edited this page Nov 29, 2017
·
1 revision
The profiles API is based around two core interfaces.
A profile represents the unique id + (optional) username of a player on the server.
Player p = ...;
Profile profile = Profile.create(p.getUniqueId(), p.getName());
Profile repositories contain a cache of known profiles, and provide methods to lookup profiles by unique id or username.
A base implementation of this interface is provided by the helper-profiles
plugin.
ProfileRepository repo = getService(ProfileRepository.class);
Optional<Profile> lucksProfile = repo.getProfile("Luck");
if (lucksProfile.isPresent()) {
UUID lucksUniqueId = lucksProfile.get().getUniqueId(); // wew!
}
Profile lucksProfile = repo.getProfile(UUID.fromString("c1d60c50-70b5-4722-8057-87767557e50d"));
Optional<String> lucksName = lucksProfile.getName();
The #get methods will only query the local in-memory cache for profiles, whereas the #lookup methods will query the backing database (and therefore return promises)
repo.lookupProfile("Notch")
.thenAcceptSync(profile -> {
if (profile.isPresent()) {
UUID uniqueId = profile.get().getUniqueId();
}
});
When getting multiple profiles, it's better to use the combined methods, as the request can be combined into a single SQL query.
Promise<Map<String, Profile>> profiles = repo.lookupProfilesByName(Arrays.asList("Luck", "lucko", "Notch"));
profiles.thenAcceptAsync(result -> {
Profile luck = result.get("Luck");
Profile lucko = result.get("lucko");
Profile helper = result.get("Notch");
// Do something
});
- Events
- Scheduler
- Promise
- Metadata
- Commands
- Terminables
- Messenger
- Extended Plugin
- Serialization
- Menu