Created
January 15, 2022 17:22
-
-
Save GroverChouT/c0d2f38e3ce9ce617c1c779d433b70bf to your computer and use it in GitHub Desktop.
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
import argparse | |
import uuid | |
import httpx | |
def get_parser() -> argparse.ArgumentParser: | |
parser = argparse.ArgumentParser( | |
description="Generate minecraft give command to get player head by username." | |
) | |
parser.add_argument( | |
"username", metavar="username", type=str, | |
help="minecraft username" | |
) | |
parser.add_argument( | |
"-r", "--random", action="store_true", | |
help="use random uuid to replace the original one" | |
) | |
parser.add_argument( | |
"-v", "--version", action="version", | |
version = f"{parser.prog} version 1.0.0" | |
) | |
return parser | |
def get_player_uuid_by_username(username: str) -> str: | |
url = "https://api.mojang.com/users/profiles/minecraft/%s" % username | |
r = httpx.get(url) | |
return r.json()["id"] | |
def get_player_profile_by_uuid(uuid: str): | |
url = "https://sessionserver.mojang.com/session/minecraft/profile/%s" % uuid | |
r = httpx.get(url) | |
return r.json() | |
def main() -> None: | |
parser = get_parser() | |
args = parser.parse_args() | |
player_uuid = get_player_uuid_by_username(args.username) | |
player_profile = get_player_profile_by_uuid(player_uuid) | |
if args.random: | |
player_uuid = str(uuid.uuid4()) | |
print("minecraft:give %s minecraft:player_head{SkullOwner:{Id:\"%s\",Properties:{textures:[{Value:\"%s\"}]}}} 1" % (player_profile["name"], player_uuid, player_profile["properties"][0]["value"])) | |
if "__main__" == __name__: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment