use of org.spongepowered.api.profile.GameProfile in project LanternServer by LanternPowered.
the class UserConfig method addEntry.
@Override
public void addEntry(T entry) {
final GameProfile gameProfile = entry.getProfile();
this.byUUID.put(gameProfile.getUniqueId(), entry);
final Optional<String> optName = entry.getProfile().getName();
if (optName.isPresent()) {
this.byName.put(optName.get().toLowerCase(), entry);
}
}
use of org.spongepowered.api.profile.GameProfile in project LanternServer by LanternPowered.
the class NetworkSession method isWhitelisted.
private static boolean isWhitelisted(GameProfile gameProfile) {
if (!Lantern.getGame().getGlobalConfig().isWhitelistEnabled()) {
return true;
}
final WhitelistService whitelistService = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
if (whitelistService.isWhitelisted(gameProfile)) {
return true;
}
final PermissionService permissionService = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
return permissionService.getUserSubjects().getSubject(gameProfile.getUniqueId().toString()).map(subject -> subject.hasPermission(Permissions.Login.BYPASS_WHITELIST_PERMISSION)).orElse(false);
}
use of org.spongepowered.api.profile.GameProfile in project LanternServer by LanternPowered.
the class LanternGameProfileCache method lookupById.
@Override
public Optional<GameProfile> lookupById(UUID uniqueId) {
try {
final GameProfile gameProfile = GameProfileQuery.queryProfileByUUID(uniqueId, true);
add(gameProfile, true, (Instant) null);
return Optional.of(gameProfile);
} catch (IOException e) {
Lantern.getLogger().warn("An error occurred while retrieving game profile data.", e);
} catch (ProfileNotFoundException ignored) {
}
return Optional.empty();
}
use of org.spongepowered.api.profile.GameProfile in project LanternServer by LanternPowered.
the class LanternGameProfileManager method fill.
@Override
public CompletableFuture<GameProfile> fill(GameProfile profile, boolean signed, boolean useCache) {
checkNotNull(profile, "profile");
return Lantern.getScheduler().submitAsyncTask(() -> {
if (useCache) {
// Load the profile into the cache
this.gameProfileCache.getOrLookupById(profile.getUniqueId());
final Optional<GameProfile> optProfile = this.gameProfileCache.fillProfile(profile, signed);
if (optProfile.isPresent()) {
return optProfile.get();
}
throw new ProfileNotFoundException("Failed to find a profile with the uuid: " + profile.getUniqueId());
}
final GameProfile gameProfile = getById(profile.getUniqueId(), false, signed);
((LanternGameProfile) profile).setName(gameProfile.getName().get());
profile.getPropertyMap().putAll(gameProfile.getPropertyMap());
return profile;
});
}
use of org.spongepowered.api.profile.GameProfile in project LanternServer by LanternPowered.
the class ProxyUser method setInternalUser.
/**
* Sets the internal {@link AbstractUser} of this proxy user.
*
* @param user The user
*/
public void setInternalUser(@Nullable AbstractUser user) {
if (this.user != null) {
try {
UserIO.save(Lantern.getGame().getSavesDirectory(), this.user);
} catch (IOException e) {
Lantern.getLogger().warn("An error occurred while saving the player data for {}", this.gameProfile, e);
}
}
this.user = user;
if (user != null) {
final GameProfile oldProfile = this.gameProfile;
// Update the game profile, in case anything changed
this.gameProfile = user.getProfile();
checkState(this.uniqueId.equals(this.gameProfile.getUniqueId()));
// Reinitialize the subject
if (!Objects.equal(oldProfile.getName().orElse(null), this.gameProfile.getName().orElse(null))) {
initializeSubject();
}
try {
UserIO.load(Lantern.getGame().getSavesDirectory(), this.user);
} catch (IOException e) {
Lantern.getLogger().warn("An error occurred while loading the player data for {}", this.gameProfile, e);
}
}
}
Aggregations