Search in sources :

Example 11 with SkinProperty

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

the class MojangSkinApi method parseSkinTexture.

private Optional<SkinModel> parseSkinTexture(Reader reader) {
    TexturesModel texturesModel = gson.fromJson(reader, TexturesModel.class);
    SkinProperty[] properties = texturesModel.getProperties();
    try {
        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 (Exception ex) {
        logger.error("Failed to parse skin model", ex);
        logger.error(texturesModel.toString());
    }
    return Optional.empty();
}
Also used : SkinProperty(com.github.games647.changeskin.core.model.skin.SkinProperty) TexturesModel(com.github.games647.changeskin.core.model.skin.TexturesModel) IOException(java.io.IOException)

Example 12 with SkinProperty

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

the class MemoryCacheTest method addSkin.

@Test
public void addSkin() throws Exception {
    UUID profileId = UUID.randomUUID();
    assertThat(cache.getSkin(profileId).isPresent(), is(false));
    SkinProperty property = new SkinProperty(SkinPropertyTest.STEVE_VALUE, SkinPropertyTest.STEVE_SIGNATURE);
    cache.addSkin(profileId, property);
    assertThat(cache.getSkin(profileId).get(), is(property));
}
Also used : UUID(java.util.UUID) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) SkinPropertyTest(com.github.games647.craftapi.model.skin.SkinPropertyTest) Test(org.junit.Test)

Example 13 with SkinProperty

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

the class AbstractResolverTest method encodeSkinSlim.

@Test
public void encodeSkinSlim() throws Exception {
    Skin skin = new Skin(Instant.ofEpochMilli(1519552798232L), UUIDAdapter.parseId("78c3a4e837e448189df8f9ce61c5efcc"), "F0ggyMonst3r", "52847ba3eb656e7ac69f2af9cec58d4ec2f5a2ea7e18968c97907e87efa9cc4", Model.SLIM, "");
    skin.setSignature(hexStringToByteArray(SLIM_SIGNATURE));
    SkinProperty property = resolver.encodeSkin(skin);
    assertThat(property.getValue(), is(SkinPropertyTest.SLIM_VALUE));
    assertThat(property.getSignature(), is(SkinPropertyTest.SLIM_SIGNATURE));
}
Also used : Skin(com.github.games647.craftapi.model.skin.Skin) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) Test(org.junit.Test) SkinPropertyTest(com.github.games647.craftapi.model.skin.SkinPropertyTest)

Example 14 with SkinProperty

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

the class AbstractResolverTest method decodeSkinCape.

@Test
public void decodeSkinCape() throws Exception {
    SkinProperty property = new SkinProperty(SkinPropertyTest.CAPE_VALUE, SkinPropertyTest.CAPE_SIGNATURE);
    Skin skin = resolver.decodeSkin(property);
    assertThat(skin.getSignature(), is(hexStringToByteArray(CAPE_SIGNATURE)));
    assertThat(skin.getTimeFetched(), is(Instant.ofEpochMilli(1520277572322L)));
    assertThat(skin.getOwnerId(), is(UUIDAdapter.parseId("61699b2ed3274a019f1e0ea8c3f06bc6")));
    assertThat(skin.getOwnerName(), is("Dinnerbone"));
    Texture skinTexture = skin.getTexture(Type.SKIN).get();
    assertThat(skinTexture.getHash(), is("cd6be915b261643fd13621ee4e99c9e541a551d80272687a3b56183b981fb9a"));
    assertThat(skinTexture.getArmModel().orElse(null), is(Model.SQUARE));
    Texture capeTexture = skin.getTexture(Type.CAPE).get();
    assertThat(capeTexture.getHash(), is("eec3cabfaeed5dafe61c6546297e853a547c39ec238d7c44bf4eb4a49dc1f2c0"));
    assertThat(capeTexture.getArmModel(), is(Optional.empty()));
}
Also used : Skin(com.github.games647.craftapi.model.skin.Skin) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) Texture(com.github.games647.craftapi.model.skin.Texture) Test(org.junit.Test) SkinPropertyTest(com.github.games647.craftapi.model.skin.SkinPropertyTest)

Example 15 with SkinProperty

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

the class AbstractResolverTest method encodeSkinSteve.

@Test
public void encodeSkinSteve() throws Exception {
    Skin skin = new Skin(Instant.ofEpochMilli(1517052435668L), UUIDAdapter.parseId("0aaa2c13922a411bb6559b8c08404695"), "games647", "a2e6a3f8caea7913ab48237beea6d6a1a6f76936e3b71af4c7a08bb61c7870", Model.SQUARE, "");
    skin.setSignature(hexStringToByteArray(STEVE_SIGNATURE));
    SkinProperty property = resolver.encodeSkin(skin);
    assertThat(property.getValue(), is(SkinPropertyTest.STEVE_VALUE));
    assertThat(property.getSignature(), is(SkinPropertyTest.STEVE_SIGNATURE));
}
Also used : Skin(com.github.games647.craftapi.model.skin.Skin) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) Test(org.junit.Test) SkinPropertyTest(com.github.games647.craftapi.model.skin.SkinPropertyTest)

Aggregations

SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)12 SkinPropertyTest (com.github.games647.craftapi.model.skin.SkinPropertyTest)10 Test (org.junit.Test)10 Skin (com.github.games647.craftapi.model.skin.Skin)7 Texture (com.github.games647.craftapi.model.skin.Texture)3 IOException (java.io.IOException)3 SkinProperty (com.github.games647.changeskin.core.model.skin.SkinProperty)2 TexturesModel (com.github.games647.changeskin.core.model.skin.TexturesModel)2 HttpURLConnection (java.net.HttpURLConnection)2 UUID (java.util.UUID)2 Profile (com.github.games647.craftapi.model.Profile)1 Verification (com.github.games647.craftapi.model.auth.Verification)1 Textures (com.github.games647.craftapi.model.skin.Textures)1 MojangResolver (com.github.games647.craftapi.resolver.MojangResolver)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 GeneralSecurityException (java.security.GeneralSecurityException)1