Skip to content

Instantly share code, notes, and snippets.

@MrDOS
Last active December 30, 2015 13:39
Show Gist options
  • Save MrDOS/7836937 to your computer and use it in GitHub Desktop.
Save MrDOS/7836937 to your computer and use it in GitHub Desktop.
In light of UUID conversion, pull player names out of the NBT files.
#! /bin/sh
# Generate a markers.js file with markers for players based on their last-known positions.
# Requires a binary of NBTologist:
# https://gist.github.com/MrDOS/7836657
# Path to NBTologist.
NBTOLOGIST=/home/minecraft/map/nbtologist
# Path to directory containing player NBT files.
PLAYERS=/home/seecraft/map/world/playerdata
# The name of the Mapcrafter world.
WORLD=world
# Output markers.js file.
MARKERS=/home/minecraft/public_html/markers.js
cat <<EOF > "$MARKERS"
var MAPCRAFTER_MARKERS = [
{
"id": "players",
"name": "Players",
"showDefault": true,
"markers": {
"$WORLD": [
EOF
for player_file in "$PLAYERS"/*.dat
do
player=`gunzip -c "$player_file" | "$NBTOLOGIST"`
x=`echo "$player" | cut -d ' ' -f 1`
y=`echo "$player" | cut -d ' ' -f 2`
z=`echo "$player" | cut -d ' ' -f 3`
player_name=`echo "$player" | cut -d ' ' -f 4`
if [ -z "$player_name" ]
then
# No Bukkit "lastKnownName" tag -- we'll have to ask the session server.
bare_uuid=`echo "$player_file" | sed -e 's/.*\/\(.*\).dat/\1/' | sed -e 's/-//g'`
player_name=`curl -s https://sessionserver.mojang.com/session/minecraft/profile/"$bare_uuid" \
| grep -oP '.*\[' | grep -oP -m 1 '"name":".+?"' \
| sed -e 's/"name":"\(.*\)"/\1/'`
fi
echo " {\"pos\": [$x, $z, $y], \"title\": \"$player_name\", \"icon\": \"http://overviewer.org/avatar/$player_name\", \"iconSize\": [16, 32]}," >> "$MARKERS"
done
cat <<EOF >> "$MARKERS"
]
}
}
];
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment