Search in sources :

Example 6 with GameProfile

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();
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) GameProfile(org.spongepowered.api.profile.GameProfile) SpongeProfileManager(org.spongepowered.common.profile.SpongeProfileManager)

Example 7 with GameProfile

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)));
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) Ban(org.spongepowered.api.util.ban.Ban) UserListBans(net.minecraft.server.management.UserListBans)

Example 8 with GameProfile

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;
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile)

Example 9 with GameProfile

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;
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) UserListWhitelistEntry(net.minecraft.server.management.UserListWhitelistEntry)

Example 10 with GameProfile

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())));
    }
}
Also used : User(me.lucko.luckperms.common.model.User) GameProfile(org.spongepowered.api.profile.GameProfile) Listener(org.spongepowered.api.event.Listener) AbstractConnectionListener(me.lucko.luckperms.common.listener.AbstractConnectionListener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Aggregations

GameProfile (org.spongepowered.api.profile.GameProfile)44 Optional (java.util.Optional)12 UUID (java.util.UUID)12 Text (org.spongepowered.api.text.Text)9 User (org.spongepowered.api.entity.living.player.User)8 IOException (java.io.IOException)7 List (java.util.List)6 Sponge (org.spongepowered.api.Sponge)6 Cause (org.spongepowered.api.event.cause.Cause)6 World (org.spongepowered.api.world.World)6 Vector3d (com.flowpowered.math.vector.Vector3d)5 Collectors (java.util.stream.Collectors)5 Keys (org.spongepowered.api.data.key.Keys)5 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)4 ImmutableList (com.google.common.collect.ImmutableList)4 Lists (com.google.common.collect.Lists)4 Collection (java.util.Collection)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4