use of org.spongepowered.common.profile.SpongeProfileManager 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.common.profile.SpongeProfileManager in project SpongeCommon by SpongePowered.
the class MixinEntity method onConstruction.
@Inject(method = "<init>", at = @At("RETURN"))
public void onConstruction(net.minecraft.world.World worldIn, CallbackInfo ci) {
if (this.entityType instanceof SpongeEntityType) {
SpongeEntityType spongeEntityType = (SpongeEntityType) this.entityType;
if (spongeEntityType.getEnumCreatureType() == null) {
for (EnumCreatureType type : EnumCreatureType.values()) {
if (SpongeImplHooks.isCreatureOfType((net.minecraft.entity.Entity) (Object) this, type)) {
spongeEntityType.setEnumCreatureType(type);
break;
}
}
}
}
if (worldIn != null && !worldIn.isRemote) {
this.spongeProfileManager = ((SpongeProfileManager) Sponge.getServer().getGameProfileManager());
this.userStorageService = SpongeImpl.getGame().getServiceManager().provide(UserStorageService.class).get();
}
}
Aggregations