Merge branch 'tweak/forge-fix' into 'dev'

Fixing Forge Installation

See merge request crafty-controller/crafty-4!687
This commit is contained in:
Iain Powrie 2024-01-16 18:08:27 +00:00
commit 700635acf2
2 changed files with 35 additions and 3 deletions

View File

@ -5,7 +5,7 @@ TBD
### Bug fixes
- Fix bukkit and downstream fork MOTD crash ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/686))
### Tweaks
TBD
- Refactor Forge server initialisation flow for newer versions ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/687))
### Lang
TBD
<br><br>

View File

@ -725,8 +725,9 @@ class ServerInstance:
server_obj.execution_command = execution_command
Console.debug("SUCCESS! Forge install completed")
else:
# NEW VERSION >= 1.17
elif version_major <= 1 and version_minor < 20:
# NEW VERSION >= 1.17 and <= 1.20
# (no jar file in server dir, only run.bat and run.sh)
run_file_path = ""
if self.helper.is_os_windows():
@ -771,6 +772,37 @@ class ServerInstance:
)
server_obj.execution_command = execution_command
Console.debug("SUCCESS! Forge install completed")
else:
# NEW VERSION >= 1.20
# (executable jar is back in server dir)
# Retrieving the executable jar filename
file_path = glob.glob(
f"{server_obj.path}/forge-{version[0][0]}*.jar"
)[0]
file_name = re.findall(
r"(forge-[\-0-9.]+-shim.jar)",
file_path,
)[0]
# Let's set the proper server executable
server_obj.executable = os.path.join(file_name)
# Get memory values
memory_values = re.findall(
r"-Xms([A-Z0-9\.]+) -Xmx([A-Z0-9\.]+)",
server_obj.execution_command,
)
# Now lets set up the new run command.
# This is based off the run.sh/bat that
# Forge uses in 1.17 and <
execution_command = (
f"java -Xms{memory_values[0][0]} -Xmx{memory_values[0][1]}"
f' -jar "{file_name}" nogui'
)
server_obj.execution_command = execution_command
Console.debug("SUCCESS! Forge install completed")
except:
logger.debug("Could not find run file.")
# TODO Use regex to get version and rebuild simple execution