Search in sources :

Example 1 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.

the class ItemSkullRepresentedPlayerDataProcessor method removeFrom.

@Override
public DataTransactionResult removeFrom(ValueContainer<?> container) {
    if (supports(container)) {
        ItemStack stack = (ItemStack) container;
        Optional<GameProfile> old = getVal(stack);
        if (!old.isPresent()) {
            return DataTransactionResult.successNoData();
        }
        if (SkullUtils.setProfile(stack, null)) {
            return DataTransactionResult.successRemove(constructImmutableValue(old.get()));
        }
        return DataTransactionResult.builder().result(DataTransactionResult.Type.ERROR).build();
    }
    return DataTransactionResult.failNoData();
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) ItemStack(net.minecraft.item.ItemStack)

Example 2 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.

the class SkullRepresentedPlayerDataProcessor method removeFrom.

@Override
public DataTransactionResult removeFrom(ValueContainer<?> container) {
    if (supports(container)) {
        TileEntitySkull skull = (TileEntitySkull) container;
        Optional<GameProfile> old = getVal(skull);
        if (!old.isPresent()) {
            return DataTransactionResult.successNoData();
        }
        if (SkullUtils.setProfile(skull, null)) {
            return DataTransactionResult.successRemove(constructImmutableValue(old.get()));
        }
        return DataTransactionResult.builder().result(DataTransactionResult.Type.ERROR).build();
    }
    return DataTransactionResult.failNoData();
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) TileEntitySkull(net.minecraft.tileentity.TileEntitySkull)

Example 3 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.

the class MixinPlayerProfileCache method lookupByIds.

@Override
public Map<UUID, Optional<GameProfile>> lookupByIds(Iterable<UUID> uniqueIds) {
    checkNotNull(uniqueIds, "unique ids");
    Map<UUID, Optional<GameProfile>> result = Maps.newHashMap();
    MinecraftSessionService service = SpongeImpl.getServer().getMinecraftSessionService();
    for (UUID uniqueId : uniqueIds) {
        com.mojang.authlib.GameProfile profile = service.fillProfileProperties(new com.mojang.authlib.GameProfile(uniqueId, ""), true);
        if (profile != null && profile.getName() != null && !profile.getName().isEmpty()) {
            this.addEntry(profile, null);
            result.put(uniqueId, Optional.of((GameProfile) profile));
        } else {
            // create a dummy profile to avoid future lookups
            // if actual user logs in, the profile will be updated during PlayerList#initializeConnectionToPlayer
            this.addEntry(new com.mojang.authlib.GameProfile(uniqueId, "[sponge]"), null);
            result.put(uniqueId, Optional.empty());
        }
    }
    return result.isEmpty() ? ImmutableMap.of() : ImmutableMap.copyOf(result);
}
Also used : Optional(java.util.Optional) GameProfile(org.spongepowered.api.profile.GameProfile) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) UUID(java.util.UUID)

Example 4 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.

the class MixinPlayerProfileCache method remove.

@Override
public Collection<GameProfile> remove(Iterable<GameProfile> profiles) {
    checkNotNull(profiles, "profiles");
    Collection<GameProfile> result = Lists.newArrayList();
    for (GameProfile profile : profiles) {
        if (this.remove(profile)) {
            result.add(profile);
        }
    }
    return result;
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile)

Example 5 with GameProfile

use of org.spongepowered.api.profile.GameProfile in project SpongeCommon by SpongePowered.

the class Query method fromUniqueIds.

protected List<GameProfile> fromUniqueIds(Collection<UUID> uniqueIds) throws ProfileNotFoundException {
    if (this.useCache) {
        List<UUID> pool = Lists.newArrayList(uniqueIds);
        List<GameProfile> result = Lists.newArrayListWithCapacity(uniqueIds.size());
        // check username cache first
        Iterator<UUID> it = pool.iterator();
        while (it.hasNext()) {
            UUID uniqueId = it.next();
            @Nullable String username = SpongeUsernameCache.getLastKnownUsername(uniqueId);
            if (username != null) {
                result.add(GameProfile.of(uniqueId, username));
                it.remove();
            }
        }
        if (!pool.isEmpty()) {
            result.addAll(this.cache.getOrLookupByIds(pool).values().stream().filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
        }
        return result;
    }
    return this.cache.lookupByIds(uniqueIds).values().stream().filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
}
Also used : Optional(java.util.Optional) GameProfile(org.spongepowered.api.profile.GameProfile) UUID(java.util.UUID) Nullable(javax.annotation.Nullable)

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