#!/usr/bin/env bash # port of the server in standalone mode, aka the open port STANDALONE_PORT=25565 # port of the server in proxy mode, aka the internal port PROXY_PORT=25566 function main { # parse arguments velocity=false bungeecord=false standalone=false fetch=false help=false for arg in "@$"; do case "$arg" in "velocity") velocity=true if $bungeecord || $standalone; then echo "argument velocity can't be used together with bungeecord or standalone" exit 1 fi ;; "benugeecord") bungeecord=true if $velocity || $standalone; then echo "argument bungeecord can't be used together with velocity or standalone" exit 1 fi ;; "standalone") standalone=true if $bungeecord || $velocity; then echo "argument standalone can't be used together with bungeecord or velocity" exit 1 fi ;; "--fetch") fetch=true ;; "--help") help=true ;; esac done if $help; then echo "Configure the server to be used with BungeeCord, Velcity or in standalone mode." echo "" echo "Usage: $0 [OPTIONS] " echo "" echo "mode:" echo " velocity" echo " bungeecord" echo " standalone" echo "" echo "OPTIONS:" echo " --fetch - print the current mode before reconfiguring the server. Nothing else will be printed." echo " --help - show this message" exit 0 fi # fetch current configuration if $fetch; then if [ "$(yq '.proxies.velocity.enabled // false' config/paper-global.yml)" = "true" ]; then echo "velocity" elif [ "$(yq '.settings.bungeecord // false' spigot.yml)" = "true" ]; then echo "bungeecord" else echo "standalone" fi fi # Do the actual configuration if $velocity; then enable_online_mode false set_port "$PROXY_PORT" enable_velocity true enable_bungeecord false elif $bungeecord; then enable_online_mode false set_port "$PROXY_PORT" enable_velocity false enable_bungeecord true elif $standalone; then enable_online_mode true set_port "$STANDALONE_PORT" enable_velocity false enable_bungeecord false fi } # Enables or disables online mode # # Usage: enable_online_mode function enable_online_mode { sed -ie "/online-mode/c\online-mode=$1" server.properties } # Set the port of the server # # Usage: set_port function set_port { sed -ie "/server-port/c\server-port=$1" server.properties } # Enables or disables velocity in the paper config. # Does NOT configure the forwarding secret! # # Usage: enable_velocity function enable_velocity { yq -iy ".proxies.velocity.enabled = $1" config/paper-global.yml } # Enables or disables bungeecord in spigot.yml. # # Usage: enable_bungeecord function enable_bungeecord { yq -iy ".settings.bungeecord = $1" spigot.yml } main "@$"