use of com.github.games647.changeskin.core.model.skin.SkinProperty in project ChangeSkin by games647.
the class MojangSkinApi method downloadSkin.
public Optional<SkinModel> downloadSkin(UUID ownerUUID) {
if (crackedUUID.containsKey(ownerUUID)) {
return Optional.empty();
}
// unsigned is needed in order to receive the signature
String uuidString = UUIDTypeAdapter.toMojangId(ownerUUID);
try {
HttpURLConnection httpConnection = getConnection(String.format(SKIN_URL, uuidString));
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
crackedUUID.put(ownerUUID, new Object());
return Optional.empty();
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), StandardCharsets.UTF_8))) {
TexturesModel texturesModel = gson.fromJson(reader, TexturesModel.class);
SkinProperty[] properties = texturesModel.getProperties();
if (properties != null && properties.length > 0) {
SkinProperty propertiesModel = properties[0];
// base64 encoded skin data
String encodedSkin = propertiesModel.getValue();
String signature = propertiesModel.getSignature();
return Optional.of(SkinModel.createSkinFromEncoded(encodedSkin, signature));
}
}
} catch (IOException ex) {
logger.error("Tried downloading skin data of: {} from Mojang", ownerUUID, ex);
}
return Optional.empty();
}
Aggregations