From 8c378d21cbc4537885b04f8292e0e1233feecf2e Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Sun, 21 Jan 2024 15:52:19 -0600 Subject: [PATCH 01/16] use /bin/bash instead of .bat files --- .vscode/scripts/copy.bat | 36 ------------------------------------ .vscode/scripts/launch.bat | 36 ------------------------------------ .vscode/tasks.json | 30 +++++++++++------------------- 3 files changed, 11 insertions(+), 91 deletions(-) delete mode 100644 .vscode/scripts/copy.bat delete mode 100644 .vscode/scripts/launch.bat diff --git a/.vscode/scripts/copy.bat b/.vscode/scripts/copy.bat deleted file mode 100644 index baadd34..0000000 --- a/.vscode/scripts/copy.bat +++ /dev/null @@ -1,36 +0,0 @@ -@echo off -setlocal - -:: If there's an env file defined, load the environment variables from it -if exist "%ENV_FILE%" ( - for /f "delims=" %%i in (%ENV_FILE%) do set %%i -) - -:: Make sure a JAR file is specified -if not exist "%JAR_FILE%" ( - echo No JAR file specified. %JAR_FILE% - exit /b 1 -) - -:: Make sure SERVER_DIRECTORY is set -if "%SERVER_DIRECTORY%"=="" ( - echo SERVER_DIRECTORY is not set. Please set it via an environment variable. - exit /b 1 -) - -:: Make sure SERVER_DIRECTORY exists -if not exist "%SERVER_DIRECTORY%" ( - echo The server directory at %SERVER_DIRECTORY% does not exist. Please create one and try again. - exit /b 1 -) - -:: Check that the server directory has a paper*.jar -if not exist "%SERVER_DIRECTORY%\paper*.jar" ( - echo No Paper JAR found in %SERVER_DIRECTORY%. Please place a Paper JAR in the directory and try again. - exit /b 1 -) - -:: Copy JAR file to server directory -echo Copying %JAR_FILE% to %SERVER_DIRECTORY%/plugins -mkdir "%SERVER_DIRECTORY%\plugins" -copy /Y "%JAR_FILE%" "%SERVER_DIRECTORY%\plugins" diff --git a/.vscode/scripts/launch.bat b/.vscode/scripts/launch.bat deleted file mode 100644 index 8316e84..0000000 --- a/.vscode/scripts/launch.bat +++ /dev/null @@ -1,36 +0,0 @@ -@echo off -setlocal - -:: If there's an env file defined, load the environment variables from it -if exist "%ENV_FILE%" ( - for /f "delims=" %%i in (%ENV_FILE%) do set %%i -) - -:: Make sure SERVER_DIRECTORY is set -if "%SERVER_DIRECTORY%"=="" ( - echo SERVER_DIRECTORY is not set. Please set it via an environment variable. - exit /b 1 -) - -:: Make sure SERVER_DIRECTORY exists -if not exist "%SERVER_DIRECTORY%" ( - echo The server directory at %SERVER_DIRECTORY% does not exist. Please create one and try again. - exit /b 1 -) - -:: Check that the server directory has a paper*.jar -if not exist "%SERVER_DIRECTORY%\paper*.jar" ( - echo No Paper JAR found in %SERVER_DIRECTORY%. Please place a Paper JAR in the directory and try again. - exit /b 1 -) - -:: Check if SERVER_ARGS is set, otherwise set it to "-Xmx1024M -Xms512M" -if "%SERVER_ARGS%"=="" ( - set "SERVER_ARGS=-Xmx1024M -Xms512M" - echo Using %SERVER_ARGS% as SERVER_ARGS. -) - -:: Start the server -echo Starting server.. -cd /d "%SERVER_DIRECTORY%" -java %SERVER_ARGS% -Dcom.mojang.eula.agree=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar "%SERVER_DIRECTORY%\paper*.jar" nogui diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3d26360..2c5465a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,19 +2,13 @@ "version": "2.0.0", "tasks": [ { - "label": "Set permissions for scripts", - "hide": true, + "label": "Script: Set permissions for scripts", "type": "shell", - "command": "chmod +x ${workspaceFolder}/.vscode/scripts/*.sh", - "windows": { - "command": "echo Bill Gates" - }, + "command": "/bin/bash -c \"chmod +x ${workspaceFolder}/.vscode/scripts/*.sh\" && echo Permissions set.", "presentation": { - "reveal": "never", "echo": false, "showReuseMessage": false, - "close": true, - "revealProblems": "never" + "clear": true }, "problemMatcher": [] }, @@ -34,15 +28,13 @@ { "label": "Build and copy JAR to plugin directory", "dependsOn": [ - "Set permissions for scripts", "Build regular-place-kit" ], - "dependsOrder": "sequence", "type": "shell", - "command": "${workspaceFolder}/.vscode/scripts/copy.sh", - "windows": { - "command": "${workspaceFolder}/.vscode/scripts/copy.bat" - }, + "command": "/bin/bash", + "args": [ + "${workspaceFolder}/.vscode/scripts/copy.sh" + ], "options": { "env": { "ENV_FILE": "${workspaceFolder}/.env", @@ -59,10 +51,10 @@ { "label": "Start Paper server", "type": "shell", - "command": "${workspaceFolder}/.vscode/scripts/launch.sh", - "windows": { - "command": "${workspaceFolder}/.vscode/scripts/launch.bat" - }, + "command": "/bin/bash", + "args": [ + "${workspaceFolder}/.vscode/scripts/launch.sh" + ], "isBackground": true, "presentation": { "echo": true, From e8681346d34092ceb3d4d97beb8044cb5cba3b08 Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Sun, 21 Jan 2024 15:59:38 -0600 Subject: [PATCH 02/16] remove unix labels --- .vscode/scripts/copy.sh | 1 - .vscode/scripts/launch.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/.vscode/scripts/copy.sh b/.vscode/scripts/copy.sh index 6ca5b22..ca49f74 100755 --- a/.vscode/scripts/copy.sh +++ b/.vscode/scripts/copy.sh @@ -1,5 +1,4 @@ #!/bin/bash -# Unix-like # If there's an env file defined, load the environment variables from it if [ -f "$ENV_FILE" ]; then diff --git a/.vscode/scripts/launch.sh b/.vscode/scripts/launch.sh index 7669570..e4395b5 100755 --- a/.vscode/scripts/launch.sh +++ b/.vscode/scripts/launch.sh @@ -1,5 +1,4 @@ #!/bin/bash -# Unix-like # If there's an env file defined, load the environment variables from it if [ -f "$ENV_FILE" ]; then From 64c58a7beb808dd5ddbabf3bd495ba80db3cf812 Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Sun, 21 Jan 2024 16:25:54 -0600 Subject: [PATCH 03/16] rename scripts --- .vscode/scripts/{copy.sh => copy-build.sh} | 0 .vscode/scripts/{launch.sh => start-server.sh} | 0 .vscode/tasks.json | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename .vscode/scripts/{copy.sh => copy-build.sh} (100%) rename .vscode/scripts/{launch.sh => start-server.sh} (100%) diff --git a/.vscode/scripts/copy.sh b/.vscode/scripts/copy-build.sh similarity index 100% rename from .vscode/scripts/copy.sh rename to .vscode/scripts/copy-build.sh diff --git a/.vscode/scripts/launch.sh b/.vscode/scripts/start-server.sh similarity index 100% rename from .vscode/scripts/launch.sh rename to .vscode/scripts/start-server.sh diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2c5465a..0b1e487 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -33,7 +33,7 @@ "type": "shell", "command": "/bin/bash", "args": [ - "${workspaceFolder}/.vscode/scripts/copy.sh" + "${workspaceFolder}/.vscode/scripts/copy-build.sh" ], "options": { "env": { @@ -53,7 +53,7 @@ "type": "shell", "command": "/bin/bash", "args": [ - "${workspaceFolder}/.vscode/scripts/launch.sh" + "${workspaceFolder}/.vscode/scripts/start-server.sh" ], "isBackground": true, "presentation": { From 62055478809ffc8874d1c8c1ab5e1cb3334bce66 Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Sun, 21 Jan 2024 18:09:52 -0600 Subject: [PATCH 04/16] add project.properties --- project.properties | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 project.properties diff --git a/project.properties b/project.properties new file mode 100644 index 0000000..f8e2cec --- /dev/null +++ b/project.properties @@ -0,0 +1,2 @@ +MINECRAFT_VERSION=1.20.2 +PAPER_BUILD=318 \ No newline at end of file From baf2154cd1a1f29a46c4560193fc777d0e466b31 Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Sun, 21 Jan 2024 18:10:07 -0600 Subject: [PATCH 05/16] update scripts and tasks --- .vscode/scripts/copy-build.sh | 35 ------------ .vscode/scripts/start-server.sh | 35 ------------ .vscode/tasks.json | 94 ++++++++++++++++++++++++++------- scripts/copy-build.sh | 17 ++++++ scripts/create-server-dir.sh | 29 ++++++++++ scripts/enforce-env-jar.sh | 10 ++++ scripts/enforce-server-jar.sh | 51 ++++++++++++++++++ scripts/get-env.sh | 7 +++ scripts/project-properties.sh | 12 +++++ scripts/replace-server-jar.sh | 25 +++++++++ scripts/start-server.sh | 19 +++++++ scripts/update-build.sh | 21 ++++++++ scripts/update-patch.sh | 30 +++++++++++ scripts/update-version.sh | 18 +++++++ 14 files changed, 315 insertions(+), 88 deletions(-) delete mode 100755 .vscode/scripts/copy-build.sh delete mode 100755 .vscode/scripts/start-server.sh create mode 100755 scripts/copy-build.sh create mode 100755 scripts/create-server-dir.sh create mode 100755 scripts/enforce-env-jar.sh create mode 100755 scripts/enforce-server-jar.sh create mode 100755 scripts/get-env.sh create mode 100755 scripts/project-properties.sh create mode 100755 scripts/replace-server-jar.sh create mode 100755 scripts/start-server.sh create mode 100755 scripts/update-build.sh create mode 100755 scripts/update-patch.sh create mode 100755 scripts/update-version.sh diff --git a/.vscode/scripts/copy-build.sh b/.vscode/scripts/copy-build.sh deleted file mode 100755 index ca49f74..0000000 --- a/.vscode/scripts/copy-build.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# If there's an env file defined, load the environment variables from it -if [ -f "$ENV_FILE" ]; then - export $(cat "$ENV_FILE" | xargs) >/dev/null 2>&1 -fi - -# Make sure a JAR file is specified -if [ ! -f "$JAR_FILE" ]; then - echo "No JAR file specified. $JAR_FILE" - exit 1 -fi - -# Make sure SERVER_DIRECTORY is set -if [ -z "$SERVER_DIRECTORY" ]; then - echo "SERVER_DIRECTORY is not set. Please set it via an environment variable." - exit 1 -fi - -# Make sure SERVER_DIRECTORY exists -if [ ! -d "$SERVER_DIRECTORY" ]; then - echo "The server directory at $SERVER_DIRECTORY does not exist. Please create one and try again." - exit 1 -fi - -# Check that the server directory has a paper*.jar -if [ ! -f "$SERVER_DIRECTORY"/paper*.jar ]; then - echo "No Paper JAR found in $SERVER_DIRECTORY. Please place a Paper JAR in the directory and try again." - exit 1 -fi - -# Copy JAR file to server directory -echo "Copying $JAR_FILE to $SERVER_DIRECTORY/plugins" -mkdir -p "$SERVER_DIRECTORY/plugins" -cp "$JAR_FILE" "$SERVER_DIRECTORY/plugins" \ No newline at end of file diff --git a/.vscode/scripts/start-server.sh b/.vscode/scripts/start-server.sh deleted file mode 100755 index e4395b5..0000000 --- a/.vscode/scripts/start-server.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# If there's an env file defined, load the environment variables from it -if [ -f "$ENV_FILE" ]; then - export $(cat "$ENV_FILE" | xargs) >/dev/null 2>&1 -fi - -# Make sure SERVER_DIRECTORY is set -if [ -z "$SERVER_DIRECTORY" ]; then - echo "SERVER_DIRECTORY is not set. Please set it via an environment variable." - exit 1 -fi - -# Make sure SERVER_DIRECTORY exists -if [ ! -d "$SERVER_DIRECTORY" ]; then - echo "The server directory at $SERVER_DIRECTORY does not exist. Please create one and try again." - exit 1 -fi - -# Check that the server directory has a paper*.jar -if [ ! -f "$SERVER_DIRECTORY"/paper*.jar ]; then - echo "No Paper JAR found in $SERVER_DIRECTORY. Please place a Paper JAR in the directory and try again." - exit 1 -fi - -# Check if SERVER_ARGS is set, otherwise set it to "-Xmx1024M -Xms512M" -if [ -z "$SERVER_ARGS" ]; then - export SERVER_ARGS="-Xmx1024M -Xms512M" - echo "Using $SERVER_ARGS as SERVER_ARGS." -fi - -# Start the server -echo "Starting server.." -cd "$SERVER_DIRECTORY" -java $SERVER_ARGS -Dcom.mojang.eula.agree=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar "$SERVER_DIRECTORY"/paper*.jar nogui \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0b1e487..0f3483e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,13 +1,24 @@ { "version": "2.0.0", + "presentation": { + "echo": false, + "showReuseMessage": false, + "clear": false + }, + "options": { + "cwd": "${workspaceFolder}", + "env": { + "ENV_FILE": "${workspaceFolder}/.env", + "SERVER_DIRECTORY": "${workspaceFolder}/server", + "JAR_FILE": "${workspaceFolder}/target/regular-place-kit.jar" + } + }, "tasks": [ { "label": "Script: Set permissions for scripts", "type": "shell", - "command": "/bin/bash -c \"chmod +x ${workspaceFolder}/.vscode/scripts/*.sh\" && echo Permissions set.", + "command": "/bin/bash -c \"chmod +x ${workspaceFolder}/scripts/*.sh\" && echo Permissions set.", "presentation": { - "echo": false, - "showReuseMessage": false, "clear": true }, "problemMatcher": [] @@ -33,15 +44,8 @@ "type": "shell", "command": "/bin/bash", "args": [ - "${workspaceFolder}/.vscode/scripts/copy-build.sh" + "${workspaceFolder}/scripts/copy-build.sh" ], - "options": { - "env": { - "ENV_FILE": "${workspaceFolder}/.env", - "SERVER_DIRECTORY": "${workspaceFolder}/server", - "JAR_FILE": "${workspaceFolder}/target/regular-place-kit.jar" - } - }, "group": { "kind": "build", "isDefault": true @@ -53,7 +57,7 @@ "type": "shell", "command": "/bin/bash", "args": [ - "${workspaceFolder}/.vscode/scripts/start-server.sh" + "${workspaceFolder}/scripts/start-server.sh" ], "isBackground": true, "presentation": { @@ -67,12 +71,6 @@ "group": { "kind": "test" }, - "options": { - "env": { - "ENV_FILE": "${workspaceFolder}/.env", - "SERVER_DIRECTORY": "${workspaceFolder}/server" - } - }, "problemMatcher": { "owner": "java", "fileLocation": [ @@ -113,6 +111,66 @@ }, "hide": true, "problemMatcher": [] + }, + { + "label": "Script: Update Minecraft version", + "hide": true, + "type": "shell", + "command": "/bin/bash", + "args": [ + "${workspaceFolder}/scripts/update-version.sh" + ], + "presentation": { + "echo": false, + "showReuseMessage": false + }, + "problemMatcher": [] + }, + { + "label": "Script: Update Minecraft patch", + "hide": true, + "type": "shell", + "command": "/bin/bash", + "args": [ + "${workspaceFolder}/scripts/update-patch.sh" + ], + "problemMatcher": [] + }, + { + "label": "Project: Update Paper build", + "type": "shell", + "command": "/bin/bash", + "args": [ + "${workspaceFolder}/scripts/update-build.sh" + ], + "problemMatcher": [] + }, + { + "label": "Project: Update Minecraft version", + "dependsOn": [ + "Script: Update Minecraft version", + "Project: Update Paper build", + ], + "dependsOrder": "sequence", + "problemMatcher": [] + }, + { + "label": "Project: Update Minecraft patch", + "dependsOn": [ + "Script: Update Minecraft patch", + "Project: Update Paper build", + ], + "dependsOrder": "sequence", + "problemMatcher": [] + }, + { + "label": "Replace Paper server JAR with correct build", + "type": "shell", + "command": "/bin/bash", + "args": [ + "${workspaceFolder}/scripts/replace-server-jar.sh" + ], + "problemMatcher": [] } ], "inputs": [ diff --git a/scripts/copy-build.sh b/scripts/copy-build.sh new file mode 100755 index 0000000..53ce726 --- /dev/null +++ b/scripts/copy-build.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +# Enforce that the built JAR file is specified in the environment +./scripts/enforce-env-jar.sh + +# Create the server directory if it doesn't exist +./scripts/create-server-dir.sh + +# Get the environment variables +source ./scripts/get-env.sh + +# Copy JAR file to server directory +echo "Copying $JAR_FILE to $SERVER_DIRECTORY/plugins" +mkdir -p "$SERVER_DIRECTORY/plugins" +cp "$JAR_FILE" "$SERVER_DIRECTORY/plugins" +echo "Done!" \ No newline at end of file diff --git a/scripts/create-server-dir.sh b/scripts/create-server-dir.sh new file mode 100755 index 0000000..adb0daf --- /dev/null +++ b/scripts/create-server-dir.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +source ./scripts/get-env.sh + +# Make sure SERVER_DIRECTORY is set +if [ -z "$SERVER_DIRECTORY" ]; then + echo "SERVER_DIRECTORY is not set. Please set it via an environment variable." + exit 1 +fi + +# Make sure SERVER_DIRECTORY exists +if [ ! -d "$SERVER_DIRECTORY" ]; then + echo "The server directory at $SERVER_DIRECTORY does not exist." + + # Ask if we should create the directory + read -p "Would you like to create it? [Y/n] " -n 1 -r + echo # Move to a new line + + # If the user says yes, create the directory + if [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Creating the directory.." + mkdir -p "$SERVER_DIRECTORY" + echo "Created the Minecraft server directory. Proceeding.." + else + echo "Please create the directory and try again." + exit 1 + fi +fi \ No newline at end of file diff --git a/scripts/enforce-env-jar.sh b/scripts/enforce-env-jar.sh new file mode 100755 index 0000000..5c49483 --- /dev/null +++ b/scripts/enforce-env-jar.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +source ./scripts/get-env.sh + +# Make sure a JAR file is specified +if [ ! -f "$JAR_FILE" ]; then + echo "No JAR file specified. $JAR_FILE" + exit 1 +fi \ No newline at end of file diff --git a/scripts/enforce-server-jar.sh b/scripts/enforce-server-jar.sh new file mode 100755 index 0000000..77bf624 --- /dev/null +++ b/scripts/enforce-server-jar.sh @@ -0,0 +1,51 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +# Check for the auto-download flag +AUTO_DOWNLOAD=false + +for arg in "$@"; do + case $arg in + --force|-f) + AUTO_DOWNLOAD=true + shift # Remove --force or -f from processing + ;; + *) + # Unknown option + ;; + esac +done + +# Create the server directory if it doesn't exist +./scripts/create-server-dir.sh + +# Get the environment variables and project properties +source ./scripts/get-env.sh +source ./scripts/project-properties.sh + +# Check that the server directory has a paper*.jar +if [ ! -f "$SERVER_DIRECTORY"/paper*.jar ]; then + DOWNLOAD=false + + if [ "$AUTO_DOWNLOAD" = true ]; then + DOWNLOAD=true + else + echo "No Paper JAR found in $SERVER_DIRECTORY." + # Ask if we should download the Paper JAR for Minecraft $MINECRAFT_VERSION build $PAPER_BUILD + read -p "Would you like to download it (Minecraft $MINECRAFT_VERSION, build $PAPER_BUILD)? [Y/n] " -n 1 -r + echo # Move to a new line + + if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then + DOWNLOAD=true + fi + fi + + if [ "$DOWNLOAD" = true ]; then + echo "Downloading the Paper JAR.." + curl -o "$SERVER_DIRECTORY/$SERVER_JAR_NAME" "https://papermc.io/api/v2/projects/paper/versions/$MINECRAFT_VERSION/builds/$PAPER_BUILD/downloads/$SERVER_JAR_NAME" + echo "Downloaded the Paper JAR. Proceeding.." + else + echo "Please download the Paper JAR and try again." + exit 1 + fi +fi diff --git a/scripts/get-env.sh b/scripts/get-env.sh new file mode 100755 index 0000000..386fe4c --- /dev/null +++ b/scripts/get-env.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +# Check if the ENV_FILE variable is set and the file exists +if [ -f "$ENV_FILE" ]; then + export $(grep -v '^#' "$ENV_FILE" | xargs) +fi diff --git a/scripts/project-properties.sh b/scripts/project-properties.sh new file mode 100755 index 0000000..85f7b54 --- /dev/null +++ b/scripts/project-properties.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +MINECRAFT_VERSION=$(grep "^MINECRAFT_VERSION=" project.properties | cut -d'=' -f2) +PAPER_BUILD=$(grep "^PAPER_BUILD=" project.properties | cut -d'=' -f2) +SERVER_JAR_NAME="paper-$MINECRAFT_VERSION-$PAPER_BUILD.jar" + +# Enforce that MINECRAFT_VERSION and PAPER_BUILD are set +if [ -z "$MINECRAFT_VERSION" ] || [ -z "$PAPER_BUILD" ]; then + echo "MINECRAFT_VERSION and PAPER_BUILD must be set in project.properties." + exit 1 +fi \ No newline at end of file diff --git a/scripts/replace-server-jar.sh b/scripts/replace-server-jar.sh new file mode 100755 index 0000000..b979057 --- /dev/null +++ b/scripts/replace-server-jar.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +# Create the server directory if it doesn't exist +./scripts/create-server-dir.sh + +# Get the environment variables and project properties +source ./scripts/get-env.sh +source ./scripts/project-properties.sh + +# Check if the server directory has a $SERVER_JAR_NAME file +if [ ! -f "$SERVER_DIRECTORY/$SERVER_JAR_NAME" ]; then + # Check if the server directory has a paper*.jar file + if [ -f "$SERVER_DIRECTORY/paper*.jar" ]; then + # Move all paper*.jar files to the previous_jars directory + mkdir -p "$SERVER_DIRECTORY/previous_jars" + mv "$SERVER_DIRECTORY"/paper*.jar "$SERVER_DIRECTORY/previous_jars" + fi + + # Download the Paper JAR without asking for confirmation + ./scripts/enforce-server-jar.sh --force + echo "Done!" +else + echo "Server directory already running the proper build of Paper. No need to replace it!" +fi diff --git a/scripts/start-server.sh b/scripts/start-server.sh new file mode 100755 index 0000000..101c753 --- /dev/null +++ b/scripts/start-server.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +# Create the server directory if it doesn't exist +./scripts/create-server-dir.sh + +# Enforce that the server directory has a Paper JAR +./scripts/enforce-server-jar.sh + +# Check if SERVER_ARGS is set, otherwise set it to "-Xmx1024M -Xms512M" +if [ -z "$SERVER_ARGS" ]; then + export SERVER_ARGS="-Xmx1024M -Xms512M" + echo "Using $SERVER_ARGS as SERVER_ARGS." +fi + +# Start the server +echo "Starting server.." +cd "$SERVER_DIRECTORY" +java $SERVER_ARGS -Dcom.mojang.eula.agree=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar "$SERVER_DIRECTORY"/paper*.jar nogui \ No newline at end of file diff --git a/scripts/update-build.sh b/scripts/update-build.sh new file mode 100755 index 0000000..675972a --- /dev/null +++ b/scripts/update-build.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +# Extract the current MINECRAFT_VERSION from project.properties +PREVIOUS_VERSION=$(grep "^MINECRAFT_VERSION=" project.properties | cut -d'=' -f2) + +# Fetch the JSON data from the PaperMC API +RESPONSE=$(curl -s "https://api.papermc.io/v2/projects/paper/versions/$PREVIOUS_VERSION") + +# Parse the JSON to get the latest build +BUILD=$(echo $RESPONSE | jq -r '.builds[-1]') + +# Check if the build was successfully retrieved +if [ -z "$BUILD" ]; then + echo "No build found in the API response from PaperMC." + exit 1 +fi + +# Replace PAPER_BUILD in project.properties with the build +sed -i '' "s/^PAPER_BUILD=.*/PAPER_BUILD=$BUILD/" project.properties +echo "Updated PAPER_BUILD to $BUILD in project.properties" \ No newline at end of file diff --git a/scripts/update-patch.sh b/scripts/update-patch.sh new file mode 100755 index 0000000..e6511ff --- /dev/null +++ b/scripts/update-patch.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +# Extract the current MINECRAFT_VERSION from project.properties +PREVIOUS_VERSION=$(grep "^MINECRAFT_VERSION=" project.properties | cut -d'=' -f2) + +# Extract version group (major.minor) +VERSION_GROUP=$(echo $PREVIOUS_VERSION | grep -oE '^[0-9]+\.[0-9]+') + +# Check if version group was successfully extracted +if [ -z "$VERSION_GROUP" ]; then + echo "Failed to determine the version group from MINECRAFT_VERSION in project.properties." + exit 1 +fi + +# Fetch the JSON data from the PaperMC API +API_RESPONSE=$(curl -s "https://api.papermc.io/v2/projects/paper/version_group/$VERSION_GROUP") + +# Parse the JSON to get the version +VERSION=$(echo $API_RESPONSE | jq -r '.versions[-1]') + +# Check if the version was successfully retrieved +if [ -z "$VERSION" ]; then + echo "No version found in the API response from PaperMC." + exit 1 +fi + +# Replace MINECRAFT_VERSION in project.properties with the version +sed -i '' "s/^MINECRAFT_VERSION=.*/MINECRAFT_VERSION=$VERSION/" project.properties +echo "Updated MINECRAFT_VERSION to $VERSION in project.properties" diff --git a/scripts/update-version.sh b/scripts/update-version.sh new file mode 100755 index 0000000..094e90e --- /dev/null +++ b/scripts/update-version.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +# Fetch the JSON data from the PaperMC API +RESPONSE=$(curl -s "https://api.papermc.io/v2/projects/paper") + +# Parse the JSON to get the last version +VERSION=$(echo $RESPONSE | jq -r '.versions[-1]') + +# Check if the last version was successfully retrieved +if [ -z "$VERSION" ]; then + echo "No version found in the API response from PaperMC." + exit 1 +fi + +# Replace MINECRAFT_VERSION in project.properties with the retrieved version +sed -i "s/^MINECRAFT_VERSION=.*/MINECRAFT_VERSION=$VERSION/" project.properties +echo "Updated project.properties MINECRAFT_VERSION to $VERSION." From 4c6a9039467c0e7b09024401d005a809de5ebedf Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Sun, 21 Jan 2024 18:32:36 -0600 Subject: [PATCH 06/16] add script to update pom automatically --- .vscode/tasks.json | 11 +++++++++++ scripts/update-pom.sh | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 scripts/update-pom.sh diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0f3483e..4992788 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -136,6 +136,15 @@ ], "problemMatcher": [] }, + { + "label": "Script: Update pom to match project properties", + "type": "shell", + "command": "/bin/bash", + "args": [ + "${workspaceFolder}/scripts/update-pom.sh" + ], + "problemMatcher": [] + }, { "label": "Project: Update Paper build", "type": "shell", @@ -150,6 +159,7 @@ "dependsOn": [ "Script: Update Minecraft version", "Project: Update Paper build", + "Script: Update pom to match project properties" ], "dependsOrder": "sequence", "problemMatcher": [] @@ -159,6 +169,7 @@ "dependsOn": [ "Script: Update Minecraft patch", "Project: Update Paper build", + "Script: Update pom to match project properties" ], "dependsOrder": "sequence", "problemMatcher": [] diff --git a/scripts/update-pom.sh b/scripts/update-pom.sh new file mode 100755 index 0000000..7b00a52 --- /dev/null +++ b/scripts/update-pom.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e # Exit script immediately on first error. + +POM_FILE="./pom.xml" + +# Check if the pom.xml file exists +if [ ! -f "$POM_FILE" ]; then + echo "pom.xml file at $POM_FILE not found." + exit 1 +fi + +# Get the project properties +source ./scripts/project-properties.sh + +# Update the paper-api version +sed -i '' "/paper-api<\/artifactId>/{n;s/.*<\/version>/${MINECRAFT_VERSION}-R0.1-SNAPSHOT<\/version>/;}" "$POM_FILE" +echo "Updated paper-api version to ${MINECRAFT_VERSION}-R0.1-SNAPSHOT in pom.xml" \ No newline at end of file From f6ee75a3582489e136162cabc70a2b1e9e59471a Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Mon, 22 Jan 2024 14:32:08 -0600 Subject: [PATCH 07/16] add readme to properties task --- .vscode/tasks.json | 6 +++--- scripts/update-pom.sh | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4992788..ba289e3 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -137,7 +137,7 @@ "problemMatcher": [] }, { - "label": "Script: Update pom to match project properties", + "label": "Script: Update pom/README to match project properties", "type": "shell", "command": "/bin/bash", "args": [ @@ -159,7 +159,7 @@ "dependsOn": [ "Script: Update Minecraft version", "Project: Update Paper build", - "Script: Update pom to match project properties" + "Script: Update pom/README to match project properties" ], "dependsOrder": "sequence", "problemMatcher": [] @@ -169,7 +169,7 @@ "dependsOn": [ "Script: Update Minecraft patch", "Project: Update Paper build", - "Script: Update pom to match project properties" + "Script: Update pom/README to match project properties" ], "dependsOrder": "sequence", "problemMatcher": [] diff --git a/scripts/update-pom.sh b/scripts/update-pom.sh index 7b00a52..d453e43 100755 --- a/scripts/update-pom.sh +++ b/scripts/update-pom.sh @@ -2,16 +2,51 @@ set -e # Exit script immediately on first error. POM_FILE="./pom.xml" +README_FILE="./README.md" +GUIDE_FILE="./guides/Beginners.md" +# Verbose.. # Check if the pom.xml file exists if [ ! -f "$POM_FILE" ]; then echo "pom.xml file at $POM_FILE not found." exit 1 fi +# Check if the README.md file exists +if [ ! -f "$README_FILE" ]; then + echo "README.md file at $README_FILE not found." + exit 1 +fi + +# Check if the guides/Beginners.md file exists +if [ ! -f "$GUIDE_FILE" ]; then + echo "Beginners.md file at $GUIDE_FILE not found." + exit 1 +fi + # Get the project properties source ./scripts/project-properties.sh -# Update the paper-api version -sed -i '' "/paper-api<\/artifactId>/{n;s/.*<\/version>/${MINECRAFT_VERSION}-R0.1-SNAPSHOT<\/version>/;}" "$POM_FILE" -echo "Updated paper-api version to ${MINECRAFT_VERSION}-R0.1-SNAPSHOT in pom.xml" \ No newline at end of file +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + + # Update the paper-api version in pom.xml + sed -i '' "/paper-api<\/artifactId>/{n;s/.*<\/version>/${MINECRAFT_VERSION}-R0.1-SNAPSHOT<\/version>/;}" "$POM_FILE" + echo "Updated paper-api version to ${MINECRAFT_VERSION}-R0.1-SNAPSHOT in pom.xml" + + # Update the .md files + sed -i '' "s/.*/${MINECRAFT_VERSION}/g" "$README_FILE" + sed -i '' "s/.*/${MINECRAFT_VERSION}/g" "$GUIDE_FILE" + echo "Updated .md files with Minecraft version ${MINECRAFT_VERSION}" +else + # Linux + + # Update the paper-api version in pom.xml + sed -i "/paper-api<\/artifactId>/{n;s/.*<\/version>/${MINECRAFT_VERSION}-R0.1-SNAPSHOT<\/version>/;}" "$POM_FILE" + echo "Updated paper-api version to ${MINECRAFT_VERSION}-R0.1-SNAPSHOT in pom.xml" + + # Update the .md files + sed -i "s/.*/${MINECRAFT_VERSION}/g" "$README_FILE" + sed -i "s/.*/${MINECRAFT_VERSION}/g" "$GUIDE_FILE" + echo "Updated .md files with Minecraft version ${MINECRAFT_VERSION}" +fi From 55f767a5e9e50840d76217e02ea68c47aaa64c3a Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Mon, 22 Jan 2024 14:32:15 -0600 Subject: [PATCH 08/16] update scripts to work with Linux --- scripts/update-build.sh | 8 +++++++- scripts/update-patch.sh | 8 +++++++- scripts/update-version.sh | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/scripts/update-build.sh b/scripts/update-build.sh index 675972a..ca0560e 100755 --- a/scripts/update-build.sh +++ b/scripts/update-build.sh @@ -17,5 +17,11 @@ if [ -z "$BUILD" ]; then fi # Replace PAPER_BUILD in project.properties with the build -sed -i '' "s/^PAPER_BUILD=.*/PAPER_BUILD=$BUILD/" project.properties +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + sed -i '' "s/^PAPER_BUILD=.*/PAPER_BUILD=$BUILD/" project.properties +else + # Linux + sed -i "s/^PAPER_BUILD=.*/PAPER_BUILD=$BUILD/" project.properties +fi echo "Updated PAPER_BUILD to $BUILD in project.properties" \ No newline at end of file diff --git a/scripts/update-patch.sh b/scripts/update-patch.sh index e6511ff..f7d239e 100755 --- a/scripts/update-patch.sh +++ b/scripts/update-patch.sh @@ -26,5 +26,11 @@ if [ -z "$VERSION" ]; then fi # Replace MINECRAFT_VERSION in project.properties with the version -sed -i '' "s/^MINECRAFT_VERSION=.*/MINECRAFT_VERSION=$VERSION/" project.properties +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + sed -i '' "s/^MINECRAFT_VERSION=.*/MINECRAFT_VERSION=$VERSION/" project.properties +else + # Linux + sed -i "s/^MINECRAFT_VERSION=.*/MINECRAFT_VERSION=$VERSION/" project.properties +fi echo "Updated MINECRAFT_VERSION to $VERSION in project.properties" diff --git a/scripts/update-version.sh b/scripts/update-version.sh index 094e90e..018fb2a 100755 --- a/scripts/update-version.sh +++ b/scripts/update-version.sh @@ -14,5 +14,11 @@ if [ -z "$VERSION" ]; then fi # Replace MINECRAFT_VERSION in project.properties with the retrieved version -sed -i "s/^MINECRAFT_VERSION=.*/MINECRAFT_VERSION=$VERSION/" project.properties +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + sed -i '' "s/^MINECRAFT_VERSION=.*/MINECRAFT_VERSION=$VERSION/" project.properties +else + # Linux + sed -i "s/^MINECRAFT_VERSION=.*/MINECRAFT_VERSION=$VERSION/" project.properties +fi echo "Updated project.properties MINECRAFT_VERSION to $VERSION." From 178f125c7bc5283e138bf015923f80e58a021329 Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Tue, 23 Jan 2024 05:24:51 -0600 Subject: [PATCH 09/16] continue work --- .vscode/tasks.json | 58 +++++++++++++------------- scripts/cmd/copy-build.cmd | 26 ++++++++++++ scripts/cmd/create-server-dir.cmd | 33 +++++++++++++++ scripts/cmd/enforce-env-jar.cmd | 14 +++++++ scripts/cmd/enforce-server-jar.cmd | 54 ++++++++++++++++++++++++ scripts/cmd/get-env.cmd | 21 ++++++++++ scripts/cmd/project-properties.cmd | 15 +++++++ scripts/cmd/replace-server-jar.cmd | 34 +++++++++++++++ scripts/cmd/start-server.cmd | 25 +++++++++++ scripts/cmd/update-build.cmd | 24 +++++++++++ scripts/cmd/update-patch.cmd | 33 +++++++++++++++ scripts/cmd/update-pom.cmd | 40 ++++++++++++++++++ scripts/cmd/update-version.cmd | 21 ++++++++++ scripts/{ => sh}/copy-build.sh | 6 +-- scripts/{ => sh}/create-server-dir.sh | 2 +- scripts/{ => sh}/enforce-env-jar.sh | 2 +- scripts/{ => sh}/enforce-server-jar.sh | 6 +-- scripts/{ => sh}/get-env.sh | 0 scripts/{ => sh}/project-properties.sh | 0 scripts/{ => sh}/replace-server-jar.sh | 8 ++-- scripts/{ => sh}/start-server.sh | 4 +- scripts/{ => sh}/update-build.sh | 0 scripts/{ => sh}/update-patch.sh | 0 scripts/{ => sh}/update-pom.sh | 2 +- scripts/{ => sh}/update-version.sh | 0 25 files changed, 384 insertions(+), 44 deletions(-) create mode 100644 scripts/cmd/copy-build.cmd create mode 100644 scripts/cmd/create-server-dir.cmd create mode 100644 scripts/cmd/enforce-env-jar.cmd create mode 100644 scripts/cmd/enforce-server-jar.cmd create mode 100644 scripts/cmd/get-env.cmd create mode 100644 scripts/cmd/project-properties.cmd create mode 100644 scripts/cmd/replace-server-jar.cmd create mode 100644 scripts/cmd/start-server.cmd create mode 100644 scripts/cmd/update-build.cmd create mode 100644 scripts/cmd/update-patch.cmd create mode 100644 scripts/cmd/update-pom.cmd create mode 100644 scripts/cmd/update-version.cmd rename scripts/{ => sh}/copy-build.sh (79%) mode change 100755 => 100644 rename scripts/{ => sh}/create-server-dir.sh (96%) mode change 100755 => 100644 rename scripts/{ => sh}/enforce-env-jar.sh (85%) mode change 100755 => 100644 rename scripts/{ => sh}/enforce-server-jar.sh (92%) mode change 100755 => 100644 rename scripts/{ => sh}/get-env.sh (100%) mode change 100755 => 100644 rename scripts/{ => sh}/project-properties.sh (100%) mode change 100755 => 100644 rename scripts/{ => sh}/replace-server-jar.sh (82%) mode change 100755 => 100644 rename scripts/{ => sh}/start-server.sh (89%) mode change 100755 => 100644 rename scripts/{ => sh}/update-build.sh (100%) mode change 100755 => 100644 rename scripts/{ => sh}/update-patch.sh (100%) mode change 100755 => 100644 rename scripts/{ => sh}/update-pom.sh (97%) mode change 100755 => 100644 rename scripts/{ => sh}/update-version.sh (100%) mode change 100755 => 100644 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ba289e3..990452e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -17,7 +17,7 @@ { "label": "Script: Set permissions for scripts", "type": "shell", - "command": "/bin/bash -c \"chmod +x ${workspaceFolder}/scripts/*.sh\" && echo Permissions set.", + "command": "chmod +x ${workspaceFolder}/scripts/sh/*.sh && echo Permissions set.", "presentation": { "clear": true }, @@ -42,10 +42,10 @@ "Build regular-place-kit" ], "type": "shell", - "command": "/bin/bash", - "args": [ - "${workspaceFolder}/scripts/copy-build.sh" - ], + "command": "${workspaceFolder}/scripts/sh/copy-build.sh", + "windows": { + "command": "${workspaceFolder}/scripts/cmd/copy-build.cmd" + }, "group": { "kind": "build", "isDefault": true @@ -55,10 +55,10 @@ { "label": "Start Paper server", "type": "shell", - "command": "/bin/bash", - "args": [ - "${workspaceFolder}/scripts/start-server.sh" - ], + "command": "${workspaceFolder}/scripts/sh/start-server.sh", + "windows": { + "command": "${workspaceFolder}/scripts/cmd/start-server.cmd" + }, "isBackground": true, "presentation": { "echo": true, @@ -116,10 +116,10 @@ "label": "Script: Update Minecraft version", "hide": true, "type": "shell", - "command": "/bin/bash", - "args": [ - "${workspaceFolder}/scripts/update-version.sh" - ], + "command": "${workspaceFolder}/scripts/sh/update-version.sh", + "windows": { + "command": "${workspaceFolder}/scripts/cmd/update-version.cmd" + }, "presentation": { "echo": false, "showReuseMessage": false @@ -130,28 +130,28 @@ "label": "Script: Update Minecraft patch", "hide": true, "type": "shell", - "command": "/bin/bash", - "args": [ - "${workspaceFolder}/scripts/update-patch.sh" - ], + "command": "${workspaceFolder}/scripts/sh/update-patch.sh", + "windows": { + "command": "${workspaceFolder}/scripts/cmd/update-patch.cmd" + }, "problemMatcher": [] }, { "label": "Script: Update pom/README to match project properties", "type": "shell", - "command": "/bin/bash", - "args": [ - "${workspaceFolder}/scripts/update-pom.sh" - ], + "command": "${workspaceFolder}/scripts/sh/update-pom.sh", + "windows": { + "command": "${workspaceFolder}/scripts/cmd/update-pom.cmd" + }, "problemMatcher": [] }, { "label": "Project: Update Paper build", "type": "shell", - "command": "/bin/bash", - "args": [ - "${workspaceFolder}/scripts/update-build.sh" - ], + "command": "${workspaceFolder}/scripts/sh/update-build.sh", + "windows": { + "command": "${workspaceFolder}/scripts/cmd/update-build.cmd" + }, "problemMatcher": [] }, { @@ -177,10 +177,10 @@ { "label": "Replace Paper server JAR with correct build", "type": "shell", - "command": "/bin/bash", - "args": [ - "${workspaceFolder}/scripts/replace-server-jar.sh" - ], + "command": "${workspaceFolder}/scripts/sh/replace-server-jar.sh", + "windows": { + "command": "${workspaceFolder}/scripts/cmd/replace-server-jar.cmd" + }, "problemMatcher": [] } ], diff --git a/scripts/cmd/copy-build.cmd b/scripts/cmd/copy-build.cmd new file mode 100644 index 0000000..9f759f8 --- /dev/null +++ b/scripts/cmd/copy-build.cmd @@ -0,0 +1,26 @@ +@echo off +REM Exit script immediately on first error. +setlocal EnableDelayedExpansion +set errorlevel=0 + +REM Enforce that the built JAR file is specified in the environment +call .\scripts\cmd\enforce-env-jar.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Create the server directory if it doesn't exist +call .\scripts\cmd\create-server-dir.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Get the environment variables +call .\scripts\cmd\get-env.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Copy JAR file to server directory +echo Copying %JAR_FILE% to %SERVER_DIRECTORY%\plugins +mkdir "%SERVER_DIRECTORY%\plugins" 2>nul +copy "%JAR_FILE%" "%SERVER_DIRECTORY%\plugins" +if %errorlevel% neq 0 ( + echo Error occurred during copying. + exit /b %errorlevel% +) +echo Done! diff --git a/scripts/cmd/create-server-dir.cmd b/scripts/cmd/create-server-dir.cmd new file mode 100644 index 0000000..6b97151 --- /dev/null +++ b/scripts/cmd/create-server-dir.cmd @@ -0,0 +1,33 @@ +@echo off +setlocal enabledelayedexpansion + +REM Exit script immediately on first error. +set errorlevel=0 + +call .\scripts\cmd\get-env.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Make sure SERVER_DIRECTORY is set +if "%SERVER_DIRECTORY%"=="" ( + echo SERVER_DIRECTORY is not set. Please set it via an environment variable. + exit /b 1 +) + +REM Make sure SERVER_DIRECTORY exists +if not exist "%SERVER_DIRECTORY%" ( + echo The server directory at %SERVER_DIRECTORY% does not exist. + set /p user_input="Would you like to create it? [Y/n] " + + if /i "!user_input!"=="Y" ( + echo Creating the directory.. + mkdir "%SERVER_DIRECTORY%" + if %errorlevel% neq 0 ( + echo Error occurred during directory creation. + exit /b %errorlevel% + ) + echo Created the Minecraft server directory. Proceeding.. + ) else ( + echo Please create the directory and try again. + exit /b 1 + ) +) diff --git a/scripts/cmd/enforce-env-jar.cmd b/scripts/cmd/enforce-env-jar.cmd new file mode 100644 index 0000000..c987350 --- /dev/null +++ b/scripts/cmd/enforce-env-jar.cmd @@ -0,0 +1,14 @@ +@echo off +setlocal EnableDelayedExpansion + +REM Exit script immediately on first error. +set errorlevel=0 + +call .\scripts\cmd\get-env.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Make sure a JAR file is specified +if not exist "%JAR_FILE%" ( + echo No JAR file specified. %JAR_FILE% + exit /b 1 +) diff --git a/scripts/cmd/enforce-server-jar.cmd b/scripts/cmd/enforce-server-jar.cmd new file mode 100644 index 0000000..79d2e6c --- /dev/null +++ b/scripts/cmd/enforce-server-jar.cmd @@ -0,0 +1,54 @@ +@echo off +setlocal EnableDelayedExpansion + +REM Exit script immediately on first error. +set errorlevel=0 + +REM Check for the auto-download flag +set AUTO_DOWNLOAD=false + +REM Parse command line arguments +:arg_loop +if "%1"=="" goto end_arg_loop +if "%1"=="--force" set AUTO_DOWNLOAD=true & shift & goto arg_loop +if "%1"=="-f" set AUTO_DOWNLOAD=true & shift & goto arg_loop +shift +goto arg_loop +:end_arg_loop + +REM Create the server directory if it doesn't exist +call .\scripts\cmd\create-server-dir.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Get the environment variables and project properties +call .\scripts\cmd\get-env.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +call .\scripts\cmd\project-properties.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Check that the server directory has a paper*.jar +set DOWNLOAD=false +set FILEFOUND=false + +for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do if exist "%%F" set FILEFOUND=true +if "!FILEFOUND!"=="false" ( + if "!AUTO_DOWNLOAD!"=="true" ( + set DOWNLOAD=true + ) else ( + echo No Paper JAR found in %SERVER_DIRECTORY%. + set /p user_input="Would you like to download it (Minecraft %MINECRAFT_VERSION%, build %PAPER_BUILD%)? [Y/n] " + + if /i "!user_input!"=="Y" set DOWNLOAD=true + if /i "!user_input!"=="" set DOWNLOAD=true + ) + + if "!DOWNLOAD!"=="true" ( + echo Downloading the Paper JAR.. + powershell -command "Invoke-WebRequest -Uri 'https://papermc.io/api/v2/projects/paper/versions/%MINECRAFT_VERSION%/builds/%PAPER_BUILD%/downloads/%SERVER_JAR_NAME%' -OutFile '%SERVER_DIRECTORY%\%SERVER_JAR_NAME%'" + echo Downloaded the Paper JAR. Proceeding.. + ) else ( + echo Please download the Paper JAR and try again. + exit /b 1 + ) +) diff --git a/scripts/cmd/get-env.cmd b/scripts/cmd/get-env.cmd new file mode 100644 index 0000000..115120b --- /dev/null +++ b/scripts/cmd/get-env.cmd @@ -0,0 +1,21 @@ +@echo off + +REM Exit script immediately on first error. +set errorlevel=0 + +REM Check if the ENV_FILE variable is set and the file exists +if exist "%ENV_FILE%" ( + for /f "usebackq tokens=*" %%a in (`findstr /v /b "#" "%ENV_FILE%"`) do ( + set "line=%%a" + REM Use standard expansion to get the first character + set "var=%line:~0,1%" + REM Check if the line is not empty and the first character is not a space + REM Delayed expansion not used, so a different approach is needed + call :ProcessLine + ) +) +goto :eof + +:ProcessLine +if not "%var%"=="" if not "%var%"==" " set %line% +goto :eof diff --git a/scripts/cmd/project-properties.cmd b/scripts/cmd/project-properties.cmd new file mode 100644 index 0000000..90cd2f3 --- /dev/null +++ b/scripts/cmd/project-properties.cmd @@ -0,0 +1,15 @@ +@echo off + +REM Exit script immediately on first error. +set errorlevel=0 + +REM Extracting MINECRAFT_VERSION and PAPER_BUILD from project.properties +for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set MINECRAFT_VERSION=%%b +for /f "tokens=1,* delims==" %%a in ('findstr "^PAPER_BUILD=" project.properties') do set PAPER_BUILD=%%b +set SERVER_JAR_NAME=paper-%MINECRAFT_VERSION%-%PAPER_BUILD%.jar + +REM Enforce that MINECRAFT_VERSION and PAPER_BUILD are set +if "%MINECRAFT_VERSION%"=="" or "%PAPER_BUILD%"=="" ( + echo MINECRAFT_VERSION and PAPER_BUILD must be set in project.properties. + exit /b 1 +) diff --git a/scripts/cmd/replace-server-jar.cmd b/scripts/cmd/replace-server-jar.cmd new file mode 100644 index 0000000..044e120 --- /dev/null +++ b/scripts/cmd/replace-server-jar.cmd @@ -0,0 +1,34 @@ +@echo off +setlocal enabledelayedexpansion + +REM Exit script immediately on first error. +set errorlevel=0 + +REM Create the server directory if it doesn't exist +call .\scripts\cmd\create-server-dir.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Get the environment variables and project properties +call .\scripts\cmd\get-env.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +call .\scripts\cmd\project-properties.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Check if the server directory has a %SERVER_JAR_NAME% file +if not exist "%SERVER_DIRECTORY%\%SERVER_JAR_NAME%" ( + REM Check if the server directory has a paper*.jar file + set FILEFOUND=false + for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do if exist "%%F" set FILEFOUND=true + if "!FILEFOUND!"=="true" ( + REM Move all paper*.jar files to the previous_jars directory + mkdir "%SERVER_DIRECTORY%\previous_jars" 2>nul + move "%SERVER_DIRECTORY%\paper*.jar" "%SERVER_DIRECTORY%\previous_jars" + ) + + REM Download the Paper JAR without asking for confirmation + call .\scripts\cmd\enforce-server-jar.cmd --force + echo Done! +) else ( + echo Server directory already running the proper build of Paper. No need to replace it! +) diff --git a/scripts/cmd/start-server.cmd b/scripts/cmd/start-server.cmd new file mode 100644 index 0000000..b81748a --- /dev/null +++ b/scripts/cmd/start-server.cmd @@ -0,0 +1,25 @@ +@echo off + +REM Exit script immediately on first error. +set errorlevel=0 + +REM Create the server directory if it doesn't exist +call .\scripts\cmd\create-server-dir.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Enforce that the server directory has a Paper JAR +call .\scripts\cmd\enforce-server-jar.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Check if SERVER_ARGS is set, otherwise set it to "-Xmx1024M -Xms512M" +if "%SERVER_ARGS%"=="" ( + set SERVER_ARGS=-Xmx1024M -Xms512M + echo Using %SERVER_ARGS% as SERVER_ARGS. +) + +REM Start the server +echo Starting server.. +cd /d "%SERVER_DIRECTORY%" +for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do ( + java %SERVER_ARGS% -Dcom.mojang.eula.agree=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar "%%F" nogui +) diff --git a/scripts/cmd/update-build.cmd b/scripts/cmd/update-build.cmd new file mode 100644 index 0000000..e43edf9 --- /dev/null +++ b/scripts/cmd/update-build.cmd @@ -0,0 +1,24 @@ +@echo off +setlocal enabledelayedexpansion + +REM Exit script immediately on first error. +set errorlevel=0 + +REM Extract the current MINECRAFT_VERSION from project.properties +for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set PREVIOUS_VERSION=%%b + +REM Fetch the JSON data from the PaperMC API +for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/versions/!PREVIOUS_VERSION!').Content"') do set RESPONSE=%%i + +REM Parse the JSON to get the latest build +for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '!RESPONSE!'; $obj.builds[-1]"') do set BUILD=%%a + +REM Check if the build was successfully retrieved +if "!BUILD!"=="" ( + echo No build found in the API response from PaperMC. + exit /b 1 +) + +REM Replace PAPER_BUILD in project.properties with the build +powershell -command "(Get-Content project.properties) -replace '^PAPER_BUILD=.*', 'PAPER_BUILD=!BUILD!' | Set-Content project.properties" +echo Updated PAPER_BUILD to !BUILD! in project.properties diff --git a/scripts/cmd/update-patch.cmd b/scripts/cmd/update-patch.cmd new file mode 100644 index 0000000..598bb05 --- /dev/null +++ b/scripts/cmd/update-patch.cmd @@ -0,0 +1,33 @@ +@echo off +setlocal enabledelayedexpansion + +REM Exit script immediately on first error. +set errorlevel=0 + +REM Extract the current MINECRAFT_VERSION from project.properties +for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set PREVIOUS_VERSION=%%b + +REM Extract version group (major.minor) +for /f %%i in ('echo !PREVIOUS_VERSION! ^| powershell -command "$input -match '^[0-9]+\.[0-9]+'; $matches[0]"') do set VERSION_GROUP=%%i + +REM Check if version group was successfully extracted +if "!VERSION_GROUP!"=="" ( + echo Failed to determine the version group from MINECRAFT_VERSION in project.properties. + exit /b 1 +) + +REM Fetch the JSON data from the PaperMC API +for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/version_group/!VERSION_GROUP!').Content"') do set API_RESPONSE=%%i + +REM Parse the JSON to get the version +for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '!API_RESPONSE!'; $obj.versions[-1]"') do set VERSION=%%a + +REM Check if the version was successfully retrieved +if "!VERSION!"=="" ( + echo No version found in the API response from PaperMC. + exit /b 1 +) + +REM Replace MINECRAFT_VERSION in project.properties with the version +powershell -command "(Get-Content project.properties) -replace '^MINECRAFT_VERSION=.*', 'MINECRAFT_VERSION=!VERSION!' | Set-Content project.properties" +echo Updated MINECRAFT_VERSION to !VERSION! in project.properties diff --git a/scripts/cmd/update-pom.cmd b/scripts/cmd/update-pom.cmd new file mode 100644 index 0000000..70480ba --- /dev/null +++ b/scripts/cmd/update-pom.cmd @@ -0,0 +1,40 @@ +@echo off +setlocal enabledelayedexpansion + +REM Exit script immediately on first error. +set errorlevel=0 + +set POM_FILE=.\pom.xml +set README_FILE=.\README.md +set GUIDE_FILE=.\guides\Beginners.md + +REM Check if the pom.xml file exists +if not exist "%POM_FILE%" ( + echo pom.xml file at %POM_FILE% not found. + exit /b 1 +) + +REM Check if the README.md file exists +if not exist "%README_FILE%" ( + echo README.md file at %README_FILE% not found. + exit /b 1 +) + +REM Check if the guides/Beginners.md file exists +if not exist "%GUIDE_FILE%" ( + echo Beginners.md file at %GUIDE_FILE% not found. + exit /b 1 +) + +REM Get the project properties +call .\scripts\cmd\project-properties.cmd +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Update the paper-api version in pom.xml +powershell -command "(Get-Content '%POM_FILE%') -replace 'paper-api<\/artifactId>(.*?).*<\/version>', 'paper-api<\/artifactId>`n%MINECRAFT_VERSION%-R0.1-SNAPSHOT<\/version>' | Set-Content '%POM_FILE%'" +echo Updated paper-api version to %MINECRAFT_VERSION%-R0.1-SNAPSHOT in pom.xml + +REM Update the .md files +powershell -command "(Get-Content '%README_FILE%') -replace '.*', '%MINECRAFT_VERSION%' | Set-Content '%README_FILE%'" +powershell -command "(Get-Content '%GUIDE_FILE%') -replace '.*', '%MINECRAFT_VERSION%' | Set-Content '%GUIDE_FILE%'" +echo Updated .md files with Minecraft version %MINECRAFT_VERSION% diff --git a/scripts/cmd/update-version.cmd b/scripts/cmd/update-version.cmd new file mode 100644 index 0000000..292749a --- /dev/null +++ b/scripts/cmd/update-version.cmd @@ -0,0 +1,21 @@ +@echo off +setlocal enabledelayedexpansion + +REM Exit script immediately on first error. +set errorlevel=0 + +REM Fetch the JSON data from the PaperMC API +for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper').Content"') do set RESPONSE=%%i + +REM Parse the JSON to get the last version +for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '!RESPONSE!'; $obj.versions[-1]"') do set VERSION=%%a + +REM Check if the last version was successfully retrieved +if "!VERSION!"=="" ( + echo No version found in the API response from PaperMC. + exit /b 1 +) + +REM Replace MINECRAFT_VERSION in project.properties with the retrieved version +powershell -command "(Get-Content project.properties) -replace '^MINECRAFT_VERSION=.*', 'MINECRAFT_VERSION=!VERSION!' | Set-Content project.properties" +echo Updated project.properties MINECRAFT_VERSION to !VERSION!. diff --git a/scripts/copy-build.sh b/scripts/sh/copy-build.sh old mode 100755 new mode 100644 similarity index 79% rename from scripts/copy-build.sh rename to scripts/sh/copy-build.sh index 53ce726..cf9fc2f --- a/scripts/copy-build.sh +++ b/scripts/sh/copy-build.sh @@ -2,13 +2,13 @@ set -e # Exit script immediately on first error. # Enforce that the built JAR file is specified in the environment -./scripts/enforce-env-jar.sh +./scripts/cmd/enforce-env-jar.sh # Create the server directory if it doesn't exist -./scripts/create-server-dir.sh +./scripts/cmd/create-server-dir.sh # Get the environment variables -source ./scripts/get-env.sh +source ./scripts/cmd/get-env.sh # Copy JAR file to server directory echo "Copying $JAR_FILE to $SERVER_DIRECTORY/plugins" diff --git a/scripts/create-server-dir.sh b/scripts/sh/create-server-dir.sh old mode 100755 new mode 100644 similarity index 96% rename from scripts/create-server-dir.sh rename to scripts/sh/create-server-dir.sh index adb0daf..0f9d8c5 --- a/scripts/create-server-dir.sh +++ b/scripts/sh/create-server-dir.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e # Exit script immediately on first error. -source ./scripts/get-env.sh +source ./scripts/cmd/get-env.sh # Make sure SERVER_DIRECTORY is set if [ -z "$SERVER_DIRECTORY" ]; then diff --git a/scripts/enforce-env-jar.sh b/scripts/sh/enforce-env-jar.sh old mode 100755 new mode 100644 similarity index 85% rename from scripts/enforce-env-jar.sh rename to scripts/sh/enforce-env-jar.sh index 5c49483..51a4cdf --- a/scripts/enforce-env-jar.sh +++ b/scripts/sh/enforce-env-jar.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e # Exit script immediately on first error. -source ./scripts/get-env.sh +source ./scripts/cmd/get-env.sh # Make sure a JAR file is specified if [ ! -f "$JAR_FILE" ]; then diff --git a/scripts/enforce-server-jar.sh b/scripts/sh/enforce-server-jar.sh old mode 100755 new mode 100644 similarity index 92% rename from scripts/enforce-server-jar.sh rename to scripts/sh/enforce-server-jar.sh index 77bf624..7a10fd3 --- a/scripts/enforce-server-jar.sh +++ b/scripts/sh/enforce-server-jar.sh @@ -17,11 +17,11 @@ for arg in "$@"; do done # Create the server directory if it doesn't exist -./scripts/create-server-dir.sh +./scripts/cmd/create-server-dir.sh # Get the environment variables and project properties -source ./scripts/get-env.sh -source ./scripts/project-properties.sh +source ./scripts/cmd/get-env.sh +source ./scripts/cmd/project-properties.sh # Check that the server directory has a paper*.jar if [ ! -f "$SERVER_DIRECTORY"/paper*.jar ]; then diff --git a/scripts/get-env.sh b/scripts/sh/get-env.sh old mode 100755 new mode 100644 similarity index 100% rename from scripts/get-env.sh rename to scripts/sh/get-env.sh diff --git a/scripts/project-properties.sh b/scripts/sh/project-properties.sh old mode 100755 new mode 100644 similarity index 100% rename from scripts/project-properties.sh rename to scripts/sh/project-properties.sh diff --git a/scripts/replace-server-jar.sh b/scripts/sh/replace-server-jar.sh old mode 100755 new mode 100644 similarity index 82% rename from scripts/replace-server-jar.sh rename to scripts/sh/replace-server-jar.sh index b979057..b0a026a --- a/scripts/replace-server-jar.sh +++ b/scripts/sh/replace-server-jar.sh @@ -2,11 +2,11 @@ set -e # Exit script immediately on first error. # Create the server directory if it doesn't exist -./scripts/create-server-dir.sh +./scripts/cmd/create-server-dir.sh # Get the environment variables and project properties -source ./scripts/get-env.sh -source ./scripts/project-properties.sh +source ./scripts/cmd/get-env.sh +source ./scripts/cmd/project-properties.sh # Check if the server directory has a $SERVER_JAR_NAME file if [ ! -f "$SERVER_DIRECTORY/$SERVER_JAR_NAME" ]; then @@ -18,7 +18,7 @@ if [ ! -f "$SERVER_DIRECTORY/$SERVER_JAR_NAME" ]; then fi # Download the Paper JAR without asking for confirmation - ./scripts/enforce-server-jar.sh --force + ./scripts/cmd/enforce-server-jar.sh --force echo "Done!" else echo "Server directory already running the proper build of Paper. No need to replace it!" diff --git a/scripts/start-server.sh b/scripts/sh/start-server.sh old mode 100755 new mode 100644 similarity index 89% rename from scripts/start-server.sh rename to scripts/sh/start-server.sh index 101c753..571c28d --- a/scripts/start-server.sh +++ b/scripts/sh/start-server.sh @@ -2,10 +2,10 @@ set -e # Exit script immediately on first error. # Create the server directory if it doesn't exist -./scripts/create-server-dir.sh +./scripts/cmd/create-server-dir.sh # Enforce that the server directory has a Paper JAR -./scripts/enforce-server-jar.sh +./scripts/cmd/enforce-server-jar.sh # Check if SERVER_ARGS is set, otherwise set it to "-Xmx1024M -Xms512M" if [ -z "$SERVER_ARGS" ]; then diff --git a/scripts/update-build.sh b/scripts/sh/update-build.sh old mode 100755 new mode 100644 similarity index 100% rename from scripts/update-build.sh rename to scripts/sh/update-build.sh diff --git a/scripts/update-patch.sh b/scripts/sh/update-patch.sh old mode 100755 new mode 100644 similarity index 100% rename from scripts/update-patch.sh rename to scripts/sh/update-patch.sh diff --git a/scripts/update-pom.sh b/scripts/sh/update-pom.sh old mode 100755 new mode 100644 similarity index 97% rename from scripts/update-pom.sh rename to scripts/sh/update-pom.sh index d453e43..4121cbb --- a/scripts/update-pom.sh +++ b/scripts/sh/update-pom.sh @@ -25,7 +25,7 @@ if [ ! -f "$GUIDE_FILE" ]; then fi # Get the project properties -source ./scripts/project-properties.sh +source ./scripts/cmd/project-properties.sh if [[ "$OSTYPE" == "darwin"* ]]; then # macOS diff --git a/scripts/update-version.sh b/scripts/sh/update-version.sh old mode 100755 new mode 100644 similarity index 100% rename from scripts/update-version.sh rename to scripts/sh/update-version.sh From 191a8935c2dba09fa806723b05f4d74112403f08 Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Tue, 23 Jan 2024 17:14:53 -0600 Subject: [PATCH 10/16] completely renovate all cmd scripts --- scripts/cmd/copy-build.cmd | 15 +++------ scripts/cmd/create-server-dir.cmd | 19 +++-------- scripts/cmd/enforce-env-jar.cmd | 7 ++-- scripts/cmd/enforce-server-jar.cmd | 51 ++++++++++++++---------------- scripts/cmd/get-env.cmd | 18 +++-------- scripts/cmd/project-properties.cmd | 3 -- scripts/cmd/replace-server-jar.cmd | 18 ++++------- scripts/cmd/start-server.cmd | 15 +++++---- scripts/cmd/update-build.cmd | 18 ++++------- scripts/cmd/update-patch.cmd | 26 +++++++-------- scripts/cmd/update-pom.cmd | 13 +++----- scripts/cmd/update-version.cmd | 18 ++++------- scripts/sh/create-server-dir.sh | 9 +++--- 13 files changed, 88 insertions(+), 142 deletions(-) diff --git a/scripts/cmd/copy-build.cmd b/scripts/cmd/copy-build.cmd index 9f759f8..f2bd4a0 100644 --- a/scripts/cmd/copy-build.cmd +++ b/scripts/cmd/copy-build.cmd @@ -1,26 +1,21 @@ @echo off -REM Exit script immediately on first error. -setlocal EnableDelayedExpansion -set errorlevel=0 REM Enforce that the built JAR file is specified in the environment call .\scripts\cmd\enforce-env-jar.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Create the server directory if it doesn't exist call .\scripts\cmd\create-server-dir.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Get the environment variables call .\scripts\cmd\get-env.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Copy JAR file to server directory echo Copying %JAR_FILE% to %SERVER_DIRECTORY%\plugins mkdir "%SERVER_DIRECTORY%\plugins" 2>nul copy "%JAR_FILE%" "%SERVER_DIRECTORY%\plugins" -if %errorlevel% neq 0 ( - echo Error occurred during copying. - exit /b %errorlevel% -) +if ERRORLEVEL 1 exit /b 1 + echo Done! diff --git a/scripts/cmd/create-server-dir.cmd b/scripts/cmd/create-server-dir.cmd index 6b97151..8d6c8c9 100644 --- a/scripts/cmd/create-server-dir.cmd +++ b/scripts/cmd/create-server-dir.cmd @@ -1,11 +1,7 @@ @echo off -setlocal enabledelayedexpansion - -REM Exit script immediately on first error. -set errorlevel=0 call .\scripts\cmd\get-env.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Make sure SERVER_DIRECTORY is set if "%SERVER_DIRECTORY%"=="" ( @@ -18,16 +14,11 @@ if not exist "%SERVER_DIRECTORY%" ( echo The server directory at %SERVER_DIRECTORY% does not exist. set /p user_input="Would you like to create it? [Y/n] " - if /i "!user_input!"=="Y" ( - echo Creating the directory.. - mkdir "%SERVER_DIRECTORY%" - if %errorlevel% neq 0 ( - echo Error occurred during directory creation. - exit /b %errorlevel% - ) - echo Created the Minecraft server directory. Proceeding.. - ) else ( + if /i "%user_input%"=="N" ( echo Please create the directory and try again. exit /b 1 + ) else ( + mkdir "%SERVER_DIRECTORY%" + echo Created the Minecraft server directory. Proceeding.. ) ) diff --git a/scripts/cmd/enforce-env-jar.cmd b/scripts/cmd/enforce-env-jar.cmd index c987350..1b25f0f 100644 --- a/scripts/cmd/enforce-env-jar.cmd +++ b/scripts/cmd/enforce-env-jar.cmd @@ -1,11 +1,8 @@ @echo off -setlocal EnableDelayedExpansion - -REM Exit script immediately on first error. -set errorlevel=0 +REM Call get-env.cmd and check if it was successful call .\scripts\cmd\get-env.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Make sure a JAR file is specified if not exist "%JAR_FILE%" ( diff --git a/scripts/cmd/enforce-server-jar.cmd b/scripts/cmd/enforce-server-jar.cmd index 79d2e6c..85578fe 100644 --- a/scripts/cmd/enforce-server-jar.cmd +++ b/scripts/cmd/enforce-server-jar.cmd @@ -1,49 +1,46 @@ @echo off -setlocal EnableDelayedExpansion -REM Exit script immediately on first error. -set errorlevel=0 +REM Setting default value for AUTO_DOWNLOAD (0 for false, 1 for true) +set AUTO_DOWNLOAD=0 -REM Check for the auto-download flag -set AUTO_DOWNLOAD=false - -REM Parse command line arguments -:arg_loop -if "%1"=="" goto end_arg_loop -if "%1"=="--force" set AUTO_DOWNLOAD=true & shift & goto arg_loop -if "%1"=="-f" set AUTO_DOWNLOAD=true & shift & goto arg_loop +REM Processing command line arguments +:args_loop +if "%~1"=="" goto end_args_loop +if "%~1"=="--force" set AUTO_DOWNLOAD=1 & shift & goto args_loop +if "%~1"=="-f" set AUTO_DOWNLOAD=1 & shift & goto args_loop shift -goto arg_loop -:end_arg_loop +goto args_loop +:end_args_loop REM Create the server directory if it doesn't exist call .\scripts\cmd\create-server-dir.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Get the environment variables and project properties call .\scripts\cmd\get-env.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 call .\scripts\cmd\project-properties.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Check that the server directory has a paper*.jar -set DOWNLOAD=false -set FILEFOUND=false +set PAPER_JAR_FOUND=0 +for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do if exist "%%F" set PAPER_JAR_FOUND=1 + +if "%PAPER_JAR_FOUND%"=="0" ( + set DOWNLOAD=0 -for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do if exist "%%F" set FILEFOUND=true -if "!FILEFOUND!"=="false" ( - if "!AUTO_DOWNLOAD!"=="true" ( - set DOWNLOAD=true + if "%AUTO_DOWNLOAD%"=="1" ( + set DOWNLOAD=1 ) else ( echo No Paper JAR found in %SERVER_DIRECTORY%. - set /p user_input="Would you like to download it (Minecraft %MINECRAFT_VERSION%, build %PAPER_BUILD%)? [Y/n] " - - if /i "!user_input!"=="Y" set DOWNLOAD=true - if /i "!user_input!"=="" set DOWNLOAD=true + set /p USER_INPUT="Would you like to download it (Minecraft %MINECRAFT_VERSION%, build %PAPER_BUILD%)? [Y/n] " + + if /i "%USER_INPUT%"=="Y" set DOWNLOAD=1 + if /i "%USER_INPUT%"=="" set DOWNLOAD=1 ) - if "!DOWNLOAD!"=="true" ( + if "%DOWNLOAD%"=="1" ( echo Downloading the Paper JAR.. powershell -command "Invoke-WebRequest -Uri 'https://papermc.io/api/v2/projects/paper/versions/%MINECRAFT_VERSION%/builds/%PAPER_BUILD%/downloads/%SERVER_JAR_NAME%' -OutFile '%SERVER_DIRECTORY%\%SERVER_JAR_NAME%'" echo Downloaded the Paper JAR. Proceeding.. diff --git a/scripts/cmd/get-env.cmd b/scripts/cmd/get-env.cmd index 115120b..1e401d6 100644 --- a/scripts/cmd/get-env.cmd +++ b/scripts/cmd/get-env.cmd @@ -1,21 +1,11 @@ @echo off -REM Exit script immediately on first error. -set errorlevel=0 - REM Check if the ENV_FILE variable is set and the file exists if exist "%ENV_FILE%" ( for /f "usebackq tokens=*" %%a in (`findstr /v /b "#" "%ENV_FILE%"`) do ( - set "line=%%a" - REM Use standard expansion to get the first character - set "var=%line:~0,1%" - REM Check if the line is not empty and the first character is not a space - REM Delayed expansion not used, so a different approach is needed - call :ProcessLine + REM Setting environment variable + for /f "tokens=1,* delims==" %%b in ("%%a") do ( + set "%%b=%%c" + ) ) ) -goto :eof - -:ProcessLine -if not "%var%"=="" if not "%var%"==" " set %line% -goto :eof diff --git a/scripts/cmd/project-properties.cmd b/scripts/cmd/project-properties.cmd index 90cd2f3..ec64823 100644 --- a/scripts/cmd/project-properties.cmd +++ b/scripts/cmd/project-properties.cmd @@ -1,8 +1,5 @@ @echo off -REM Exit script immediately on first error. -set errorlevel=0 - REM Extracting MINECRAFT_VERSION and PAPER_BUILD from project.properties for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set MINECRAFT_VERSION=%%b for /f "tokens=1,* delims==" %%a in ('findstr "^PAPER_BUILD=" project.properties') do set PAPER_BUILD=%%b diff --git a/scripts/cmd/replace-server-jar.cmd b/scripts/cmd/replace-server-jar.cmd index 044e120..cd30358 100644 --- a/scripts/cmd/replace-server-jar.cmd +++ b/scripts/cmd/replace-server-jar.cmd @@ -1,28 +1,24 @@ @echo off -setlocal enabledelayedexpansion - -REM Exit script immediately on first error. -set errorlevel=0 REM Create the server directory if it doesn't exist call .\scripts\cmd\create-server-dir.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Get the environment variables and project properties call .\scripts\cmd\get-env.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 call .\scripts\cmd\project-properties.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Check if the server directory has a %SERVER_JAR_NAME% file if not exist "%SERVER_DIRECTORY%\%SERVER_JAR_NAME%" ( REM Check if the server directory has a paper*.jar file - set FILEFOUND=false - for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do if exist "%%F" set FILEFOUND=true - if "!FILEFOUND!"=="true" ( + set PAPER_JAR_FOUND=0 + for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do if exist "%%F" ( + set PAPER_JAR_FOUND=1 REM Move all paper*.jar files to the previous_jars directory - mkdir "%SERVER_DIRECTORY%\previous_jars" 2>nul + if not exist "%SERVER_DIRECTORY%\previous_jars" mkdir "%SERVER_DIRECTORY%\previous_jars" move "%SERVER_DIRECTORY%\paper*.jar" "%SERVER_DIRECTORY%\previous_jars" ) diff --git a/scripts/cmd/start-server.cmd b/scripts/cmd/start-server.cmd index b81748a..e001bc9 100644 --- a/scripts/cmd/start-server.cmd +++ b/scripts/cmd/start-server.cmd @@ -1,15 +1,12 @@ @echo off -REM Exit script immediately on first error. -set errorlevel=0 - REM Create the server directory if it doesn't exist call .\scripts\cmd\create-server-dir.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Enforce that the server directory has a Paper JAR call .\scripts\cmd\enforce-server-jar.cmd -if %errorlevel% neq 0 exit /b %errorlevel% +if ERRORLEVEL 1 exit /b 1 REM Check if SERVER_ARGS is set, otherwise set it to "-Xmx1024M -Xms512M" if "%SERVER_ARGS%"=="" ( @@ -17,9 +14,13 @@ if "%SERVER_ARGS%"=="" ( echo Using %SERVER_ARGS% as SERVER_ARGS. ) -REM Start the server +REM Start the server with the first paper*.jar found echo Starting server.. cd /d "%SERVER_DIRECTORY%" +set PAPER_JAR_FOUND= for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do ( - java %SERVER_ARGS% -Dcom.mojang.eula.agree=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar "%%F" nogui + if not defined PAPER_JAR_FOUND ( + set PAPER_JAR_FOUND=1 + java %SERVER_ARGS% -Dcom.mojang.eula.agree=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar "%%F" nogui + ) ) diff --git a/scripts/cmd/update-build.cmd b/scripts/cmd/update-build.cmd index e43edf9..01adde6 100644 --- a/scripts/cmd/update-build.cmd +++ b/scripts/cmd/update-build.cmd @@ -1,24 +1,20 @@ @echo off -setlocal enabledelayedexpansion - -REM Exit script immediately on first error. -set errorlevel=0 REM Extract the current MINECRAFT_VERSION from project.properties for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set PREVIOUS_VERSION=%%b -REM Fetch the JSON data from the PaperMC API -for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/versions/!PREVIOUS_VERSION!').Content"') do set RESPONSE=%%i +REM Fetch the JSON data from the PaperMC API using PowerShell +for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/versions/%PREVIOUS_VERSION%').Content"') do set RESPONSE=%%i -REM Parse the JSON to get the latest build -for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '!RESPONSE!'; $obj.builds[-1]"') do set BUILD=%%a +REM Parse the JSON to get the latest build using PowerShell +for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '%RESPONSE%'; $obj.builds[-1]"') do set BUILD=%%a REM Check if the build was successfully retrieved -if "!BUILD!"=="" ( +if "%BUILD%"=="" ( echo No build found in the API response from PaperMC. exit /b 1 ) REM Replace PAPER_BUILD in project.properties with the build -powershell -command "(Get-Content project.properties) -replace '^PAPER_BUILD=.*', 'PAPER_BUILD=!BUILD!' | Set-Content project.properties" -echo Updated PAPER_BUILD to !BUILD! in project.properties +powershell -command "(Get-Content project.properties) -replace '^PAPER_BUILD=.*', 'PAPER_BUILD=%BUILD%' | Set-Content project.properties" +echo Updated PAPER_BUILD to %BUILD% in project.properties diff --git a/scripts/cmd/update-patch.cmd b/scripts/cmd/update-patch.cmd index 598bb05..e2ee192 100644 --- a/scripts/cmd/update-patch.cmd +++ b/scripts/cmd/update-patch.cmd @@ -1,33 +1,29 @@ @echo off -setlocal enabledelayedexpansion - -REM Exit script immediately on first error. -set errorlevel=0 REM Extract the current MINECRAFT_VERSION from project.properties for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set PREVIOUS_VERSION=%%b -REM Extract version group (major.minor) -for /f %%i in ('echo !PREVIOUS_VERSION! ^| powershell -command "$input -match '^[0-9]+\.[0-9]+'; $matches[0]"') do set VERSION_GROUP=%%i +REM Extract version group (major.minor) using PowerShell +for /f %%i in ('echo %PREVIOUS_VERSION% ^| powershell -command "$input -match '^[0-9]+\.[0-9]+'; $matches[0]"') do set VERSION_GROUP=%%i REM Check if version group was successfully extracted -if "!VERSION_GROUP!"=="" ( +if "%VERSION_GROUP%"=="" ( echo Failed to determine the version group from MINECRAFT_VERSION in project.properties. exit /b 1 ) -REM Fetch the JSON data from the PaperMC API -for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/version_group/!VERSION_GROUP!').Content"') do set API_RESPONSE=%%i +REM Fetch the JSON data from the PaperMC API using PowerShell +for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/version_group/%VERSION_GROUP%').Content"') do set API_RESPONSE=%%i -REM Parse the JSON to get the version -for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '!API_RESPONSE!'; $obj.versions[-1]"') do set VERSION=%%a +REM Parse the JSON to get the version using PowerShell +for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '%API_RESPONSE%'; $obj.versions[-1]"') do set VERSION=%%a REM Check if the version was successfully retrieved -if "!VERSION!"=="" ( +if "%VERSION%"=="" ( echo No version found in the API response from PaperMC. exit /b 1 ) -REM Replace MINECRAFT_VERSION in project.properties with the version -powershell -command "(Get-Content project.properties) -replace '^MINECRAFT_VERSION=.*', 'MINECRAFT_VERSION=!VERSION!' | Set-Content project.properties" -echo Updated MINECRAFT_VERSION to !VERSION! in project.properties +REM Replace MINECRAFT_VERSION in project.properties with the version using PowerShell +powershell -command "(Get-Content project.properties) -replace '^MINECRAFT_VERSION=.*', 'MINECRAFT_VERSION=%VERSION%' | Set-Content project.properties" +echo Updated MINECRAFT_VERSION to %VERSION% in project.properties diff --git a/scripts/cmd/update-pom.cmd b/scripts/cmd/update-pom.cmd index 70480ba..922c9b2 100644 --- a/scripts/cmd/update-pom.cmd +++ b/scripts/cmd/update-pom.cmd @@ -1,12 +1,8 @@ @echo off -setlocal enabledelayedexpansion -REM Exit script immediately on first error. -set errorlevel=0 - -set POM_FILE=.\pom.xml -set README_FILE=.\README.md -set GUIDE_FILE=.\guides\Beginners.md +set POM_FILE=./pom.xml +set README_FILE=./README.md +set GUIDE_FILE=./guides/Beginners.md REM Check if the pom.xml file exists if not exist "%POM_FILE%" ( @@ -28,10 +24,9 @@ if not exist "%GUIDE_FILE%" ( REM Get the project properties call .\scripts\cmd\project-properties.cmd -if %errorlevel% neq 0 exit /b %errorlevel% REM Update the paper-api version in pom.xml -powershell -command "(Get-Content '%POM_FILE%') -replace 'paper-api<\/artifactId>(.*?).*<\/version>', 'paper-api<\/artifactId>`n%MINECRAFT_VERSION%-R0.1-SNAPSHOT<\/version>' | Set-Content '%POM_FILE%'" +powershell -command "(Get-Content '%POM_FILE%') -replace 'paper-api<\/artifactId>.*?.*?<\/version>', 'paper-api<\/artifactId>`n%MINECRAFT_VERSION%-R0.1-SNAPSHOT<\/version>' | Set-Content '%POM_FILE%'" echo Updated paper-api version to %MINECRAFT_VERSION%-R0.1-SNAPSHOT in pom.xml REM Update the .md files diff --git a/scripts/cmd/update-version.cmd b/scripts/cmd/update-version.cmd index 292749a..75bc68c 100644 --- a/scripts/cmd/update-version.cmd +++ b/scripts/cmd/update-version.cmd @@ -1,21 +1,17 @@ @echo off -setlocal enabledelayedexpansion -REM Exit script immediately on first error. -set errorlevel=0 - -REM Fetch the JSON data from the PaperMC API +REM Fetch the JSON data from the PaperMC API using PowerShell for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper').Content"') do set RESPONSE=%%i -REM Parse the JSON to get the last version -for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '!RESPONSE!'; $obj.versions[-1]"') do set VERSION=%%a +REM Parse the JSON to get the last version using PowerShell +for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '%RESPONSE%'; $obj.versions[-1]"') do set VERSION=%%a REM Check if the last version was successfully retrieved -if "!VERSION!"=="" ( +if "%VERSION%"=="" ( echo No version found in the API response from PaperMC. exit /b 1 ) -REM Replace MINECRAFT_VERSION in project.properties with the retrieved version -powershell -command "(Get-Content project.properties) -replace '^MINECRAFT_VERSION=.*', 'MINECRAFT_VERSION=!VERSION!' | Set-Content project.properties" -echo Updated project.properties MINECRAFT_VERSION to !VERSION!. +REM Replace MINECRAFT_VERSION in project.properties with the retrieved version using PowerShell +powershell -command "(Get-Content project.properties) -replace '^MINECRAFT_VERSION=.*', 'MINECRAFT_VERSION=%VERSION%' | Set-Content project.properties" +echo Updated project.properties MINECRAFT_VERSION to %VERSION%. diff --git a/scripts/sh/create-server-dir.sh b/scripts/sh/create-server-dir.sh index 0f9d8c5..7e46d6d 100644 --- a/scripts/sh/create-server-dir.sh +++ b/scripts/sh/create-server-dir.sh @@ -18,12 +18,11 @@ if [ ! -d "$SERVER_DIRECTORY" ]; then echo # Move to a new line # If the user says yes, create the directory - if [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Creating the directory.." - mkdir -p "$SERVER_DIRECTORY" - echo "Created the Minecraft server directory. Proceeding.." - else + if [[ $REPLY =~ ^[Nn]$ ]]; then echo "Please create the directory and try again." exit 1 + else + mkdir -p "$SERVER_DIRECTORY" + echo "Created the Minecraft server directory. Proceeding.." fi fi \ No newline at end of file From 2e0681d756073d6211270b909d499f566fa3c48d Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Wed, 24 Jan 2024 16:10:52 -0600 Subject: [PATCH 11/16] update windows script problems --- .vscode/tasks.json | 9 ++++++ scripts/cmd/create-server-dir.cmd | 37 +++++++++++++----------- scripts/cmd/enforce-server-jar.cmd | 46 ++++++++++++++++-------------- scripts/cmd/project-properties.cmd | 13 ++++++--- scripts/cmd/replace-server-jar.cmd | 35 +++++++++++++---------- scripts/cmd/start-server.cmd | 8 ++---- scripts/cmd/update-patch.cmd | 2 +- 7 files changed, 87 insertions(+), 63 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 990452e..35a9129 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -13,6 +13,15 @@ "JAR_FILE": "${workspaceFolder}/target/regular-place-kit.jar" } }, + "windows": { + "options": { + "env": { + "ENV_FILE": "${workspaceFolder}\\.env", + "SERVER_DIRECTORY": "${workspaceFolder}\\server", + "JAR_FILE": "${workspaceFolder}\\target\\regular-place-kit.jar" + } + } + }, "tasks": [ { "label": "Script: Set permissions for scripts", diff --git a/scripts/cmd/create-server-dir.cmd b/scripts/cmd/create-server-dir.cmd index 8d6c8c9..0b932dd 100644 --- a/scripts/cmd/create-server-dir.cmd +++ b/scripts/cmd/create-server-dir.cmd @@ -4,21 +4,26 @@ call .\scripts\cmd\get-env.cmd if ERRORLEVEL 1 exit /b 1 REM Make sure SERVER_DIRECTORY is set -if "%SERVER_DIRECTORY%"=="" ( - echo SERVER_DIRECTORY is not set. Please set it via an environment variable. - exit /b 1 -) +if not "%SERVER_DIRECTORY%"=="" goto check_dir_exists +echo SERVER_DIRECTORY is not set. Please set it via an environment variable. +exit /b 1 -REM Make sure SERVER_DIRECTORY exists -if not exist "%SERVER_DIRECTORY%" ( - echo The server directory at %SERVER_DIRECTORY% does not exist. - set /p user_input="Would you like to create it? [Y/n] " +:check_dir_exists +if exist "%SERVER_DIRECTORY%" goto end +echo The server directory at %SERVER_DIRECTORY% does not exist. +set /p USER_INPUT="Would you like to create it? [Y/n] " - if /i "%user_input%"=="N" ( - echo Please create the directory and try again. - exit /b 1 - ) else ( - mkdir "%SERVER_DIRECTORY%" - echo Created the Minecraft server directory. Proceeding.. - ) -) +if /i "%USER_INPUT%"=="Y" goto create_dir +if not defined USER_INPUT goto create_dir +goto dir_not_created + +:create_dir +mkdir "%SERVER_DIRECTORY%" +echo Created the Minecraft server directory. Proceeding.. +goto end + +:dir_not_created +echo Please create the directory and try again. +exit /b 1 + +:end diff --git a/scripts/cmd/enforce-server-jar.cmd b/scripts/cmd/enforce-server-jar.cmd index 85578fe..5d4a583 100644 --- a/scripts/cmd/enforce-server-jar.cmd +++ b/scripts/cmd/enforce-server-jar.cmd @@ -27,25 +27,27 @@ REM Check that the server directory has a paper*.jar set PAPER_JAR_FOUND=0 for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do if exist "%%F" set PAPER_JAR_FOUND=1 -if "%PAPER_JAR_FOUND%"=="0" ( - set DOWNLOAD=0 - - if "%AUTO_DOWNLOAD%"=="1" ( - set DOWNLOAD=1 - ) else ( - echo No Paper JAR found in %SERVER_DIRECTORY%. - set /p USER_INPUT="Would you like to download it (Minecraft %MINECRAFT_VERSION%, build %PAPER_BUILD%)? [Y/n] " - - if /i "%USER_INPUT%"=="Y" set DOWNLOAD=1 - if /i "%USER_INPUT%"=="" set DOWNLOAD=1 - ) - - if "%DOWNLOAD%"=="1" ( - echo Downloading the Paper JAR.. - powershell -command "Invoke-WebRequest -Uri 'https://papermc.io/api/v2/projects/paper/versions/%MINECRAFT_VERSION%/builds/%PAPER_BUILD%/downloads/%SERVER_JAR_NAME%' -OutFile '%SERVER_DIRECTORY%\%SERVER_JAR_NAME%'" - echo Downloaded the Paper JAR. Proceeding.. - ) else ( - echo Please download the Paper JAR and try again. - exit /b 1 - ) -) +if "%PAPER_JAR_FOUND%"=="0" goto no_paper_jar +goto end + +:no_paper_jar +if "%AUTO_DOWNLOAD%"=="1" goto download_paper_jar + +echo No Paper JAR found in %SERVER_DIRECTORY%. +set /p USER_INPUT="Would you like to download it (Minecraft %MINECRAFT_VERSION%, build %PAPER_BUILD%)? [Y/n] " + +if /i "%USER_INPUT%"=="Y" goto download_paper_jar +if /i "%USER_INPUT%"=="" goto download_paper_jar +goto no_download + +:no_download +echo Please download the Paper JAR and try again. +exit /b 1 + +:download_paper_jar +echo Downloading the Paper JAR.. +powershell -command "Invoke-WebRequest -Uri 'https://papermc.io/api/v2/projects/paper/versions/%MINECRAFT_VERSION%/builds/%PAPER_BUILD%/downloads/%SERVER_JAR_NAME%' -OutFile '%SERVER_DIRECTORY%\%SERVER_JAR_NAME%'" +echo Downloaded the Paper JAR. Proceeding.. +goto end + +:end diff --git a/scripts/cmd/project-properties.cmd b/scripts/cmd/project-properties.cmd index ec64823..73d23e1 100644 --- a/scripts/cmd/project-properties.cmd +++ b/scripts/cmd/project-properties.cmd @@ -1,12 +1,17 @@ @echo off REM Extracting MINECRAFT_VERSION and PAPER_BUILD from project.properties -for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set MINECRAFT_VERSION=%%b -for /f "tokens=1,* delims==" %%a in ('findstr "^PAPER_BUILD=" project.properties') do set PAPER_BUILD=%%b +for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set %%a=%%b +for /f "tokens=1,* delims==" %%a in ('findstr "^PAPER_BUILD=" project.properties') do set %%a=%%b + set SERVER_JAR_NAME=paper-%MINECRAFT_VERSION%-%PAPER_BUILD%.jar REM Enforce that MINECRAFT_VERSION and PAPER_BUILD are set -if "%MINECRAFT_VERSION%"=="" or "%PAPER_BUILD%"=="" ( - echo MINECRAFT_VERSION and PAPER_BUILD must be set in project.properties. +if not defined MINECRAFT_VERSION ( + echo MINECRAFT_VERSION not set in project.properties. exit /b 1 ) +if not defined PAPER_BUILD ( + echo PAPER_BUILD not set in project.properties. + exit /b 1 +) \ No newline at end of file diff --git a/scripts/cmd/replace-server-jar.cmd b/scripts/cmd/replace-server-jar.cmd index cd30358..7a088f3 100644 --- a/scripts/cmd/replace-server-jar.cmd +++ b/scripts/cmd/replace-server-jar.cmd @@ -12,19 +12,24 @@ call .\scripts\cmd\project-properties.cmd if ERRORLEVEL 1 exit /b 1 REM Check if the server directory has a %SERVER_JAR_NAME% file -if not exist "%SERVER_DIRECTORY%\%SERVER_JAR_NAME%" ( - REM Check if the server directory has a paper*.jar file - set PAPER_JAR_FOUND=0 - for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do if exist "%%F" ( - set PAPER_JAR_FOUND=1 - REM Move all paper*.jar files to the previous_jars directory - if not exist "%SERVER_DIRECTORY%\previous_jars" mkdir "%SERVER_DIRECTORY%\previous_jars" - move "%SERVER_DIRECTORY%\paper*.jar" "%SERVER_DIRECTORY%\previous_jars" - ) - - REM Download the Paper JAR without asking for confirmation - call .\scripts\cmd\enforce-server-jar.cmd --force - echo Done! -) else ( - echo Server directory already running the proper build of Paper. No need to replace it! +if exist "%SERVER_DIRECTORY%\%SERVER_JAR_NAME%" goto jar_exists +goto jar_not_exist + +:jar_exists +echo Server directory already running the proper build of Paper. No need to replace it! +goto end + +:jar_not_exist +REM Move all paper*.jar files to the previous_jars directory +for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do if exist "%%F" ( + if not exist "%SERVER_DIRECTORY%\previous_jars" mkdir "%SERVER_DIRECTORY%\previous_jars" + move "%SERVER_DIRECTORY%\paper*.jar" "%SERVER_DIRECTORY%\previous_jars" ) + +REM Download the Paper JAR without asking for confirmation +call .\scripts\cmd\enforce-server-jar.cmd --force + +echo Done! +goto end + +:end diff --git a/scripts/cmd/start-server.cmd b/scripts/cmd/start-server.cmd index e001bc9..529630d 100644 --- a/scripts/cmd/start-server.cmd +++ b/scripts/cmd/start-server.cmd @@ -11,16 +11,14 @@ if ERRORLEVEL 1 exit /b 1 REM Check if SERVER_ARGS is set, otherwise set it to "-Xmx1024M -Xms512M" if "%SERVER_ARGS%"=="" ( set SERVER_ARGS=-Xmx1024M -Xms512M - echo Using %SERVER_ARGS% as SERVER_ARGS. ) +echo Using %SERVER_ARGS% as SERVER_ARGS. REM Start the server with the first paper*.jar found echo Starting server.. cd /d "%SERVER_DIRECTORY%" set PAPER_JAR_FOUND= for %%F in ("%SERVER_DIRECTORY%\paper*.jar") do ( - if not defined PAPER_JAR_FOUND ( - set PAPER_JAR_FOUND=1 - java %SERVER_ARGS% -Dcom.mojang.eula.agree=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar "%%F" nogui - ) + java %SERVER_ARGS% -Dcom.mojang.eula.agree=true -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar "%%F" nogui + exit /b ) diff --git a/scripts/cmd/update-patch.cmd b/scripts/cmd/update-patch.cmd index e2ee192..ddd8a7b 100644 --- a/scripts/cmd/update-patch.cmd +++ b/scripts/cmd/update-patch.cmd @@ -4,7 +4,7 @@ REM Extract the current MINECRAFT_VERSION from project.properties for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set PREVIOUS_VERSION=%%b REM Extract version group (major.minor) using PowerShell -for /f %%i in ('echo %PREVIOUS_VERSION% ^| powershell -command "$input -match '^[0-9]+\.[0-9]+'; $matches[0]"') do set VERSION_GROUP=%%i +for /f "tokens=1,2 delims=." %%a in ("%PREVIOUS_VERSION%") do set VERSION_GROUP=%%a.%%b REM Check if version group was successfully extracted if "%VERSION_GROUP%"=="" ( From c02ee1b2e5a7aaf1e0e5a7d9e600c4a386287e39 Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Wed, 24 Jan 2024 16:21:06 -0600 Subject: [PATCH 12/16] add trailing space --- guides/Beginners.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/guides/Beginners.md b/guides/Beginners.md index 0f4b3d0..da632f7 100644 --- a/guides/Beginners.md +++ b/guides/Beginners.md @@ -36,4 +36,4 @@ And, VSCode is now all set up! You're almost ready to make your first changes. ## To be continued -Unfortunately, I can't really finish this part of the saga right now. But you can ask questions in the [OMG Dev Community](https://dev.omg.games/) if you need any more help. THANKS \ No newline at end of file +Unfortunately, I can't really finish this part of the saga right now. But you can ask questions in the [OMG Dev Community](https://dev.omg.games/) if you need any more help. THANKS diff --git a/pom.xml b/pom.xml index 9217d66..21b600b 100644 --- a/pom.xml +++ b/pom.xml @@ -38,4 +38,4 @@ 1.1 - \ No newline at end of file + From beb5b20d8780779719fda8496f06ad360e92753a Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Wed, 24 Jan 2024 16:22:46 -0600 Subject: [PATCH 13/16] remove outdated comment --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index 21b600b..92a58c6 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,6 @@ - io.papermc.paper paper-api From fea3a444d7233d510b2155451cec3df3b1b52fef Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Wed, 24 Jan 2024 16:27:58 -0600 Subject: [PATCH 14/16] update pom structure --- pom.xml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 92a58c6..af658d9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,20 +1,14 @@ - - + + 4.0.0 - rpk games.omg 1.0 - 1.8 1.8 UTF-8 - - @@ -22,7 +16,6 @@ https://repo.papermc.io/repository/maven-public/ - @@ -37,4 +30,4 @@ 1.1 - + \ No newline at end of file From b1b577f9d30ba293cfc1c038975325dc9660fafb Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Wed, 24 Jan 2024 16:28:16 -0600 Subject: [PATCH 15/16] update PowerShell parsing --- scripts/cmd/update-build.cmd | 7 ++----- scripts/cmd/update-patch.cmd | 7 ++----- scripts/cmd/update-pom.cmd | 2 +- scripts/cmd/update-version.cmd | 7 ++----- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/scripts/cmd/update-build.cmd b/scripts/cmd/update-build.cmd index 01adde6..b8320aa 100644 --- a/scripts/cmd/update-build.cmd +++ b/scripts/cmd/update-build.cmd @@ -3,11 +3,8 @@ REM Extract the current MINECRAFT_VERSION from project.properties for /f "tokens=1,* delims==" %%a in ('findstr "^MINECRAFT_VERSION=" project.properties') do set PREVIOUS_VERSION=%%b -REM Fetch the JSON data from the PaperMC API using PowerShell -for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/versions/%PREVIOUS_VERSION%').Content"') do set RESPONSE=%%i - -REM Parse the JSON to get the latest build using PowerShell -for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '%RESPONSE%'; $obj.builds[-1]"') do set BUILD=%%a +REM Fetch the JSON data and parse it to get the latest build using PowerShell +for /f %%a in ('powershell -command "try { $response = Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/versions/%PREVIOUS_VERSION%'; $obj = ConvertFrom-Json $response.Content; $obj.builds[-1] } catch { '' }"') do set BUILD=%%a REM Check if the build was successfully retrieved if "%BUILD%"=="" ( diff --git a/scripts/cmd/update-patch.cmd b/scripts/cmd/update-patch.cmd index ddd8a7b..47ed66c 100644 --- a/scripts/cmd/update-patch.cmd +++ b/scripts/cmd/update-patch.cmd @@ -12,11 +12,8 @@ if "%VERSION_GROUP%"=="" ( exit /b 1 ) -REM Fetch the JSON data from the PaperMC API using PowerShell -for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/version_group/%VERSION_GROUP%').Content"') do set API_RESPONSE=%%i - -REM Parse the JSON to get the version using PowerShell -for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '%API_RESPONSE%'; $obj.versions[-1]"') do set VERSION=%%a +REM Fetch the JSON data and parse it to get the version using PowerShell +for /f %%a in ('powershell -command "try { $response = Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper/version_group/%VERSION_GROUP%'; $obj = ConvertFrom-Json $response.Content; $obj.versions[-1] } catch { '' }"') do set VERSION=%%a REM Check if the version was successfully retrieved if "%VERSION%"=="" ( diff --git a/scripts/cmd/update-pom.cmd b/scripts/cmd/update-pom.cmd index 922c9b2..59f80ad 100644 --- a/scripts/cmd/update-pom.cmd +++ b/scripts/cmd/update-pom.cmd @@ -26,7 +26,7 @@ REM Get the project properties call .\scripts\cmd\project-properties.cmd REM Update the paper-api version in pom.xml -powershell -command "(Get-Content '%POM_FILE%') -replace 'paper-api<\/artifactId>.*?.*?<\/version>', 'paper-api<\/artifactId>`n%MINECRAFT_VERSION%-R0.1-SNAPSHOT<\/version>' | Set-Content '%POM_FILE%'" +powershell -command "$xml = [xml](Get-Content '%POM_FILE%'); $xml.project.dependencies.dependency | where { $_.artifactId -eq 'paper-api' } | ForEach-Object { $_.version = '%MINECRAFT_VERSION%-R0.1-SNAPSHOT' }; $xml.Save('%POM_FILE%')" echo Updated paper-api version to %MINECRAFT_VERSION%-R0.1-SNAPSHOT in pom.xml REM Update the .md files diff --git a/scripts/cmd/update-version.cmd b/scripts/cmd/update-version.cmd index 75bc68c..b644814 100644 --- a/scripts/cmd/update-version.cmd +++ b/scripts/cmd/update-version.cmd @@ -1,10 +1,7 @@ @echo off -REM Fetch the JSON data from the PaperMC API using PowerShell -for /f %%i in ('powershell -command "(Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper').Content"') do set RESPONSE=%%i - -REM Parse the JSON to get the last version using PowerShell -for /f %%a in ('powershell -command "$obj = ConvertFrom-Json '%RESPONSE%'; $obj.versions[-1]"') do set VERSION=%%a +REM Fetch the JSON data and parse it to get the last version using PowerShell +for /f %%a in ('powershell -command "try { $response = Invoke-WebRequest -Uri 'https://api.papermc.io/v2/projects/paper'; $obj = ConvertFrom-Json $response.Content; $obj.versions[-1] } catch { '' }"') do set VERSION=%%a REM Check if the last version was successfully retrieved if "%VERSION%"=="" ( From 73c01ef752578f8e1f25569f6be9c062df88c6c1 Mon Sep 17 00:00:00 2001 From: iminlikewithyou Date: Wed, 24 Jan 2024 16:30:13 -0600 Subject: [PATCH 16/16] remove workflows --- .github/workflows/update-readme.yml | 50 ----------------------------- 1 file changed, 50 deletions(-) delete mode 100644 .github/workflows/update-readme.yml diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml deleted file mode 100644 index fa2699f..0000000 --- a/.github/workflows/update-readme.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Update README - -on: - push: - paths: - - 'pom.xml' - -jobs: - update-readme: - runs-on: ubuntu-latest - - steps: - - name: Check out repository - uses: actions/checkout@v2 - - - name: Set up git credentials - run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - - - name: Extract version from pom.xml - id: version - run: | - VERSION=$(grep -oPm1 "(?<=)[^<]+" pom.xml | head -1) - MINECRAFT_VERSION=${VERSION%%-*} - - if [[ -z "$VERSION" ]]; then - echo "Couldn't extract version from pom.xml!" - exit 1 - fi - - echo "Version (from pom.xml): $VERSION" - echo "Minecraft version: $MINECRAFT_VERSION" - echo "::set-output name=VERSION::$VERSION" - echo "::set-output name=MINECRAFT_VERSION::$MINECRAFT_VERSION" - - - name: Update README.md - run: | - sed -i "s/.*/${{ steps.version.outputs.MINECRAFT_VERSION }}/" README.md - git add README.md - - - name: Update Beginners.md - run: | - sed -i "s/.*/${{ steps.version.outputs.MINECRAFT_VERSION }}/" guides/Beginners.md - git add guides/Beginners.md - - - name: Commit and push changes - run: | - git commit -m "Update to Minecraft ${{ steps.version.outputs.MINECRAFT_VERSION }}" -m "[skip ci]" - git push \ No newline at end of file