diff --git a/README.md b/README.md index 2baffada..e70cc8a0 100644 --- a/README.md +++ b/README.md @@ -1670,6 +1670,7 @@ Feature is used run commands when the server starts, client connects, or client ```yaml RCON_CMDS_STARTUP: |- /gamerule doFireTick false + /pregen start 200 ``` **On Client Connection:** @@ -1686,6 +1687,22 @@ Feature is used run commands when the server starts, client connects, or client /gamerule doFireTick true ``` +**On First Client Connect** + +```yaml + RCON_CMDS_FIRST_CONNECT: |- + /pregen stop +``` + +**On Last Client Disconnect** + +```yaml + RCON_CMDS_LAST_DISCONNECT: |- + /kill @e[type=minecraft:boat] + /pregen start 200 + +``` + **Example of rules for new players** Uses team NEW and team OLD to track players on the server. So move player with no team to NEW, run a command, move them to team OLD. @@ -1693,13 +1710,19 @@ Uses team NEW and team OLD to track players on the server. So move player with n ```yaml RCON_CMDS_STARTUP: |- + /pregen start 200 /gamerule doFireTick false /team add New /team add Old RCON_CMDS_ON_CONNECT: |- /team join New @a[team=] - /give @a[team=New] diamond_block + /give @a[team=New] birch_boat /team join Old @a[team=New] + RCON_CMDS_FIRST_CONNECT: |- + /pregen stop + RCON_CMDS_LAST_DISCONNECT: |- + /kill @e[type=minecraft:boat] + /pregen start 200 ``` ## Autopause diff --git a/examples/docker-compose-rconcmd.yml b/examples/docker-compose-rconcmd.yml index 1ee09a74..f09f8bce 100644 --- a/examples/docker-compose-rconcmd.yml +++ b/examples/docker-compose-rconcmd.yml @@ -12,13 +12,19 @@ services: # YAML Heredoc, be sure to use '|-' this will remove the first newline and final new line. # This is versus '|' that will leaving with two empty strings at top and bottom. RCON_CMDS_STARTUP: |- + /pregen start 200 /gamerule doFireTick false /team add New /team add Old RCON_CMDS_ON_CONNECT: |- /team join New @a[team=] - /give @a[team=New] diamond_block + /give @a[team=New] birch_boat /team join Old @a[team=New] + RCON_CMDS_FIRST_CONNECT: |- + /pregen stop + RCON_CMDS_LAST_DISCONNECT: |- + /kill @e[type=minecraft:boat] + /pregen start 200 restart: unless-stopped volumes: mc: {} diff --git a/files/rconcmds/rcon-cmds-daemon.sh b/files/rconcmds/rcon-cmds-daemon.sh index 2310c53f..d9db30fa 100644 --- a/files/rconcmds/rcon-cmds-daemon.sh +++ b/files/rconcmds/rcon-cmds-daemon.sh @@ -3,6 +3,8 @@ : "${RCON_CMDS_STARTUP:=}" : "${RCON_CMDS_ON_CONNECT:=}" : "${RCON_CMDS_ON_DISCONNECT:=}" +: "${RCON_CMDS_FIRST_CONNECT:=}" +: "${RCON_CMDS_LAST_DISCONNECT:=}" : "${RCON_CMDS_PERIOD:=10}" # needed for the clients connected function residing in autopause @@ -44,7 +46,12 @@ do run_command "$cmd" done <<< "$RCON_CMDS_STARTUP" fi - if [[ -z "$RCON_CMDS_ON_CONNECT" ]] && [[ -z "$RCON_CMDS_ON_DISCONNECT" ]]; then + if + [[ -z "$RCON_CMDS_ON_CONNECT" ]] && + [[ -z "$RCON_CMDS_ON_DISCONNECT" ]] && + [[ -z "$RCON_CMDS_FIRST_CONNECT" ]] && + [[ -z "$RCON_CMDS_LAST_DISCONNECT" ]] + then logRcon "No addition rcon commands are given, stopping rcon cmd service" exit 0 fi @@ -52,19 +59,34 @@ do fi ;; XII) - # Main Loop looking for connections CURR_CLIENTCONNECTIONS=$(java_clients_connections) + # When a client joins if (( CURR_CLIENTCONNECTIONS > CLIENTCONNECTIONS )) && [[ "$RCON_CMDS_ON_CONNECT" ]]; then logRcon "Clients have Connected, running connect cmds" while read -r cmd; do run_command "$cmd" done <<< "$RCON_CMDS_ON_CONNECT" + # When a client leaves elif (( CURR_CLIENTCONNECTIONS < CLIENTCONNECTIONS )) && [[ "$RCON_CMDS_ON_DISCONNECT" ]]; then logRcon "Clients have Disconnected, running disconnect cmds" while read -r cmd; do run_command "$cmd" done <<< "$RCON_CMDS_ON_DISCONNECT" fi + + # First client connection + if (( CURR_CLIENTCONNECTIONS > 0 )) && (( CLIENTCONNECTIONS == 0 )) && [[ "$RCON_CMDS_FIRST_CONNECT" ]]; then + logRcon "First Clients has Connected, running first connect cmds" + while read -r cmd; do + run_command "$cmd" + done <<< "$RCON_CMDS_FIRST_CONNECT" + # Last client connection + elif (( CURR_CLIENTCONNECTIONS == 0 )) && (( CLIENTCONNECTIONS > 0 )) && [[ "$RCON_CMDS_LAST_DISCONNECT" ]]; then + logRcon "ALL Clients have Disconnected, running last disconnect cmds" + while read -r cmd; do + run_command "$cmd" + done <<< "$RCON_CMDS_LAST_DISCONNECT" + fi CLIENTCONNECTIONS=$CURR_CLIENTCONNECTIONS ;; *) diff --git a/scripts/start-configuration b/scripts/start-configuration index 2c91a286..692a339d 100755 --- a/scripts/start-configuration +++ b/scripts/start-configuration @@ -11,6 +11,8 @@ IFS=$'\n\t' : "${RCON_CMDS_STARTUP:=}" : "${RCON_CMDS_ON_CONNECT:=}" : "${RCON_CMDS_ON_DISCONNECT:=}" +: "${RCON_CMDS_FIRST_CONNECT:=}" +: "${RCON_CMDS_LAST_DISCONNECT:=}" : "${RCON_CMDS_PERIOD:=10}" shopt -s nullglob @@ -128,7 +130,13 @@ if isTrue "${ENABLE_AUTOSTOP}"; then ${SCRIPTS:-/}start-autostop fi -if [[ "$RCON_CMDS_STARTUP" ]] || [[ "$RCON_CMDS_ON_CONNECT" ]] || [[ "$RCON_CMDS_ON_DISCONNECT" ]]; then +if + [[ "$RCON_CMDS_STARTUP" ]] || + [[ "$RCON_CMDS_ON_CONNECT" ]] || + [[ "$RCON_CMDS_ON_DISCONNECT" ]] || + [[ "$RCON_CMDS_FIRST_CONNECT" ]] || + [[ "$RCON_CMDS_LAST_DISCONNECT" ]] +then log "Starting RCON commands" # shellcheck source=start-rconcmds ${SCRIPTS:-/}start-rconcmds diff --git a/scripts/start-rconcmds b/scripts/start-rconcmds index ecdda81e..28fbfeee 100644 --- a/scripts/start-rconcmds +++ b/scripts/start-rconcmds @@ -6,11 +6,14 @@ : "${RCON_CMDS_STARTUP:=}" : "${RCON_CMDS_ON_CONNECT:=}" : "${RCON_CMDS_ON_DISCONNECT:=}" +: "${RCON_CMDS_FIRST_CONNECT:=}" +: "${RCON_CMDS_LAST_DISCONNECT:=}" : "${RCON_CMDS_PERIOD:=10}" : "${SERVER_PORT:=25565}" export RCON_CMDS_STARTUP export RCON_CMDS_ON_CONNECT export RCON_CMDS_ON_DISCONNECT +export RCON_CMDS_LAST_DISCONNECT export RCON_CMDS_PERIOD export SERVER_PORT