From 470ab04bb222b8bb257ac0cf176887af014c2d49 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Thu, 17 Aug 2023 15:11:29 -0400 Subject: [PATCH] Use API v2 for jar creation and jar import --- app/classes/shared/main_controller.py | 54 ++++++-- app/frontend/templates/server/wizard.html | 146 ++++++++++++++++++++-- 2 files changed, 178 insertions(+), 22 deletions(-) diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index 071a4111..d5607d17 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -348,12 +348,14 @@ class Controller: server_file = f"{create_data['type']}-{create_data['version']}.jar" # Create an EULA file - with open( - os.path.join(new_server_path, "eula.txt"), "w", encoding="utf-8" - ) as file: - file.write( - "eula=" + ("true" if create_data["agree_to_eula"] else "false") - ) + if "agree_to_eula" in create_data: + with open( + os.path.join(new_server_path, "eula.txt"), "w", encoding="utf-8" + ) as file: + file.write( + "eula=" + + ("true" if create_data["agree_to_eula"] else "false") + ) elif root_create_data["create_type"] == "import_server": _copy_import_dir_files(create_data["existing_server_path"]) server_file = create_data["jarfile"] @@ -376,11 +378,41 @@ class Controller: def _wrap_jar_if_windows(): return f'"{server_file}"' if Helpers.is_os_windows() else server_file - server_command = ( - f"java -Xms{_gibs_to_mibs(min_mem)}M " - f"-Xmx{_gibs_to_mibs(max_mem)}M " - f"-jar {_wrap_jar_if_windows()} nogui" - ) + if root_create_data["create_type"] == "download_jar": + if Helpers.is_os_windows(): + # Let's check for and setup for install server commands + if create_data["type"] == "forge": + server_command = ( + f"java -Xms{Helpers.float_to_string(min_mem)}M " + f"-Xmx{Helpers.float_to_string(max_mem)}M " + f'-jar "{server_file}" --installServer' + ) + else: + server_command = ( + f"java -Xms{Helpers.float_to_string(min_mem)}M " + f"-Xmx{Helpers.float_to_string(max_mem)}M " + f'-jar "{server_file}" nogui' + ) + else: + if create_data["type"] == "forge": + server_command = ( + f"java -Xms{Helpers.float_to_string(min_mem)}M " + f"-Xmx{Helpers.float_to_string(max_mem)}M " + f"-jar {server_file} --installServer" + ) + else: + server_command = ( + f"java -Xms{Helpers.float_to_string(min_mem)}M " + f"-Xmx{Helpers.float_to_string(max_mem)}M " + f"-jar {server_file} nogui" + ) + else: + server_command = ( + f"java -Xms{_gibs_to_mibs(min_mem)}M " + f"-Xmx{_gibs_to_mibs(max_mem)}M " + f"-jar {_wrap_jar_if_windows()} nogui" + ) + elif data["create_type"] == "minecraft_bedrock": if root_create_data["create_type"] == "import_server": existing_server_path = Helpers.get_os_understandable_path( diff --git a/app/frontend/templates/server/wizard.html b/app/frontend/templates/server/wizard.html index 69f9e5af..61fb8c46 100644 --- a/app/frontend/templates/server/wizard.html +++ b/app/frontend/templates/server/wizard.html @@ -29,7 +29,7 @@

-

+ {% if data["server_api"] and data["online"] %}
{% else %} @@ -89,7 +89,7 @@
-
@@ -98,7 +98,7 @@
-
@@ -107,7 +107,7 @@
- +
@@ -122,7 +122,7 @@
- +
@@ -130,7 +130,7 @@
- +
@@ -197,7 +197,7 @@

- + {% raw xsrf_form_html() %}

@@ -205,7 +205,7 @@
- +
@@ -237,7 +237,7 @@
- +
@@ -245,7 +245,7 @@
- +
@@ -759,7 +759,7 @@ {% end %} -{% block js%} +{% block js %} + +