Created
November 24, 2015 14:36
-
-
Save phoenixlzx/28d10cd5d591f15009d7 to your computer and use it in GitHub Desktop.
JavaScript to get all player skins from your server's whitelist.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* | |
* Script to get all player skins from your server whitelist. | |
* $ npm install request | |
* $ mkdir -p ./skins/Alex ./skins/Steve | |
* $ node getskins.js | |
**/ | |
var fs = require('fs'); | |
var request = require('request'); | |
var players = JSON.parse(fs.readFileSync('./whitelist.json', 'utf8')); | |
players.forEach(function(p) { | |
var uuid = p.uuid.replace(/-/g, ''); | |
console.log('Request uuid ' + p.uuid + ' for player ' + p.name); | |
request('https://sessionserver.mojang.com/session/minecraft/profile/' + uuid, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
var data = JSON.parse(body); | |
data.properties.forEach(function(t) { | |
if (t.name === 'textures') { | |
var texture = JSON.parse(new Buffer(t.value, 'base64').toString('ascii')); | |
if (texture.textures.SKIN) { | |
var skinUrl = texture.textures.SKIN.url; | |
// if skin is Alex model | |
if (texture.textures.SKIN.metadata && texture.textures.SKIN.metadata.model === 'slim') { | |
request(skinUrl) | |
.on('error', function(err) { | |
console.error('Error requesting skin for player ' + data.name + ': ' + err) | |
}) | |
.pipe(fs.createWriteStream('./skins/Alex/' + data.name + '.png')); | |
} else { | |
request(skinUrl) | |
.on('error', function(err) { | |
console.error('Error requesting skin for player ' + data.name + ': ' + err) | |
}) | |
.pipe(fs.createWriteStream('./skins/Steve/' + data.name + '.png')); | |
} | |
console.log('Skin for player ' + data.name + ' saved.'); | |
} else { | |
console.log('Skin for player ' + data.name + ' Not Found.'); | |
} | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment