diff --git a/web/js/minecraft.js b/web/js/minecraft.js index fabe2867..b1ced802 100644 --- a/web/js/minecraft.js +++ b/web/js/minecraft.js @@ -9,12 +9,44 @@ function createMinecraftHead(player,size,completed,failed) { faceImage.src = dynmap.options.tileUrl + 'faces/' + size + 'x' + size + '/' + player + '.png'; } +var playerHeads = {}; + function getMinecraftHead(player,size,completed) { - createMinecraftHead(player, size, completed, function() { - console.error('Failed to retrieve face of "', player, '" with size "', size, '"!') - }); + var key = player + '.' + size; + var head = playerHeads[key]; + // Synchronous + if (!completed) { + return (!head || head.working) ? null : head; + } + + // Asynchronous + if (!head) { + playerHeads[key] = { working: true, hooks: [{f:completed}] }; + createMinecraftHead(player, size, function(head) { + hooks = playerHeads[key].hooks; + playerHeads[key] = head; + var i; + for(i=0;i= 0 && servertime < 13700;