Skip to content

Commit

Permalink
Tries to re-download a skin if the file is either missing or corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
Podshot committed Dec 2, 2014
1 parent 94c9a2f commit 2818013
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion editortools/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ def movePlayerToCamera(self):
self.editor.addOperation(op)
if op.canUndo:
self.editor.addUnsavedEdit()

def delete_skin(self, uuid):
del self.playerTexture[uuid]
self.playerTexture[uuid] = loadPNGTexture('char.png')

@alertException
def reloadSkins(self):
Expand All @@ -468,7 +472,7 @@ def reloadSkins(self):
for player in self.editor.level.players:
if player != "Player" and player != "[No players]" and player in self.playerTexture.keys():
del self.playerTexture[player]
self.playerTexture[player] = loadPNGTexture(version_utils.getPlayerSkin(player, force=True))
self.playerTexture[player] = loadPNGTexture(version_utils.getPlayerSkin(player, force=True, instance=self))
except:
raise Exception("Could not connect to the skins server, please check your Internet connection and try again.")

Expand Down
11 changes: 7 additions & 4 deletions version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ def getPlayerNameFromUUID(uuid,forceNetwork=False):
print "Error getting the username for {}".format(uuid)
return uuid

def getPlayerSkin(uuid, force=False):
# FIXME: Rewrite to use skins.minecraft.net
# Refrence: http://skins.minecraft.net/MinecraftSkins/Podshot.png
def getPlayerSkin(uuid, force=False, trying_again=False, instance=None):
SKIN_URL = "http://skins.minecraft.net/MinecraftSkins/{}.png"
toReturn = 'char.png'
try:
Expand All @@ -166,7 +164,7 @@ def getPlayerSkin(uuid, force=False):
player_skin.save(os.path.join("player-skins", uuid.replace("-","_")+".png"))
toReturn = os.path.join("player-skins", uuid.replace("-","_")+".png")
else:
playername = getPlayerNameFromUUID(uuid)
playername = getPlayerNameFromUUID(uuid,forceNetwork=True)
urllib.urlretrieve(SKIN_URL.format(playername), os.path.join("player-skins", uuid.replace("-","_")+".png"))
toReturn = os.path.join("player-skins", uuid.replace("-","_")+".png")
player_skin = Image.open(toReturn)
Expand All @@ -175,6 +173,11 @@ def getPlayerSkin(uuid, force=False):
player_skin.save(os.path.join("player-skins", uuid.replace("-","_")+".png"))
except IOError:
print "Couldn't find Image file ("+str(uuid.replace("-","_")+".png")+") or the file may be corrupted"
print "Trying to re-download skin...."
if not trying_again and instance != None:
instance.delete_skin(uuid)
os.remove(os.path.join("player-skins", uuid.replace("-","_")+".png"))
toReturn = getPlayerSkin(uuid, force=True, trying_again=True)
pass
except HTTPError:
print "Couldn't connect to a network"
Expand Down

0 comments on commit 2818013

Please sign in to comment.