@echo off
setlocal EnableDelayedExpansion
rem ============================================================
rem JB Launcher - bootstrap
rem ============================================================
set "ROOT=%~dp0"
if "%ROOT:~-1%"=="\" set "ROOT=%ROOT:~0,-1%"
set "JDK_DIR=%ROOT%\jdk25"
set "JAVA_EXE=%JDK_DIR%\bin\java.exe"
set "JAR=%ROOT%\jblauncher.jar"
set "PS1=%TEMP%\jblauncher_install.ps1"
set "ARCH=x64"
if /I "%PROCESSOR_ARCHITECTURE%"=="ARM64" set "ARCH=aarch64"
if /I "%PROCESSOR_ARCHITEW6432%"=="ARM64" set "ARCH=aarch64"
if not exist "%JAR%" (
echo [ERROR] Missing jblauncher.jar
pause
exit /b 1
)
rem === Java check ===
if exist "%JAVA_EXE%" goto :ask_user
for /f "delims=" %%I in ('where java 2^>nul') do (
set "JAVA_EXE=%%I"
goto :ask_user
)
if defined JAVA_HOME (
if exist "%JAVA_HOME%\bin\java.exe" (
set "JAVA_EXE=%JAVA_HOME%\bin\java.exe"
goto :ask_user
)
)
rem 4) No Java found - install Temurin 25 locally.
set "JAVA_EXE=%JDK_DIR%\bin\java.exe"
echo.
echo === No Java found - extracting Eclipse Temurin JDK 25 ===
echo Destination: %JDK_DIR%
echo.
set "ZIP=%ROOT%\jdk25.zip"
if not exist "%ZIP%" (
echo [ERROR] jdk25.zip not found at %ZIP%
echo Please download it manually from: https://api.adoptium.net/v3/binary/latest/25/ga/windows/x64/jdk/hotspot/normal/eclipse
pause
exit /b 1
)
set "PS1=%TEMP%\jblauncher_extract_jdk25.ps1"
> "%PS1%" echo $ErrorActionPreference = "Stop"
>>"%PS1%" echo $zip = "%ZIP%"
>>"%PS1%" echo $jdk = "%JDK_DIR%"
>>"%PS1%" echo $stage = "%ROOT%\stage"
>>"%PS1%" echo.
>>"%PS1%" echo Write-Host "Extracting $zip"
>>"%PS1%" echo if (Test-Path $stage) { Remove-Item $stage -Recurse -Force }
>>"%PS1%" echo New-Item -ItemType Directory -Path $stage ^| Out-Null
>>"%PS1%" echo Expand-Archive -Path $zip -DestinationPath $stage -Force
>>"%PS1%" echo.
>>"%PS1%" echo $inner = Get-ChildItem $stage ^| Select-Object -First 1
>>"%PS1%" echo Write-Host "Moving extracted JDK to $jdk"
>>"%PS1%" echo if (Test-Path $jdk) { Remove-Item $jdk -Recurse -Force }
>>"%PS1%" echo Move-Item $inner.FullName $jdk -Force
>>"%PS1%" echo Remove-Item $stage -Recurse -Force
>>"%PS1%" echo Write-Host "Installed to $jdk"
powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%"
if errorlevel 1 (
echo [ERROR] JDK extraction failed.
del "%PS1%" >nul 2>&1
pause
exit /b 1
)
del "%PS1%" >nul 2>&1
:ask_user
echo.
set /p "USERNAME_IN=Enter Minecraft username: "
echo Launching...
"%JAVA_EXE%" -jar "%JAR%" --username "%USERNAME_IN%"
pause
endlocal