Search in sources :

Example 1 with Property

use of com.github.steveice10.mc.auth.data.GameProfile.Property in project DragonProxy by DragonetMC.

the class SkinFetcher method getPlayerProfile.

private PlayerProfile getPlayerProfile(GameProfile gameProfile) {
    try {
        return profilesCache.get(gameProfile.getId(), () -> {
            Property property = getProfileProperty(gameProfile.getId());
            System.out.println(property.toString());
            Skin skin = Skin.DEFAULT_SKIN_STEVE;
            if (gameProfile.getTextures().containsKey(GameProfile.TextureType.SKIN)) {
                System.out.println(gameProfile.getTexture(GameProfile.TextureType.SKIN).getURL());
                System.out.println(Skin.getModelFromJava(gameProfile.getTexture(GameProfile.TextureType.SKIN).getModel()));
                skin = new Skin(new URL(gameProfile.getTexture(GameProfile.TextureType.SKIN).getURL()), Skin.getModelFromJava(gameProfile.getTexture(GameProfile.TextureType.SKIN).getModel()));
            }
            if (gameProfile.getTextures().containsKey(GameProfile.TextureType.CAPE))
                skin.setCape(skin.new Cape(new URL(gameProfile.getTexture(GameProfile.TextureType.CAPE).getURL())));
            PlayerProfile profile = new PlayerProfile(gameProfile.getId(), property, skin);
            if (property != null) {
                // profilesCache.put(gameProfile.getId(), profile);
                return profile;
            }
            return null;
        });
    } catch (CacheLoader.InvalidCacheLoadException | ExecutionException ex) {
        return null;
    }
}
Also used : Skin(org.dragonet.common.data.entity.Skin) Cape(org.dragonet.common.data.entity.Skin.Cape) ExecutionException(java.util.concurrent.ExecutionException) Property(com.github.steveice10.mc.auth.data.GameProfile.Property) URL(java.net.URL)

Example 2 with Property

use of com.github.steveice10.mc.auth.data.GameProfile.Property in project DragonProxy by DragonetMC.

the class SkinFetcher method getProfileProperty.

// This will be cached by Guava
private Property getProfileProperty(UUID Uuid) throws IOException, ParseException {
    final URL url = new URL(PROFILE_URL + Uuid.toString().replace("-", "") + "?unsigned=false");
    final HttpURLConnection URLConnection = (HttpURLConnection) url.openConnection();
    System.out.println("ResponseCode : " + URLConnection.getResponseCode() + " UUID : " + Uuid.toString());
    Property property = null;
    if (URLConnection.getResponseCode() == 200 || URLConnection.getResponseCode() == 204) {
        JsonObject jsonObject = gson.fromJson(new InputStreamReader(URLConnection.getInputStream(), Charsets.UTF_8), JsonObject.class);
        JsonArray jsonArray = jsonObject.get("properties").getAsJsonArray();
        for (int i = 0; i < jsonArray.size(); i++) {
            JsonObject rawProperty = jsonArray.get(i).getAsJsonObject();
            String name = rawProperty.get("name").getAsString();
            String value = rawProperty.get("value").getAsString();
            String signature = rawProperty.get("signature").getAsString();
            property = new Property(name, value, signature);
        }
        System.out.println("Fetch Profile Property : " + Uuid + " OK!");
    }
    return property;
}
Also used : JsonArray(com.google.gson.JsonArray) HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) JsonObject(com.google.gson.JsonObject) Property(com.github.steveice10.mc.auth.data.GameProfile.Property) URL(java.net.URL)

Aggregations

Property (com.github.steveice10.mc.auth.data.GameProfile.Property)2 URL (java.net.URL)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 InputStreamReader (java.io.InputStreamReader)1 HttpURLConnection (java.net.HttpURLConnection)1 ExecutionException (java.util.concurrent.ExecutionException)1 Skin (org.dragonet.common.data.entity.Skin)1 Cape (org.dragonet.common.data.entity.Skin.Cape)1