This script automates the installation and launching of a Minecraft 1.19.2 server using Forge. It checks for required Java version (17 or higher), automatically installs Forge if not present, configures server properties, and starts the server.

Features:

  • Automatic Java Version Check: Ensures your system has Java 17 or higher installed.
  • Forge Installation: Downloads and installs Forge if it's not found.
  • Server Configuration: Creates a 'server.properties' file with basic settings.
  • Automatic Restart: Automatically restarts the server after crashes, unless disabled.

Configuration:

  • FORGE_VERSION: Specify the Forge version you want to use (e.g., 43.2.14).
  • ATM8_JAVA: (Optional) Set the full path to your Java executable if you want to use a specific Java runtime.
  • ATM8_RESTART: (Optional) Set to false to disable automatic restarts.
  • ATM8_INSTALL_ONLY: (Optional) Set to true to only install Forge without starting the server.

How to Use:

  1. Save the script as a .bat file (e.g., start_server.bat).
  2. Place the script in the desired server directory.
  3. Run the script.

Code:

@echo off
set FORGE_VERSION=43.2.14
:: To use a specific Java runtime, set an environment variable named ATM8_JAVA to the full path of java.exe.
:: To disable automatic restarts, set an environment variable named ATM8_RESTART to false.
:: To install the pack without starting the server, set an environment variable named ATM8_INSTALL_ONLY to true.
set MIRROR=https://maven.allthehosting.com/releases/
set INSTALLER='%~dp0forge-1.19.2-%FORGE_VERSION%-installer.jar'
set FORGE_URL='%MIRROR%net/minecraftforge/forge/1.19.2-%FORGE_VERSION%/forge-1.19.2-%FORGE_VERSION%-installer.jar'

:JAVA
if not defined ATM8_JAVA (
    set ATM8_JAVA=java
)

'%ATM8_JAVA%' -version 1>nul 2>nul || (
   echo Minecraft 1.19 requires Java 17 - Java not found
   pause
   exit /b 1
)

:FORGE
setlocal
cd /D '%~dp0'
if not exist 'libraries' (
    echo Forge not installed, installing now.
    if not exist %INSTALLER% (
        echo No Forge installer found, downloading from %FORGE_URL%
        bitsadmin.exe /rawreturn /nowrap /transfer forgeinstaller /download /priority FOREGROUND %FORGE_URL% %INSTALLER%
    )
    
    echo Running Forge installer.
    '%ATM8_JAVA%' -jar %INSTALLER% -installServer -mirror %MIRROR%
)

if not exist 'server.properties' (
    (
        echo allow-flight=true
        echo motd=All the Mods 8
        echo max-tick-time=180000
    )> 'server.properties'
)

if '%ATM8_INSTALL_ONLY%' == 'true' (
    echo INSTALL_ONLY: complete
    goto:EOF
)

for /f tokens^=2-5^ delims^=.-_^' %%j in (''%ATM8_JAVA%' -fullversion 2^>^&1') do set 'jver=%%j'
if not %jver% geq 17  (
    echo Minecraft 1.19 requires Java 17 - found Java %jver%
    pause
    exit /b 1
) 

:START
'%ATM8_JAVA%' @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.19.2-%FORGE_VERSION%/win_args.txt nogui

if '%ATM8_RESTART%' == 'false' ( 
    goto:EOF 
)

echo Restarting automatically in 10 seconds (press Ctrl + C to cancel)
timeout /t 10 /nobreak > NUL
goto:START

Note: The script utilizes the bitsadmin.exe command to download the Forge installer, which might require enabling BITS (Background Intelligent Transfer Service) on your system.

Minecraft 1.19.2 Forge Server Starter -  Automatic Installation and Launch

原文地址: https://www.cveoy.top/t/topic/bKG8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录