Skip to content

Commit 3257000

Browse files
committed
Hotfix: Support Java 25 and environment injection for run scripts (v1.1.9)
1 parent acc4bca commit 3257000

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

backend/server/server_handler.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,18 @@ def _get_start_command(self):
370370
self.output_callback("Critical error: No working Java installation was found. Please install Java.\n", "error")
371371
return None, None
372372

373+
# Prepare environment for startup (injecting JAVA_HOME and PATH)
374+
custom_env = os.environ.copy()
375+
if java_path != "java":
376+
# Extract installation root (assuming path/to/java-21/bin/java.exe)
377+
java_bin_dir = os.path.dirname(java_path)
378+
java_root = os.path.dirname(java_bin_dir)
379+
custom_env["JAVA_HOME"] = java_root
380+
# Prepend to PATH so scripts find this 'java' first
381+
path_sep = ';' if sys.platform == "win32" else ':'
382+
custom_env["PATH"] = f"{java_bin_dir}{path_sep}{custom_env.get('PATH', '')}"
383+
logger.info(f"Injecting Java environment: JAVA_HOME={java_root}")
384+
373385
run_script = None
374386

375387
# Universal check for startup scripts
@@ -385,9 +397,7 @@ def _get_start_command(self):
385397
# If a run script is found, prioritize it
386398
if run_script:
387399
self.output_callback(f"Detected startup script: {os.path.basename(run_script)}. Using it to launch.\n", "info")
388-
# For Forge, we might need to set JVM_ARGS, but for now, a direct run is more universal.
389-
# A more advanced implementation could parse the script to inject RAM settings.
390-
return [run_script, '--nogui'], None
400+
return [run_script, '--nogui'], custom_env
391401

392402
# Fallback to JAR-based startup if no script is found
393403
self.output_callback("No startup script found. Using generic JAR startup method.\n", "info")
@@ -451,7 +461,7 @@ def _get_start_command(self):
451461

452462
command.extend(['-jar', os.path.basename(server_jar_path), '--nogui'])
453463

454-
return command, None
464+
return command, custom_env
455465

456466
def _run_server(self, command, env):
457467
stdout_thread = None

backend/utils/java_manager.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,16 @@ def get_required_java_version(self, minecraft_version: str) -> int:
110110

111111
if major_version == 1:
112112
if minor_version >= 22:
113-
return 21 # Default to 21 for unknown future versions (e.g. 1.22+)
113+
return 25 # 1.22+ requiere Java 25
114114
elif minor_version == 21 and patch_version >= 4:
115-
return 21 # 1.21.4+ works well with 21
115+
return 25 # 1.21.4+ requiere Java 25
116116
elif minor_version >= 21:
117117
return 21
118118
elif minor_version >= 17:
119119
return 17
120+
elif major_version >= 26:
121+
# NeoForge or Future Versioning (e.g. 26.1.1)
122+
return 25
120123
except Exception as e:
121124
logger.warning(f"Error parsing version {version}: {e}")
122125

@@ -125,13 +128,13 @@ def get_required_java_version(self, minecraft_version: str) -> int:
125128
if major_minor in self.mc_java_requirements:
126129
return self.mc_java_requirements[major_minor]
127130

128-
# Para versiones no mapeadas y muy nuevas, asumir Java 21
129-
logger.warning(f"Unknown Minecraft version {version}, defaulting to Java 21")
130-
return 21
131+
# Para versiones no mapeadas y muy nuevas (>= 26 o 1.22), asumir Java 25
132+
logger.warning(f"Unknown Minecraft version {version}, defaulting to Java 25")
133+
return 25
131134

132135
# Fallback para versiones totalmente desconocidas
133-
logger.warning(f"Unknown Minecraft version {version}, defaulting to Java 21")
134-
return 21
136+
logger.warning(f"Unknown Minecraft version {version}, defaulting to Java 25")
137+
return 25
135138

136139
def detect_system_java(self, java_path: str = "java") -> Optional[Tuple[int, str]]:
137140
"""

changelog.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
### ⚡ HOTFIX 1.1.9.1 (Included in v1.1.9):
1616
- **Fixed backend restart loop on Windows** — Watchdog now correctly monitors the Electron process using a passed PID, preventing premature restarts during installations.
17-
- **Improved Java version mapping** — Version detection now defaults to Java 21/17 for unknown future versions instead of Java 25.
18-
- **Robust Forge version handling** — Versions like "26.1.1" no longer trigger incorrect Java 25 snapshot logic.
17+
- **Improved Java version mapping** — Version detection now correctly maps high-version servers (NeoForge/NeoMinecraft 26.x+) to **Java 25**.
18+
- **Fixed Startup Scripts (run.bat/run.sh)** — Implemented **Environment Injection** (JAVA_HOME & PATH) to force startup scripts to use the app's managed Java version instead of the system default.
19+
- **Robust Forge version handling** — Versions like "26.1.1" now correctly trigger the Java 25 requirement.
1920

2021
### 🔧 IMPROVEMENTS:
2122
- **Smart close behavior** — App checks for running servers before deciding to hide or quit

0 commit comments

Comments
 (0)