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();
}
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();
}
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);
}
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;
}
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());
}
Aggregations