Skip to content

Instantly share code, notes, and snippets.

@notyal
Created April 3, 2020 05:45
Show Gist options
  • Save notyal/d45e4304b51430993ff224ae8b84b879 to your computer and use it in GitHub Desktop.
Save notyal/d45e4304b51430993ff224ae8b84b879 to your computer and use it in GitHub Desktop.
get names from uuid files in minecraft/world/playerdata/*
#!/bin/bash
# get names from uuid files in minecraft/world/playerdata/*
show_usage() {
echo "usage: $0 [file..]"
echo
echo "Where \`file' is one or more uuid.dat file located in minecraft/world/playerdata/"
echo "Example: $0 minecraft/world/playerdata/*"
}
getname() {
uuid=$(basename -s .dat $1)
uuidtrim=$(echo $uuid | tr -d '-')
name=$(curl -s https://api.mojang.com/user/profiles/$uuidtrim/names | jq -r '.[-1]["name"]')
echo -e "$name\t$uuid"
}
# check if jq is installed
command -v jq >/dev/null 2>&1 || {
echo >&2 "The program \`jq' is required but not installed."
echo >&2 "See https://stedolan.github.io/jq/download/"
echo >&2 "Aborting."
exit 1
}
# show usage
if [[ $# == 0 ]]; then
show_usage
exit 1
elif [[ $1 == '-h' || $1 == '--help' || $1 == 'help' ]]; then
show_usage
exit 0
fi
# main()
for f in "$@"; do
[[ "${f##*.}" == 'dat' ]] && getname $f
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment