skinUrl method

String skinUrl()

Get the Url for the skin of this player. If the player does not have a skin, this function will return the link to the steve or alex skin.

Implementation

String skinUrl() {
  if (_skinUrl != '') {
    return _skinUrl;
  } else {
    /// There's no skin. The player is using the default Steve or Alex Skin.
    /// Minecraft uses [uuid.hashCode() & 1] for the Alex Skin.
    /// That can be compacted to counting the LSBs of every 4th byte in the Uuid.
    /// XOR-ing all the LSBs gives us 1 for alex and 0 for steve.
    /// See https://github.com/crafatar/crafatar/blob/9d2fe0c45424de3ebc8e0b10f9446e7d5c3738b2/lib/skins.js#L90-L108
    /// for the original implementation.
    var lsbs = int.parse(_profileId[7], radix: 16) ^
        int.parse(_profileId[15], radix: 16) ^
        int.parse(_profileId[23], radix: 16) ^
        int.parse(_profileId[31], radix: 16);
    return lsbs.isOdd
        ? 'http://assets.mojang.com/SkinTemplates/alex.png'
        : 'http://assets.mojang.com/SkinTemplates/steve.png';
    // return lsbs.isOdd ? 'alex' : 'steve';
  }
}