Search in sources :

Example 1 with Textures

use of com.github.games647.craftapi.model.skin.Textures in project CraftAPI by games647.

the class MojangResolver method downloadSkin.

@Override
public Optional<SkinProperty> downloadSkin(UUID uuid) throws IOException, RateLimitException {
    Optional<SkinProperty> optSkin = cache.getSkin(uuid);
    if (optSkin.isPresent()) {
        return optSkin;
    }
    String url = String.format(SKIN_URL, UUIDAdapter.toMojangId(uuid));
    HttpURLConnection conn = getConnection(url);
    int responseCode = conn.getResponseCode();
    if (responseCode == RateLimitException.RATE_LIMIT_RESPONSE_CODE) {
        discard(conn);
        throw new RateLimitException();
    }
    if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
        return Optional.empty();
    }
    Textures texturesModel = parseRequest(conn, in -> readJson(in, Textures.class));
    SkinProperty property = texturesModel.getProperties()[0];
    cache.addSkin(uuid, property);
    return Optional.of(property);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) Textures(com.github.games647.craftapi.model.skin.Textures)

Example 2 with Textures

use of com.github.games647.craftapi.model.skin.Textures in project ChangeSkin by games647.

the class SkinFormatter method apply.

@Override
public String apply(String template, SkinModel skin) {
    if (template == null) {
        return null;
    }
    int rowId = skin.getRowId();
    UUID ownerId = skin.getProfileId();
    String ownerName = skin.getProfileName();
    long timeFetched = skin.getTimestamp();
    Map<TextureType, TextureModel> textures = skin.getTextures();
    Optional<TextureModel> skinTexture = Optional.ofNullable(textures.get(TextureType.SKIN));
    Optional<TextureModel> capeTexture = Optional.ofNullable(textures.get(TextureType.CAPE));
    String skinUrl = skinTexture.map(TextureModel::getShortUrl).orElse("");
    String slimModel = skinTexture.map(TextureModel::isSlim).map(slim -> "Alex").orElse("Steve");
    String capeUrl = capeTexture.map(TextureModel::getShortUrl).orElse(" - ");
    String timeFormat = timeFormatter.format(Instant.ofEpochMilli(timeFetched));
    return template.replace("{0}", Integer.toString(rowId)).replace("{1}", ownerId.toString()).replace("{2}", ownerName).replace("{3}", timeFormat).replace("{4}", skinUrl).replace("{5}", slimModel).replace("{6}", capeUrl);
}
Also used : TextureModel(com.github.games647.changeskin.core.model.skin.TextureModel) FormatStyle(java.time.format.FormatStyle) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) BiFunction(java.util.function.BiFunction) Optional(java.util.Optional) UUID(java.util.UUID) TextureType(com.github.games647.changeskin.core.model.skin.TextureType) Instant(java.time.Instant) TextureModel(com.github.games647.changeskin.core.model.skin.TextureModel) ZoneId(java.time.ZoneId) UUID(java.util.UUID) TextureType(com.github.games647.changeskin.core.model.skin.TextureType)

Aggregations

SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)1 TextureModel (com.github.games647.changeskin.core.model.skin.TextureModel)1 TextureType (com.github.games647.changeskin.core.model.skin.TextureType)1 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)1 Textures (com.github.games647.craftapi.model.skin.Textures)1 HttpURLConnection (java.net.HttpURLConnection)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 FormatStyle (java.time.format.FormatStyle)1 Map (java.util.Map)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 BiFunction (java.util.function.BiFunction)1