Search in sources :

Example 31 with GameProfile

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

Example 32 with GameProfile

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);
}
Also used : PermissionService(org.spongepowered.api.service.permission.PermissionService) AttributeKey(io.netty.util.AttributeKey) LanternEntity(org.lanternpowered.server.entity.LanternEntity) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) SocketAddress(java.net.SocketAddress) ScheduledFuture(io.netty.util.concurrent.ScheduledFuture) EntityProtocolManager(org.lanternpowered.server.network.entity.EntityProtocolManager) LanternTexts(org.lanternpowered.server.text.LanternTexts) PermissionService(org.spongepowered.api.service.permission.PermissionService) WorldConfig(org.lanternpowered.server.config.world.WorldConfig) Ban(org.spongepowered.api.util.ban.Ban) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) CodecException(io.netty.handler.codec.CodecException) ChannelPromise(io.netty.channel.ChannelPromise) MessageInOutKeepAlive(org.lanternpowered.server.network.vanilla.message.type.connection.MessageInOutKeepAlive) GameProfile(org.spongepowered.api.profile.GameProfile) DecoderException(io.netty.handler.codec.DecoderException) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) LanternServer(org.lanternpowered.server.LanternServer) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) EventLoop(io.netty.channel.EventLoop) Instant(java.time.Instant) InetSocketAddress(java.net.InetSocketAddress) Protocol(org.lanternpowered.server.network.protocol.Protocol) PlayerConnection(org.spongepowered.api.network.PlayerConnection) Preconditions.checkState(com.google.common.base.Preconditions.checkState) LanternWorldProperties(org.lanternpowered.server.world.LanternWorldProperties) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Transform(org.spongepowered.api.entity.Transform) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Queue(java.util.Queue) MessageRegistration(org.lanternpowered.server.network.message.MessageRegistration) EventContext(org.spongepowered.api.event.cause.EventContext) EntityProtocolTypes(org.lanternpowered.server.network.entity.EntityProtocolTypes) Permissions(org.lanternpowered.server.permission.Permissions) Keys(org.spongepowered.api.data.key.Keys) Handler(org.lanternpowered.server.network.message.handler.Handler) Vector3d(com.flowpowered.math.vector.Vector3d) MessageOutDisconnect(org.lanternpowered.server.network.vanilla.message.type.connection.MessageOutDisconnect) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ProtocolState(org.lanternpowered.server.network.protocol.ProtocolState) WhitelistService(org.spongepowered.api.service.whitelist.WhitelistService) HashSet(java.util.HashSet) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HandlerMessage(org.lanternpowered.server.network.message.HandlerMessage) CauseStack(org.lanternpowered.server.event.CauseStack) ImmutableList(com.google.common.collect.ImmutableList) Text(org.spongepowered.api.text.Text) ChannelFutureListener(io.netty.channel.ChannelFutureListener) LanternWorld(org.lanternpowered.server.world.LanternWorld) GlobalTabList(org.lanternpowered.server.entity.living.player.tab.GlobalTabList) Nullable(javax.annotation.Nullable) AsyncHelper(org.lanternpowered.server.network.message.AsyncHelper) TranslationHelper.tr(org.lanternpowered.server.text.translation.TranslationHelper.tr) NullMessage(org.lanternpowered.server.network.message.NullMessage) Iterator(java.util.Iterator) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) MoreObjects(com.google.common.base.MoreObjects) TimeoutException(io.netty.handler.timeout.TimeoutException) IOException(java.io.IOException) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ChannelFuture(io.netty.channel.ChannelFuture) Message(org.lanternpowered.server.network.message.Message) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) DateTimeFormatter(java.time.format.DateTimeFormatter) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) MessageEvent(org.spongepowered.api.event.message.MessageEvent) BulkMessage(org.lanternpowered.server.network.message.BulkMessage) BanService(org.spongepowered.api.service.ban.BanService) WhitelistService(org.spongepowered.api.service.whitelist.WhitelistService)

Example 33 with GameProfile

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

Example 34 with GameProfile

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

Example 35 with GameProfile

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

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