Search in sources :

Example 1 with Model

use of com.github.games647.craftapi.model.skin.Model 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 2 with Model

use of com.github.games647.craftapi.model.skin.Model 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)

Aggregations

SkinProperty (com.github.games647.changeskin.core.model.skin.SkinProperty)1 TexturesModel (com.github.games647.changeskin.core.model.skin.TexturesModel)1 Skin (com.github.games647.craftapi.model.skin.Skin)1 IOException (java.io.IOException)1