use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.
the class MixinEntity_Tracker method getUserForUuid.
private Optional<User> getUserForUuid(UUID uuid) {
// get player if online
Player player = Sponge.getServer().getPlayer(uuid).orElse(null);
if (player != null) {
return Optional.of(player);
}
// player is not online, get user from storage if one exists
if (this.spongeProfileManager == null) {
this.spongeProfileManager = ((SpongeProfileManager) Sponge.getServer().getGameProfileManager());
}
if (this.userStorageService == null) {
this.userStorageService = SpongeImpl.getGame().getServiceManager().provide(UserStorageService.class).get();
}
// check username cache
String username = SpongeUsernameCache.getLastKnownUsername(uuid);
if (username != null) {
return this.userStorageService.get(GameProfile.of(uuid, username));
}
// check mojang cache
GameProfile profile = this.spongeProfileManager.getCache().getById(uuid).orElse(null);
if (profile != null) {
return this.userStorageService.get(profile);
}
// If we reach this point, queue UUID for async lookup and return empty
this.spongeProfileManager.lookupUserAsync(uuid);
return Optional.empty();
}
use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.
the class SpongeBanService method getBanFor.
@Override
public Optional<Ban.Profile> getBanFor(GameProfile profile) {
UserListBans bans = this.getUserBanList();
bans.removeExpired();
return Optional.ofNullable((Ban.Profile) bans.getValues().get(bans.getObjectKey((com.mojang.authlib.GameProfile) profile)));
}
use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.
the class SpongeUserStorageService method match.
@Override
public Collection<GameProfile> match(String lastKnownName) {
lastKnownName = checkNotNull(lastKnownName, "lastKnownName").toLowerCase(Locale.ROOT);
Collection<GameProfile> allProfiles = UserDiscoverer.getAllProfiles();
Collection<GameProfile> matching = Sets.newHashSet();
for (GameProfile profile : allProfiles) {
if (profile.getName().isPresent() && profile.getName().get().startsWith(lastKnownName)) {
matching.add(profile);
}
}
return matching;
}
use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.
the class SpongeWhitelistService method addProfile.
@Override
public boolean addProfile(GameProfile profile) {
boolean wasWhitelisted = this.isWhitelisted(profile);
UserListUtils.addEntry(getWhitelist(), new UserListWhitelistEntry((com.mojang.authlib.GameProfile) profile));
return wasWhitelisted;
}
use of org.spongepowered.api.profile.GameProfile in project LuckPerms by lucko.
the class SpongeConnectionListener method onClientAuth.
@Listener(order = Order.EARLY)
@IsCancelled(Tristate.UNDEFINED)
public void onClientAuth(ClientConnectionEvent.Auth e) {
/* Called when the player first attempts a connection with the server.
Listening on AFTER_PRE priority to allow plugins to modify username / UUID data here. (auth plugins) */
final GameProfile profile = e.getProfile();
final String username = profile.getName().orElseThrow(() -> new RuntimeException("No username present for user " + profile.getUniqueId()));
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
this.plugin.getLogger().info("Processing auth event for " + profile.getUniqueId() + " - " + profile.getName());
}
recordConnection(profile.getUniqueId());
/* Actually process the login for the connection.
We do this here to delay the login until the data is ready.
If the login gets cancelled later on, then this will be cleaned up.
This includes:
- loading uuid data
- loading permissions
- creating a user instance in the UserManager for this connection.
- setting up cached data. */
try {
User user = loadUser(profile.getUniqueId(), username);
this.plugin.getEventFactory().handleUserLoginProcess(profile.getUniqueId(), username, user);
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName());
ex.printStackTrace();
this.deniedAsyncLogin.add(profile.getUniqueId());
e.setCancelled(true);
e.setMessageCancelled(false);
// noinspection deprecation
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
}
}
Aggregations