Search in sources :

Example 1 with Skin

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

the class AbstractResolverTest method decodeSkinSlim.

@Test
public void decodeSkinSlim() throws Exception {
    SkinProperty property = new SkinProperty(SkinPropertyTest.SLIM_VALUE, SkinPropertyTest.SLIM_SIGNATURE);
    Skin skin = resolver.decodeSkin(property);
    assertThat(skin.getSignature(), is(hexStringToByteArray(SLIM_SIGNATURE)));
    assertThat(skin.getTimeFetched(), is(Instant.ofEpochMilli(1519552798232L)));
    assertThat(skin.getOwnerId(), is(UUIDAdapter.parseId("78c3a4e837e448189df8f9ce61c5efcc")));
    assertThat(skin.getOwnerName(), is("F0ggyMonst3r"));
    Texture skinTexture = skin.getTexture(Type.SKIN).get();
    assertThat(skinTexture.getHash(), is("52847ba3eb656e7ac69f2af9cec58d4ec2f5a2ea7e18968c97907e87efa9cc4"));
    assertThat(skinTexture.getArmModel().orElse(null), is(Model.SLIM));
}
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 2 with Skin

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

the class AbstractResolverTest method encodeSkinCape.

@Test
public void encodeSkinCape() throws Exception {
    Skin skin = new Skin(Instant.ofEpochMilli(1520277572322L), UUIDAdapter.parseId("61699b2ed3274a019f1e0ea8c3f06bc6"), "Dinnerbone", "cd6be915b261643fd13621ee4e99c9e541a551d80272687a3b56183b981fb9a", Model.SQUARE, "eec3cabfaeed5dafe61c6546297e853a547c39ec238d7c44bf4eb4a49dc1f2c0");
    skin.setSignature(hexStringToByteArray(CAPE_SIGNATURE));
    SkinProperty property = resolver.encodeSkin(skin);
    assertThat(property.getValue(), is(SkinPropertyTest.CAPE_VALUE));
    assertThat(property.getSignature(), is(SkinPropertyTest.CAPE_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 3 with Skin

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

the class AbstractResolverTest method decodeSkinSteve.

@Test
public void decodeSkinSteve() throws Exception {
    SkinProperty property = new SkinProperty(SkinPropertyTest.STEVE_VALUE, SkinPropertyTest.STEVE_SIGNATURE);
    Skin skin = resolver.decodeSkin(property);
    assertThat(skin.getSignature(), is(hexStringToByteArray(STEVE_SIGNATURE)));
    assertThat(skin.getTimeFetched(), is(Instant.ofEpochMilli(1517052435668L)));
    assertThat(skin.getOwnerId(), is(UUIDAdapter.parseId("0aaa2c13922a411bb6559b8c08404695")));
    assertThat(skin.getOwnerName(), is("games647"));
    Texture skinTexture = skin.getTexture(Type.SKIN).get();
    assertThat(skinTexture.getHash(), is("a2e6a3f8caea7913ab48237beea6d6a1a6f76936e3b71af4c7a08bb61c7870"));
    assertThat(skinTexture.getArmModel().orElse(null), is(Model.SQUARE));
}
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 4 with Skin

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

the class AbstractResolver method decodeSkin.

/**
 * Decodes the property from a skin request.
 *
 * @param property Base64 encoded skin property
 * @return decoded model
 */
public Skin decodeSkin(SkinProperty property) {
    byte[] data = Base64.getDecoder().decode(property.getValue());
    String json = new String(data, StandardCharsets.UTF_8);
    Skin skinModel = gson.fromJson(json, Skin.class);
    skinModel.setSignature(Base64.getDecoder().decode(property.getSignature()));
    return skinModel;
}
Also used : Skin(com.github.games647.craftapi.model.skin.Skin)

Example 5 with Skin

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

the class ServerSwitchListener method onLazyLoad.

private void onLazyLoad(ProxiedPlayer player) {
    UserPreference preferences = plugin.getStorage().getPreferences(player.getUniqueId());
    plugin.startSession(player.getPendingConnection(), preferences);
    if (!preferences.getTargetSkin().isPresent() && core.getConfig().getBoolean("restoreSkins")) {
        refetchSkin(player.getName(), preferences);
        if (!preferences.getTargetSkin().isPresent()) {
            // still no skin
            getRandomSkin().ifPresent(preferences::setTargetSkin);
        }
    }
    if (preferences.getTargetSkin().isPresent()) {
        plugin.getApi().applySkin(player, preferences.getTargetSkin().get());
    }
}
Also used : UserPreference(com.github.games647.changeskin.core.model.UserPreference)

Aggregations

SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)11 UserPreference (com.github.games647.changeskin.core.model.UserPreference)10 UUID (java.util.UUID)8 Skin (com.github.games647.craftapi.model.skin.Skin)7 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)6 SkinPropertyTest (com.github.games647.craftapi.model.skin.SkinPropertyTest)6 Test (org.junit.Test)6 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)5 Texture (com.github.games647.craftapi.model.skin.Texture)3 EventHandler (net.md_5.bungee.event.EventHandler)3 SkinProperty (com.github.games647.changeskin.core.model.skin.SkinProperty)2 TextureModel (com.github.games647.changeskin.core.model.skin.TextureModel)2 TextureType (com.github.games647.changeskin.core.model.skin.TextureType)2 TexturesModel (com.github.games647.changeskin.core.model.skin.TexturesModel)2 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Optional (java.util.Optional)2