Created
August 2, 2015 00:51
-
-
Save ineentho/814b0f26c3940af519e9 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
#!/bin/sh | |
# This script is expected to be run from the .minecraft directory. | |
# Go into the saves directory, since everything will based on the world | |
# directories which can be found there | |
cd saves | |
# Obtain an array of all saves | |
saveFiles=(*) | |
if [ -z $1 ] ; then | |
# No arguments was provided, ask the user to choose a world | |
echo "Please choose a world by running ./speed num" | |
echo "For example, to use the first world do ./speed 1" | |
# Print a world list | |
saveNum=0 | |
for save in "${saveFiles[@]}" ; do | |
echo ${saveNum}: ${save} | |
saveNum=$((saveNum+1)) | |
done | |
else | |
# The first argument should a world number. | |
# Go into the stats folder for the world the user chose. | |
cd "${saveFiles[$1]}" | |
cd stats | |
# There should only be one .json file, so doing *.json should | |
# only return the contents of one file. | |
echo "hh:mm:ss:ff" | |
while : ; do | |
# You are looking for the playOneMinute stat inside of the file | |
ticks=$(cat *.json | grep -Po '(?<=playOneMinute\":)[0-9]*') | |
# Calculate hours | |
hours=$(expr $ticks / 20 / 60 / 60) | |
# Calculate minutes | |
hoursInTicks=$(expr $hours \* 20 \* 60 \* 60) | |
ticksLeftForMinutes=$(expr $ticks - $hoursInTicks) | |
minutes=$(expr $ticksLeftForMinutes / 20 / 60) | |
# Calculate seconds | |
minutesInTicks=$(expr $minutes \* 20 \* 60) | |
ticksLeftForSeconds=$(expr $ticks - $hoursInTicks - $minutesInTicks) | |
seconds=$(expr $ticksLeftForSeconds / 20) | |
# Calculate hundereth of seconds | |
secondsInTicks=$(expr $seconds \* 20) | |
ticksLeftForHundereth=$(expr $ticks - $hoursInTicks - $minutesInTicks - $secondsInTicks) | |
# Bash has no support for fractions - a tick is 1/20 of a seconds, so multiplying | |
# by 5 gives us one hundereth | |
hundereth=$(expr $ticksLeftForHundereth \* 5) | |
# Format the time string | |
time=$(printf "%02d:%02d:%02d:%02d" $hours $minutes $seconds $hundereth) | |
# Output the result to the console and a textfile | |
echo $time | |
echo $time > ../../../time.txt | |
# Use inotify to wait until the json file is resaved. It might | |
# not be installed by default on all systems. As an alternative | |
# you might want to just check every X milliseconds. | |
inotifywait -qq *.json | |
done | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment