-
-
Save DouglasMeyer/210353c8eb30a51f5a36 to your computer and use it in GitHub Desktop.
UHC world setup
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/bash | |
#Note run with `bash -x ./`... to enable debugging | |
usage_text="Ultra Hardcore world setup script. | |
This script will help you prepare a seed for a match of UHC. Then it will help you run it (teams, time markers, and the like). Just run the script, join the server, and go into creative mode. | |
This script will launch a screen session that will run the server and give you helpers for UHC. | |
Or you can run the server in your own screen session and specify the screen number with MC_SERVER_SCREEN_NUM. | |
Usage: $0 | |
" | |
# If any commands in a pipe fail, they all fail. | |
set -o pipefail | |
### Options/Flags/Defaults | |
usage= | |
while [ $# -ne 0 ] ; do | |
case $1 in | |
--help | --usage ) shift ; usage=t ;; | |
* ) | |
echo "Unknown option \"$1\"" | |
echo | |
usage=t | |
shift | |
;; | |
esac | |
done | |
if [ "$usage" ] ; then | |
echo "${usage_text}" | |
exit 2 | |
fi | |
### Script Body | |
# `n` helper (newline character) | |
n=$(echo -e "\r") | |
start_screen_session() { | |
MC_SERVER_SCREEN_NUM=0 screen -S minecraft -d -m | |
screen -S minecraft -p 0 -X stuff "java -Xmx1024M -jar minecraft_server.14w11b.jar nogui$n" | |
screen -S minecraft -X screen | |
screen -S minecraft -p 1 -X stuff "$0$n" | |
exec screen -r -S minecraft | |
} | |
if [ -z "${MC_SERVER_SCREEN_NUM}" ] ; then | |
# This execution will be replaced with a screen session that runs: | |
# 0. The minecraft server | |
# 1. This uhc_script | |
start_screen_session | |
fi | |
mc_command() { | |
screen -S minecraft -p $MC_SERVER_SCREEN_NUM -X stuff "$*$n" | |
} | |
x=-1000 | |
y=128 | |
z=-1000 | |
load_region() { | |
mc_command time set day | |
mc_command gamerule doDaylightCycle false | |
mc_command tp @r $x $y $z 0 -90 | |
x=$((x + 400)) | |
if [[ $x -gt 1000 ]] ; then | |
x=-1000 | |
z=$((z + 400)) | |
if [[ $z -gt 1000 ]] ; then | |
z=-1000 | |
next_command="add_walls" | |
fi | |
fi | |
} | |
add_walls() { | |
# This builds the walls in 1x255x14 chunks. | |
# There will be a bit of spill-over since 1000/14 will have a remander. | |
y1=260 | |
x1=-1000 | |
for x1 in -1000 1000 ; do | |
for z1 in {-1000..1000..14} ; do | |
mc_command tp @r $x1 $y1 $z1 | |
mc_command fill $x1 0 $z1 $x1 255 $(( z1 + 14 )) minecraft:bedrock | |
done | |
done | |
for z1 in -1000 1000 ; do | |
for x1 in {-1000..1000..14} ; do | |
mc_command tp @r $x1 $y1 $z1 | |
mc_command fill $x1 0 $z1 $(( x1 + 14 )) 255 $z1 minecraft:bedrock | |
done | |
done | |
next_command="set_spawn" | |
} | |
auto_load_and_walls() { | |
load_region | |
while [ "$next_command" == "load_region" ] ; do | |
sleep 60 # 60 second delay between "jumps" to let the map load. | |
load_region | |
done | |
add_walls | |
exit | |
} | |
set_spawn() { | |
mc_command 'tellraw @a {"text":"","extra":[{"text":"Do not forget to ","color":"white"},{"text":"set world spawn","color":"blue","clickEvent":{"action":"run_command","value":"/setworldspawn"}},{"text":".","color":"white"}]}' | |
next_command="prepare_teams" | |
} | |
prepare_teams() { | |
mc_command gamerule doDaylightCycle false | |
mc_command time set day | |
mc_command scoreboard objectives add Health health | |
mc_command scoreboard objectives setdisplay list Health | |
mc_command scoreboard teams add red | |
mc_command scoreboard teams option red color red | |
mc_command scoreboard teams add blue | |
mc_command scoreboard teams option blue color blue | |
mc_command scoreboard teams add green | |
mc_command scoreboard teams option green color green | |
mc_command scoreboard teams join red @r[team=,c=4] | |
mc_command scoreboard teams join blue @r[team=,c=4] | |
mc_command scoreboard teams join green @r[team=,c=4] | |
next_command="start_uhc" | |
} | |
start_uhc() { | |
mc_command time set day | |
mc_command spreadplayers 0 0 400 999 true @a | |
mc_command gamerule naturalRegeneration true | |
mc_command effect @a 10 1 255 true # Regenerate players' health | |
sleep 1 | |
mc_command effect @a 23 1 255 true # Saturate players | |
mc_command say "30 seconds" ; sleep 20 | |
mc_command say "10 seconds" ; sleep 5 | |
mc_command say "5..." ; sleep 1 | |
mc_command say "4..." ; sleep 1 | |
mc_command say "3..." ; sleep 1 | |
mc_command say "2..." ; sleep 1 | |
mc_command say "1..." ; sleep 1 | |
mc_command gamerule naturalRegeneration false | |
mc_command gamerule doDaylightCycle true | |
mc_command say "Go!" | |
sleep $(( 60 * 20 )) ; mc_command say "20 Minute Mark" | |
sleep $(( 60 * 20 )) ; mc_command say "40 Minute Mark" | |
sleep $(( 60 * 20 )) ; mc_command say "60 Minute Mark" | |
sleep $(( 60 * 20 )) ; mc_command say "80 Minute Mark" | |
sleep $(( 60 * 20 )) ; mc_command say "100 Minute Mark" | |
sleep $(( 60 * 20 )) ; mc_command say "120 Minute Mark" | |
sleep $(( 60 * 20 )) ; mc_command say "140 Minute Mark" | |
sleep $(( 60 * 20 )) ; mc_command say "160 Minute Mark" | |
sleep $(( 60 * 20 )) ; mc_command say "180 Minute Mark, finish it already!" | |
} | |
show_options() { | |
echo "" | |
echo "== Values ==" | |
echo "World size: 1000x1000 (fixed)" | |
echo "# of teams: 3 (fixed)" | |
echo "# of players per teams: 4 (fixed)" | |
echo "" | |
echo "== Map Prep ==" | |
echo "load_region) Teleport to $x,$z to load the area." | |
echo "add_walls) Create a bedrock wall around the map." | |
echo "auto_load_and_walls) Automatically load the map and generate the walls." | |
echo "set_spawn) Tell someone in the world to set spawn." | |
echo "" | |
echo "== Event Prep ==" | |
echo "prepare_teams) Randomly distribute players into teams." | |
echo "start_uhc) Sets UHC rules, starts the countdown, then starts the 20x minute marks." | |
} | |
next_command="load_region" | |
input= | |
while [[ "$input" -ne "x" ]] ; do | |
show_options | |
read -p "($next_command) >" input | |
if [[ -z "$input" ]] ; then | |
input=$next_command | |
fi | |
case $input in | |
load_region ) load_region ;; | |
add_walls ) add_walls ;; | |
auto_load_and_walls ) auto_load_and_walls ;; | |
set_spawn ) set_spawn ;; | |
prepare_teams ) prepare_teams ;; | |
start_uhc ) start_uhc ;; | |
x ) | |
# exit | |
;; | |
* ) | |
echo "Unknown command $input" | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment