import requests


def get_username(uuid):
    """Get the username of a player from the UUID"""
    r = requests.get("https://api.mojang.com/user/profiles/{}/names".format(uuid))
    if r.ok and r.status_code not in [204, 400]:
        return r.json()[-1]["name"]
    else:
        if r.status_code in [204, 400]:
            raise ValueError("User not found")
        else:
            raise Exception("Can't reach Mojang API")