use of com.mojang.util.UUIDTypeAdapter in project launcher by MyFTB.
the class PlayerHeadScheme method getRemoteSkin.
private byte[] getRemoteSkin(String uuid) {
try {
HttpResponse response = HttpRequest.get("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid).execute().returnResponse();
if (response.getStatusLine().getStatusCode() != 200) {
return new byte[0];
}
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
JsonObject jsonObject = gson.fromJson(new InputStreamReader(response.getEntity().getContent()), JsonElement.class).getAsJsonObject();
JsonArray properties = jsonObject.getAsJsonArray("properties");
for (int i = 0; i < properties.size(); i++) {
JsonObject property = properties.get(i).getAsJsonObject();
if (!"textures".equals(property.get("name").getAsString())) {
continue;
}
String json = new String(Base64.decodeBase64(property.get("value").getAsString()), Charsets.UTF_8);
MinecraftTexturesPayload textures = gson.fromJson(json, MinecraftTexturesPayload.class);
if (textures.getTextures() != null && textures.getTextures().containsKey(MinecraftProfileTexture.Type.SKIN)) {
MinecraftProfileTexture skin = textures.getTextures().get(MinecraftProfileTexture.Type.SKIN);
URI skinUri = new URI(skin.getUrl());
if (skinUri.getHost().endsWith(".mojang.com") || skinUri.getHost().endsWith(".minecraft.net")) {
HttpResponse skinResponse = HttpRequest.get(skinUri).execute().returnResponse();
if (skinResponse.getStatusLine().getStatusCode() != 200) {
return new byte[0];
}
BufferedImage wholeSkin = ImageIO.read(skinResponse.getEntity().getContent());
BufferedImage head = wholeSkin.getSubimage(8, 8, 8, 8);
AffineTransform transform = new AffineTransform();
transform.scale(PlayerHeadScheme.targetSize / 8.0, PlayerHeadScheme.targetSize / 8.0);
AffineTransformOp scaleOperation = new AffineTransformOp(transform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
BufferedImage scaledHead = new BufferedImage(PlayerHeadScheme.targetSize, PlayerHeadScheme.targetSize, BufferedImage.TYPE_INT_RGB);
scaledHead = scaleOperation.filter(head, scaledHead);
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
ImageIO.write(scaledHead, "png", byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
}
}
}
}
} catch (IOException | URISyntaxException e) {
PlayerHeadScheme.log.warn("Fehler bei der Skinabfrage", e);
}
return new byte[0];
}
use of com.mojang.util.UUIDTypeAdapter in project MCCustomSkinLoader by xfl03.
the class MojangAPILoader method loadGameProfile.
public static GameProfile loadGameProfile(String username) throws Exception {
// Doc (http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time)
HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest("https://api.mojang.com/users/profiles/minecraft/" + username).setCacheTime(0));
if (StringUtils.isEmpty(responce.content))
return null;
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
GameProfile gameProfile = gson.fromJson(responce.content, GameProfile.class);
if (gameProfile.getId() == null)
return null;
return new GameProfile(gameProfile.getId(), gameProfile.getName());
}
use of com.mojang.util.UUIDTypeAdapter in project MCCustomSkinLoader by xfl03.
the class MojangAPILoader method getTextures.
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile gameProfile) throws Exception {
Property textureProperty = (Property) Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
if (textureProperty == null)
return new HashMap();
String value = textureProperty.getValue();
if (StringUtils.isBlank(value))
return new HashMap();
String json = new String(Base64.decodeBase64(value), Charsets.UTF_8);
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
MinecraftTexturesPayload result = gson.fromJson(json, MinecraftTexturesPayload.class);
if (result == null || result.getTextures() == null)
return new HashMap();
return result.getTextures();
}
use of com.mojang.util.UUIDTypeAdapter in project MCCustomSkinLoader by xfl03.
the class DynamicSkullManager method parseGameProfile.
private void parseGameProfile(GameProfile profile) {
Property textureProperty = (Property) Iterables.getFirst(profile.getProperties().get("textures"), null);
if (textureProperty == null) {
staticTextures.put(profile, new HashMap());
return;
}
String value = textureProperty.getValue();
if (StringUtils.isBlank(value)) {
staticTextures.put(profile, new HashMap());
return;
}
String json = new String(Base64.decodeBase64(value), Charsets.UTF_8);
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
SkullTexture result = gson.fromJson(json, SkullTexture.class);
if (result == null) {
staticTextures.put(profile, new HashMap());
return;
}
staticTextures.put(profile, (result.textures == null || !result.textures.containsKey(Type.SKIN)) ? new HashMap() : parseTextures(result.textures));
if (StringUtils.isNotEmpty(result.index)) {
File indexFile = new File(CustomSkinLoader.DATA_DIR, result.index);
try {
String index = FileUtils.readFileToString(indexFile, Charsets.UTF_8);
if (StringUtils.isNotEmpty(index)) {
ArrayList<String> skins = CustomSkinLoader.GSON.fromJson(index, ArrayList.class);
if (skins != null && !skins.isEmpty())
result.skins = skins;
}
} catch (Exception e) {
CustomSkinLoader.logger.warning("Exception occurs while parsing index file: " + e.toString());
}
}
if (!CustomSkinLoader.config.enableDynamicSkull || result.skins == null || result.skins.isEmpty())
return;
CustomSkinLoader.logger.info("Try to load Dynamic Skull: " + json);
for (int i = 0; i < result.skins.size(); i++) {
// check and cache skins
String skin = result.skins.get(i);
if (HttpUtil0.isLocal(skin)) {
// Local Skin
File skinFile = new File(CustomSkinLoader.DATA_DIR, skin);
if (skinFile.isFile() && skinFile.length() > 0) {
// Skin found
String fakeUrl = HttpTextureUtil.getLocalFakeUrl(skin);
result.skins.set(i, fakeUrl);
} else {
// Could not find skin
result.skins.remove(i--);
continue;
}
} else {
// Online Skin
HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequest(skin).setCacheFile(HttpTextureUtil.getCacheFile(FilenameUtils.getBaseName(skin))).setCacheTime(0).setLoadContent(false));
if (!responce.success) {
// Could not load skin
result.skins.remove(i--);
continue;
}
}
}
if (result.skins.isEmpty()) {
// Nothing loaded
CustomSkinLoader.logger.info("Failed: Nothing loaded.");
return;
}
result.interval = Math.max(result.interval, 50);
if (result.fromZero)
result.startTime = System.currentTimeMillis();
result.period = result.interval * result.skins.size();
CustomSkinLoader.logger.info("Successfully loaded Dynamic Skull: " + new Gson().toJson(result));
dynamicTextures.put(profile, result);
staticTextures.remove(profile);
}
Aggregations