Created
December 4, 2021 01:35
-
-
Save ormaaj/bd40da12408305de91e8ff5cc62fd931 to your computer and use it in GitHub Desktop.
minecraft function
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
# Stupid game. | |
# minecraft -c | -s [ -p ] | |
function minecraft { | |
typeset \ | |
jvm=${JAVA_HOME}/bin/java \ | |
worldPath=~/doc/mcdata2 \ | |
serverPath=~/doc/programs/ServerJarStorage/Release\ 1.8/minecraft_server.jar \ | |
clientPath=~/doc/programs/Minecraft.jar | |
typeset opt OPTARG OPTIND OPTERR=0 | |
typeset -A mcopts | |
[[ -x $jvm ]] || return | |
while getopts :scp: opt; do | |
case $opt in | |
\?) | |
printf 'Unknown option: %s\n' "$OPTARG" >&2 | |
return 1 | |
;; | |
:) | |
printf '-%s requires an argument.\n' "$OPTARG" >&2 | |
return 1 | |
;; | |
*) | |
mcopts[$opt]=$OPTARG | |
OPTARG= | |
esac | |
done | |
if ! ${mcopts[s]+'false'}; then # Server | |
pushd "$worldPath" || return | |
if ! ${mcopts[p]+'false'}; then # If user supplies a fifo then read from it. | |
if [[ -p ${mcopts[p]} ]]; then | |
# Open the fifo without blocking using a temporary fd in case there's no writer. | |
{ | |
{ | |
#lsof -ap "$BASHPID" -d 0-20 +f G >&2 | |
#cat | |
"$jvm" -Xmx4096M -jar "$serverPath" nogui | |
} 3<>"${mcopts[p]}" </dev/fd/3 3>&- | |
} & | |
else | |
printf '%s must be a readable/writable named pipe\n' "${mcopts[p]}" >&2 | |
return 1 | |
fi | |
else | |
"$jvm" -Xmx4096M -jar "$serverPath" nogui & | |
fi | |
printf 'Minecraft server PID: %d\n' "$!" | |
wait | |
popd | |
elif ! ${mcopts[c]+'false'}; then # Client | |
"$jvm" -jar "$clientPath" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment