docker-minecraft-server/start-finalSetup04ServerProperties

152 lines
4.1 KiB
Text
Raw Normal View History

2017-11-01 05:42:44 +00:00
#!/bin/bash
2020-03-06 15:52:17 +00:00
. /start-utils
2017-11-01 05:42:44 +00:00
# FUNCTIONS
function setServerProp {
local prop=$1
local var=$2
if [ -n "$var" ]; then
2018-04-14 18:01:34 +00:00
# normalize booleans
case ${var^^} in
TRUE|FALSE)
var=${var,,} ;;
esac
2020-03-06 15:52:17 +00:00
log "Setting ${prop} to '${var}' in ${SERVER_PROPERTIES}"
sed -i "/^${prop}\s*=/ c ${prop}=${var}" "$SERVER_PROPERTIES"
else
2020-03-06 15:52:17 +00:00
log "Skip setting ${prop}"
2017-11-01 05:42:44 +00:00
fi
}
function customizeServerProps {
2017-11-01 05:42:44 +00:00
if [ -n "$WHITELIST" ]; then
2020-03-06 15:52:17 +00:00
log "Creating whitelist"
setServerProp "whitelist" "true"
setServerProp "white-list" "true"
2017-11-01 05:42:44 +00:00
fi
# If not provided, generate a reasonable default message-of-the-day,
# which shows up in the server listing in the client
if [ -z "$MOTD" ]; then
# snapshot is the odd case where we have to look at version to identify that label
if [[ ${ORIGINAL_TYPE} == "VANILLA" && ${VERSION} == "SNAPSHOT" ]]; then
label=SNAPSHOT
else
label=${ORIGINAL_TYPE}
fi
# Convert label to title-case
label=${label,,}
label=${label^}
MOTD="A ${label} Minecraft Server powered by Docker"
fi
setServerProp "server-name" "$SERVER_NAME"
setServerProp "server-port" "$SERVER_PORT"
2017-11-01 05:42:44 +00:00
setServerProp "motd" "$MOTD"
setServerProp "allow-nether" "$ALLOW_NETHER"
setServerProp "announce-player-achievements" "$ANNOUNCE_PLAYER_ACHIEVEMENTS"
setServerProp "enable-command-block" "$ENABLE_COMMAND_BLOCK"
setServerProp "spawn-animals" "$SPAWN_ANIMALS"
setServerProp "spawn-monsters" "$SPAWN_MONSTERS"
setServerProp "spawn-npcs" "$SPAWN_NPCS"
2019-09-08 21:40:45 +00:00
setServerProp "spawn-protection" "$SPAWN_PROTECTION"
2017-11-01 05:42:44 +00:00
setServerProp "generate-structures" "$GENERATE_STRUCTURES"
setServerProp "view-distance" "$VIEW_DISTANCE"
setServerProp "hardcore" "$HARDCORE"
2018-05-19 23:07:16 +00:00
setServerProp "snooper-enabled" "$SNOOPER_ENABLED"
2017-11-01 05:42:44 +00:00
setServerProp "max-build-height" "$MAX_BUILD_HEIGHT"
setServerProp "force-gamemode" "$FORCE_GAMEMODE"
setServerProp "max-tick-time" "$MAX_TICK_TIME"
2017-11-01 05:42:44 +00:00
setServerProp "enable-query" "$ENABLE_QUERY"
setServerProp "query.port" "$QUERY_PORT"
setServerProp "enable-rcon" "$ENABLE_RCON"
setServerProp "rcon.password" "$RCON_PASSWORD"
setServerProp "rcon.port" "$RCON_PORT"
setServerProp "max-players" "$MAX_PLAYERS"
setServerProp "max-world-size" "$MAX_WORLD_SIZE"
setServerProp "level-name" "$LEVEL"
setServerProp "level-seed" "$SEED"
setServerProp "pvp" "$PVP"
setServerProp "generator-settings" "$GENERATOR_SETTINGS"
setServerProp "online-mode" "$ONLINE_MODE"
2018-04-14 18:01:34 +00:00
setServerProp "allow-flight" "$ALLOW_FLIGHT"
setServerProp "level-type" "${LEVEL_TYPE^^}"
setServerProp "resource-pack" "$RESOURCE_PACK"
setServerProp "resource-pack-sha1" "$RESOURCE_PACK_SHA1"
2017-11-01 05:42:44 +00:00
if [ -n "$DIFFICULTY" ]; then
case $DIFFICULTY in
peaceful|0)
DIFFICULTY=0
;;
easy|1)
DIFFICULTY=1
;;
normal|2)
DIFFICULTY=2
;;
hard|3)
DIFFICULTY=3
;;
*)
2020-03-06 15:52:17 +00:00
log "DIFFICULTY must be peaceful, easy, normal, or hard."
2017-11-01 05:42:44 +00:00
exit 1
;;
esac
setServerProp "difficulty" "$DIFFICULTY"
2017-11-01 05:42:44 +00:00
fi
if [ -n "$MODE" ]; then
2020-03-06 15:52:17 +00:00
log "Setting mode"
2017-11-01 05:42:44 +00:00
MODE_LC=$( echo $MODE | tr '[:upper:]' '[:lower:]' )
case $MODE_LC in
0|1|2|3)
;;
su*)
MODE=0
;;
c*)
MODE=1
;;
a*)
MODE=2
;;
sp*)
MODE=3
;;
*)
2020-03-06 15:52:17 +00:00
log "ERROR: Invalid game mode: $MODE"
2017-11-01 05:42:44 +00:00
exit 1
;;
esac
setServerProp "gamemode" "$MODE"
2017-11-01 05:42:44 +00:00
fi
}
# Deploy server.properties file
if [[ ${TYPE} == "FEED-THE-BEAST" ]]; then
export SERVER_PROPERTIES=${FTB_DIR}/server.properties
2020-03-06 15:52:17 +00:00
log "detected FTB, changing properties path to ${SERVER_PROPERTIES}"
fi
if [ ! -e "$SERVER_PROPERTIES" ]; then
2020-03-06 15:52:17 +00:00
log "Creating server.properties in ${SERVER_PROPERTIES}"
cp /tmp/server.properties "$SERVER_PROPERTIES"
customizeServerProps
elif [ -n "${OVERRIDE_SERVER_PROPERTIES}" ]; then
case ${OVERRIDE_SERVER_PROPERTIES^^} in
TRUE|1)
customizeServerProps
;;
*)
2020-03-06 15:52:17 +00:00
log "server.properties already created, skipping"
;;
esac
else
2020-03-06 15:52:17 +00:00
log "server.properties already created, skipping"
2017-11-01 05:42:44 +00:00
fi
exec /start-finalSetup05EnvVariables $@