[
    {
        "UpdateStageName": "Hytale Downloader CLI Download",
        "UpdateSourcePlatform": "All",
        "UpdateSourceArch": "x86_64",
        "UpdateSource": "FetchURL",
        "UpdateSourceData": "https://downloader.hytale.com/hytale-downloader.zip",
        "UpdateSourceTarget": "{{$FullRootDir}}",
        "UnzipUpdateSource": true,
        "OverwriteExistingFiles": true,
        "DeleteAfterExtract": true,
        "UpdateSourceConditionSetting": "disable-server-download",
        "UpdateSourceConditionValue": "false",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Hytale Downloader Script Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSourceArch": "aarch64",
        "UpdateSource": "FetchURL",
        "UpdateSourceData": "https://raw.githubusercontent.com/CubeCoders/AMPTemplates/main/hytaledownloaderscript.sh",
        "UpdateSourceArgs": "hytale-downloader-linux-arm64.sh",
        "UpdateSourceTarget": "{{$FullRootDir}}",
        "OverwriteExistingFiles": true,
        "UpdateSourceConditionSetting": "disable-server-download",
        "UpdateSourceConditionValue": "false",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Hytale Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSourceArch": "x86_64",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"cd \\\"{{$FullRootDir}}\\\" && chmod +x ./hytale-downloader-linux-amd64 && LatestVersion=$(timeout 5 wget -qO- https://maven.hytale.com/{{ServerBuildChannel}}/com/hypixel/hytale/Server/maven-metadata.xml | sed -n \\\"s/.*<latest>\\(.*\\)<\\/latest>.*/\\1/p\\\"); if [[ -n \\\"$LatestVersion\\\" ]] && [[ ! \\\"$LatestVersion\\\" =~ ^[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}-[a-fA-F0-9]+$ ]]; then LatestVersion=\\\"\\\"; fi; [[ -f ./Server/.installedversion ]] && { InstalledVersion=\\\"$(cat ./Server/.installedversion 2>/dev/null)\\\"; if [[ \\\"$InstalledVersion\\\" =~ ^[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}-[a-fA-F0-9]+$ ]] && [[ \\\"$InstalledVersion\\\" == \\\"$LatestVersion\\\" ]]; then echo \\\"Latest Hytale {{ServerBuildChannel}} version $LatestVersion already installed. Skipping\\\"; exit 0; fi; }; exec 3>&1; for attempt in 1 2; do err=$(./hytale-downloader-linux-amd64 -patchline {{ServerBuildChannel}} -download-path ./server.zip 2>&1 1>&3) 3>&1; rc=$?; ((rc==0)) && break; ((attempt==1)) && [[ -n \\\"$err\\\" ]] && [[ -f ./.hytale-downloader-credentials.json ]] && rm -f ./.hytale-downloader-credentials.json && continue; break; done; exec 3>&-; ((rc!=0)) && { echo \\\"$err\\\" >&2; echo \\\"Download failed from the Hytale CDN. This is a fault with the CDN or the download, not AMP. Aborting\\\" >&2; exit 1; }; sleep 1 && if [[ -f ./server.zip ]]; then [[ -z \\\"${LatestVersion:-}\\\" ]] && LatestVersion=$(timeout 5 wget -qO- https://maven.hytale.com/{{ServerBuildChannel}}/com/hypixel/hytale/Server/maven-metadata.xml | sed -n \\\"s/.*<latest>\\(.*\\)<\\/latest>.*/\\1/p\\\"); unzip -oq ./server.zip && sleep 1 && printf \\\"%s\\\" \\\"$LatestVersion\\\" > ./Server/.installedversion && rm -f ./server.zip >/dev/null 2>&1; fi\"",
        "UpdateSourceConditionSetting": "disable-server-download",
        "UpdateSourceConditionValue": "false",
        "ProcessToolOutput": true,
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Hytale Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSourceArch": "aarch64",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"cd \\\"{{$FullRootDir}}\\\" && chmod +x ./hytale-downloader-linux-arm64.sh && LatestVersion=$(timeout 5 wget -qO- https://maven.hytale.com/{{ServerBuildChannel}}/com/hypixel/hytale/Server/maven-metadata.xml | sed -n \\\"s/.*<latest>\\(.*\\)<\\/latest>.*/\\1/p\\\"); if [[ -n \\\"$LatestVersion\\\" ]] && [[ ! \\\"$LatestVersion\\\" =~ ^[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}-[a-fA-F0-9]+$ ]]; then LatestVersion=\\\"\\\"; fi; [[ -f ./Server/.installedversion ]] && { InstalledVersion=\\\"$(cat ./Server/.installedversion 2>/dev/null)\\\"; if [[ \\\"$InstalledVersion\\\" =~ ^[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}-[a-fA-F0-9]+$ ]] && [[ \\\"$InstalledVersion\\\" == \\\"$LatestVersion\\\" ]]; then echo \\\"Latest Hytale {{ServerBuildChannel}} version $LatestVersion already installed. Skipping\\\"; exit 0; fi; }; exec 3>&1; for attempt in 1 2; do err=$(./hytale-downloader-linux-arm64.sh -patchline {{ServerBuildChannel}} -download-path ./server.zip 2>&1 1>&3) 3>&1; rc=$?; ((rc==0)) && break; ((attempt==1)) && [[ -n \\\"$err\\\" ]] && [[ -f ./.hytale-downloader-credentials.json ]] && rm -f ./.hytale-downloader-credentials.json && continue; break; done; exec 3>&-; ((rc!=0)) && { echo \\\"$err\\\" >&2; echo \\\"Download failed from the Hytale CDN. This is a fault with the CDN or the download, not AMP. Aborting\\\" >&2; exit 1; }; sleep 1 && if [[ -f ./server.zip ]]; then [[ -z \\\"${LatestVersion:-}\\\" ]] && LatestVersion=$(timeout 5 wget -qO- https://maven.hytale.com/{{ServerBuildChannel}}/com/hypixel/hytale/Server/maven-metadata.xml | sed -n \\\"s/.*<latest>\\(.*\\)<\\/latest>.*/\\1/p\\\"); unzip -oq ./server.zip && sleep 1 && printf \\\"%s\\\" \\\"$LatestVersion\\\" > ./Server/.installedversion && rm -f ./server.zip >/dev/null 2>&1; fi\"",
        "UpdateSourceConditionSetting": "disable-server-download",
        "UpdateSourceConditionValue": "false",
        "ProcessToolOutput": true,
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Hytale Download",
        "UpdateSourcePlatform": "Windows",
        "UpdateSource": "Executable",
        "UpdateSourceData": "powershell.exe",
        "UpdateSourceArgs": "-NoProfile -Command \"$ProgressPreference='SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Set-Location -Path '{{$FullRootDir}}'; $LatestVersion = (Invoke-RestMethod -UseBasicParsing -TimeoutSec 5 -ErrorAction Stop https://maven.hytale.com/{{ServerBuildChannel}}/com/hypixel/hytale/Server/maven-metadata.xml).metadata.versioning.latest; if (-not [string]::IsNullOrEmpty($LatestVersion) -and $LatestVersion -notmatch '^[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}-[a-fA-F0-9]+$') { $LatestVersion = '' }; if (Test-Path -LiteralPath './Server/.installedversion' -PathType Leaf) { $InstalledVersion = Get-Content -LiteralPath './Server/.installedversion' -Raw -ErrorAction SilentlyContinue; if ($InstalledVersion -match '^[0-9]{4}\\.[0-9]{2}\\.[0-9]{2}-[a-fA-F0-9]+$' -and $InstalledVersion -eq $LatestVersion) { Write-Output \\\"Latest Hytale {{ServerBuildChannel}} version $LatestVersion already installed. Skipping\\\"; exit 0 } }; $err = ''; $rc = 1; for ($attempt = 1; $attempt -le 2; $attempt++) { $tmp = Join-Path $env:TEMP ([IO.Path]::GetRandomFileName()); $p = Start-Process -FilePath './hytale-downloader-windows-amd64.exe' -ArgumentList @('-patchline','{{ServerBuildChannel}}','-download-path','./server.zip') -NoNewWindow -Wait -PassThru -RedirectStandardError $tmp; $rc = $p.ExitCode; $err = (Get-Content -LiteralPath $tmp -Raw -ErrorAction SilentlyContinue); Remove-Item -LiteralPath $tmp -Force -ErrorAction SilentlyContinue *> $null; if ($rc -eq 0) { break }; if ($attempt -eq 1 -and -not [string]::IsNullOrEmpty($err) -and (Test-Path -LiteralPath './.hytale-downloader-credentials.json' -PathType Leaf)) { Remove-Item -LiteralPath './.hytale-downloader-credentials.json' -Force -ErrorAction SilentlyContinue *> $null; continue }; break }; if ($rc -ne 0) { Write-Output \\\"$err\\\"; Write-Output \\\"Download failed from the Hytale CDN. This is a fault with the CDN or the download, not AMP. Aborting\\\"; exit 1 }; Start-Sleep -Seconds 1; if (Test-Path -LiteralPath './server.zip' -PathType Leaf) { if ([string]::IsNullOrEmpty($LatestVersion)) { $LatestVersion = (Invoke-RestMethod -UseBasicParsing -TimeoutSec 5 -ErrorAction Stop https://maven.hytale.com/{{ServerBuildChannel}}/com/hypixel/hytale/Server/maven-metadata.xml).metadata.versioning.latest }; Expand-Archive -LiteralPath ./server.zip -DestinationPath . -Force 2> $null; Start-Sleep -Seconds 1; Set-Content -LiteralPath './Server/.installedversion' -Value $LatestVersion -Encoding UTF8 -NoNewline -Force; Remove-Item -LiteralPath ./server.zip -Force -ErrorAction SilentlyContinue *> $null }\"",
        "UpdateSourceConditionSetting": "disable-server-download",
        "UpdateSourceConditionValue": "false",
        "ProcessToolOutput": true,
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Print Disabled Hytale Download Message",
        "UpdateSourcePlatform": "Linux",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"echo \\\"Hytale server download disabled in AMP's settings. Skipping\\\"\"",
        "UpdateSourceConditionSetting": "disable-server-download",
        "UpdateSourceConditionValue": "true",
        "SkipOnFailure": true
    },
    {
        "UpdateStageName": "Print Disabled Hytale Download Message",
        "UpdateSourcePlatform": "Windows",
        "UpdateSource": "Executable",
        "UpdateSourceData": "powershell.exe",
        "UpdateSourceArgs": "-NoProfile -Command \"Write-Output \\\"Hytale server download disabled in AMP's settings. Skipping\\\"\"",
        "UpdateSourceConditionSetting": "disable-server-download",
        "UpdateSourceConditionValue": "true",
        "SkipOnFailure": true
    },
    {
        "UpdateStageName": "Default config.json File Download",
        "UpdateSourcePlatform": "All",
        "UpdateSource": "FetchURL",
        "UpdateSourceData": "https://raw.githubusercontent.com/CubeCoders/AMPTemplates/main/hytaleserverconfig.json",
        "UpdateSourceArgs": "config.json",
        "UpdateSourceTarget": "{{$FullBaseDir}}Server",
        "OverwriteExistingFiles": false,
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Java Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSourceArch": "x86_64",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"cd hytale && if [[ -x java/bin/java ]]; then InstalledVersion=$(java/bin/java --version | grep \\\"Temurin-\\\" | head -n1 | sed -n \\\"s/.*Temurin-\\\\([^[:space:]]\\\\+\\\\).*/\\\\1/p\\\"); else InstalledVersion=\\\"\\\"; fi; LatestVersionBuild=$(wget -qO- \\\"https://api.adoptium.net/v3/assets/latest/{{SpecificInstanceJavaVersion}}/hotspot?architecture=x64&image_type=jdk&os=linux&vendor=eclipse\\\" | jq -r \\\".[0].version.openjdk_version\\\" | sed \\\"s/-LTS$//\\\"); if [[ \\\"$InstalledVersion\\\" == \\\"$LatestVersionBuild\\\" ]]; then echo \\\"Eclipse Temurin Java $LatestVersionBuild already installed. Skipping\\\" && exit 0; else [[ -f java.tar.gz ]] && rm -f java.tar.gz >/dev/null 2>&1; wget -qO java.tar.gz https://api.adoptium.net/v3/binary/latest/{{SpecificInstanceJavaVersion}}/ga/linux/x64/jdk/hotspot/normal/eclipse || { echo \\\"Download failed from the Eclipse Temurin CDN. This is a fault with the CDN, not AMP. Aborting\\\"; exit 1; }; mkdir -p java && rm -rf java/* >/dev/null 2>&1 && tar -xzf java.tar.gz -C java --strip-components=1 >/dev/null 2>&1 && rm -f java.tar.gz >/dev/null 2>&1 && chmod +x java/bin/java && echo \\\"Eclipse Temurin Java $LatestVersionBuild downloaded\\\"; fi\"",
        "UpdateSourceConditionSetting": "JavaVersion",
        "UpdateSourceConditionValue": "{{Windows:java\\bin\\java.exe}}{{Linux:java/bin/java}}",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Java Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSourceArch": "aarch64",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"cd hytale && if [[ -x java/bin/java ]]; then InstalledVersion=$(java/bin/java --version | grep \\\"Temurin-\\\" | head -n1 | sed -n \\\"s/.*Temurin-\\\\([^[:space:]]\\\\+\\\\).*/\\\\1/p\\\"); else InstalledVersion=\\\"\\\"; fi; LatestVersionBuild=$(wget -qO- \\\"https://api.adoptium.net/v3/assets/latest/{{SpecificInstanceJavaVersion}}/hotspot?architecture=aarch64&image_type=jdk&os=linux&vendor=eclipse\\\" | jq -r \\\".[0].version.openjdk_version\\\" | sed \\\"s/-LTS$//\\\"); if [[ \\\"$InstalledVersion\\\" == \\\"$LatestVersionBuild\\\" ]]; then echo \\\"Eclipse Temurin Java $LatestVersionBuild already installed. Skipping\\\" && exit 0; else [[ -f java.tar.gz ]] && rm -f java.tar.gz >/dev/null 2>&1; wget -qO java.tar.gz https://api.adoptium.net/v3/binary/latest/{{SpecificInstanceJavaVersion}}/ga/linux/aarch64/jdk/hotspot/normal/eclipse || { echo \\\"Download failed from the Eclipse Temurin CDN. This is a fault with the CDN, not AMP. Aborting\\\"; exit 1; }; mkdir -p java && rm -rf java/* >/dev/null 2>&1 && tar -xzf java.tar.gz -C java --strip-components=1 >/dev/null 2>&1 && rm -f java.tar.gz >/dev/null 2>&1 && chmod +x java/bin/java && echo \\\"Eclipse Temurin Java $LatestVersionBuild downloaded\\\"; fi\"",
        "UpdateSourceConditionSetting": "JavaVersion",
        "UpdateSourceConditionValue": "{{Windows:java\\bin\\java.exe}}{{Linux:java/bin/java}}",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Java Download",
        "UpdateSourcePlatform": "Windows",
        "UpdateSource": "Executable",
        "UpdateSourceData": "powershell.exe",
        "UpdateSourceArgs": "-NoProfile -Command \"$ProgressPreference='SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Set-Location -Path 'hytale'; if (Test-Path 'java/bin/java.exe') { $InstalledVersion = (& java/bin/java.exe --version | Select-String -Pattern 'Temurin-(\\d+(?:\\.\\d+\\.\\d+(?:\\.\\d+)?)?\\+\\d+)' | Select-Object -First 1 | ForEach-Object { $_.Matches[0].Groups[1].Value }) } else { $InstalledVersion = '' }; $LatestVersionBuild = (Invoke-RestMethod -UseBasicParsing -Uri \\\"https://api.adoptium.net/v3/assets/latest/{{SpecificInstanceJavaVersion}}/hotspot?architecture=x64&image_type=jdk&os=windows&vendor=eclipse\\\")[0].version.openjdk_version -replace '-LTS$', ''; if ( $InstalledVersion -eq $LatestVersionBuild ) { Write-Output \\\"Eclipse Temurin Java $LatestVersionBuild already installed. Skipping\\\"; exit 0 } else { if ( Test-Path java.zip ) { Remove-Item java.zip -Force -ErrorAction SilentlyContinue *> $null }; try { Invoke-WebRequest -UseBasicParsing -Uri https://api.adoptium.net/v3/binary/latest/{{SpecificInstanceJavaVersion}}/ga/windows/x64/jdk/hotspot/normal/eclipse -OutFile java.zip -ErrorAction Stop } catch { Write-Output \\\"Download failed from the Eclipse Temurin CDN. This is a fault with the CDN, not AMP. Aborting\\\"; exit 1; }; Expand-Archive -Path \\\"java.zip\\\" -DestinationPath \\\".\\\" -Force *> $null; if ( Test-Path java.zip ) { Remove-Item java.zip -Force -ErrorAction SilentlyContinue *> $null }; if (Test-Path \\\"jdk-*\\\") { Remove-Item -Recurse -Force java -ErrorAction SilentlyContinue *> $null; Start-Sleep -Seconds 2; Get-ChildItem -Directory | Where-Object { $_.Name -like \\\"jdk-*\\\" } | Rename-Item -NewName \\\"java\\\" *> $null; Write-Output \\\"Eclipse Temurin Java $LatestVersionBuild downloaded\\\" } }\"",
        "UpdateSourceConditionSetting": "JavaVersion",
        "UpdateSourceConditionValue": "{{Windows:java\\bin\\java.exe}}{{Linux:java/bin/java}}",
        "SkipOnFailure": false
    },
    {
        "UpdateStageName": "Create Performance Saver Plugin Config Directory",
        "UpdateSourcePlatform": "All",
        "UpdateSource": "CreateDirectory",
        "UpdateSourceArgs": "{{$FullBaseDir}}Server/mods/Nitrado_PerformanceSaver",
        "UpdateSourceConditionSetting": "performance-saver-install",
        "UpdateSourceConditionValue": "true",
        "SkipOnFailure": true
    },
    {
        "UpdateStageName": "Performance Saver Plugin Download",
        "UpdateSourcePlatform": "Linux",
        "UpdateSource": "Executable",
        "UpdateSourceData": "/bin/bash",
        "UpdateSourceArgs": "-c \"cd hytale/Server/mods && wget -qO nitrado-performance-saver.jar $(wget -qO- https://api.github.com/repos/nitrado/hytale-plugin-performance-saver/releases/latest | grep browser_download_url | cut -d\\\\\\\" -f4 | grep -E \\\"nitrado-performance-saver.*\\.jar\\\") && echo \\\"Latest Nitrado Performance Saver plugin downloaded\\\"\"",
        "UpdateSourceConditionSetting": "performance-saver-install",
        "UpdateSourceConditionValue": "true",
        "SkipOnFailure": true
    },
    {
        "UpdateStageName": "Performance Saver Plugin Download",
        "UpdateSourcePlatform": "Windows",
        "UpdateSource": "Executable",
        "UpdateSourceData": "powershell.exe",
        "UpdateSourceArgs": "-NoProfile -Command \"$ProgressPreference='SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Set-Location -Path 'hytale/Server/mods'; Invoke-WebRequest -UseBasicParsing -Uri ((Invoke-RestMethod -UseBasicParsing -Uri 'https://api.github.com/repos/nitrado/hytale-plugin-performance-saver/releases/latest').assets | Where-Object { $_.browser_download_url -like '*nitrado-performance-saver*.jar' }).browser_download_url -OutFile 'nitrado-performance-saver.jar'; if ($?) { Write-Output \\\"Latest Nitrado Performance Saver plugin downloaded\\\" }\"",
        "UpdateSourceConditionSetting": "performance-saver-install",
        "UpdateSourceConditionValue": "true",
        "SkipOnFailure": true
    },
    {
        "UpdateStageName": "Default Performance Saver plugin config.json File Download",
        "UpdateSourcePlatform": "All",
        "UpdateSource": "FetchURL",
        "UpdateSourceData": "https://raw.githubusercontent.com/CubeCoders/AMPTemplates/main/hytaleperformancesaverconfig.json",
        "UpdateSourceArgs": "config.json",
        "UpdateSourceTarget": "{{$FullBaseDir}}Server/mods/Nitrado_PerformanceSaver",
        "OverwriteExistingFiles": false,
        "UpdateSourceConditionSetting": "performance-saver-install",
        "UpdateSourceConditionValue": "true",
        "SkipOnFailure": true
    },
    {
        "UpdateStageName": "Create Early Plugins Directory",
        "UpdateSourcePlatform": "All",
        "UpdateSource": "CreateDirectory",
        "UpdateSourceArgs": "{{$FullBaseDir}}Server/earlyplugins",
        "SkipOnFailure": true
    }
]