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