@@ -44,28 +44,35 @@ def start(self):
4444
4545 def _get_start_command (self ):
4646 java_path = "java"
47-
48- if self .server_type == 'forge' :
49- user_args_file = os .path .join (self .server_path , 'user_jvm_args.txt' )
50- win_args_path_pattern = os .path .join (self .server_path , 'libraries' , 'net' , 'minecraftforge' , 'forge' , '*' , 'win_args.txt' )
51- win_args_files = glob .glob (win_args_path_pattern )
52-
53- if os .path .exists (user_args_file ) and win_args_files :
54- self .output_callback ("Detected modern Forge server. Using run.bat for startup.\n " , "info" )
55- run_script = os .path .join (self .server_path , 'run.bat' )
56- if os .path .exists (run_script ):
57- env = os .environ .copy ()
58- env ["JVM_ARGS" ] = f"-Xms{ self .ram_min } { self .ram_unit } -Xmx{ self .ram_max } { self .ram_unit } "
59- return [run_script , '--nogui' ], env
60-
61- self .output_callback ("Using generic JAR startup method.\n " , "info" )
47+ run_script = None
48+
49+ # Universal check for startup scripts
50+ if sys .platform == "win32" :
51+ script_path = os .path .join (self .server_path , 'run.bat' )
52+ if os .path .exists (script_path ):
53+ run_script = script_path
54+ else : # For macOS and Linux
55+ script_path = os .path .join (self .server_path , 'run.sh' )
56+ if os .path .exists (script_path ):
57+ run_script = script_path
58+
59+ # If a run script is found, prioritize it
60+ if run_script :
61+ self .output_callback (f"Detected startup script: { os .path .basename (run_script )} . Using it to launch.\n " , "info" )
62+ # For Forge, we might need to set JVM_ARGS, but for now, a direct run is more universal.
63+ # A more advanced implementation could parse the script to inject RAM settings.
64+ return [run_script , '--nogui' ], None
65+
66+ # Fallback to JAR-based startup if no script is found
67+ self .output_callback ("No startup script found. Using generic JAR startup method.\n " , "info" )
6268 all_jars = glob .glob (os .path .join (self .server_path , '*.jar' ))
6369 server_jar_path = None
6470
6571 non_installer_jars = [j for j in all_jars if 'installer' not in os .path .basename (j ).lower ()]
6672
6773 if non_installer_jars :
68- preferred_names = ['server.jar' , 'minecraft_server.jar' , 'paper.jar' ]
74+ # Look for common server jar names first
75+ preferred_names = ['server.jar' , 'minecraft_server.jar' , 'paper.jar' , 'spigot.jar' , 'fabric-server-launch.jar' ]
6976 for name in preferred_names :
7077 for jar in non_installer_jars :
7178 if os .path .basename (jar ).lower () == name :
@@ -74,19 +81,31 @@ def _get_start_command(self):
7481 if server_jar_path :
7582 break
7683
84+ # If no preferred name is found, take the first non-installer jar
7785 if not server_jar_path :
7886 server_jar_path = non_installer_jars [0 ]
7987
80- elif all_jars :
88+ elif all_jars : # Fallback if only installer jars are present for some reason
8189 server_jar_path = all_jars [0 ]
8290
8391 if not server_jar_path :
84- self .output_callback ("No server .jar file found in the directory.\n " , "error" )
92+ self .output_callback ("Error: No server .jar file or run script found in the directory.\n " , "error" )
8593 return None , None
8694
8795 min_ram_str = f"-Xms{ self .ram_min } { self .ram_unit } "
8896 max_ram_str = f"-Xmx{ self .ram_max } { self .ram_unit } "
89- return [java_path , max_ram_str , min_ram_str , '-jar' , os .path .basename (server_jar_path ), '--nogui' ], None
97+
98+ # Base command
99+ command = [java_path , max_ram_str , min_ram_str ]
100+
101+ # Add any server-type specific arguments before the -jar flag
102+ # Example for future use:
103+ # if self.server_type == 'some_type':
104+ # command.extend(['-Dsome.flag=true'])
105+
106+ command .extend (['-jar' , os .path .basename (server_jar_path ), '--nogui' ])
107+
108+ return command , None
90109
91110 def _run_server (self , command , env ):
92111 try :
@@ -131,20 +150,22 @@ def stop(self, silent=False):
131150
132151 # The process will terminate on its own, and the _run_server finally block will clean up.
133152
134- def send_command (self , cmd ):
135- if self .server_process and ( self .is_running () or self .is_starting ()) :
153+ def send_command (self , command ):
154+ if self .is_running () and self .server_process and self .server_process . stdin :
136155 try :
137- if self .server_process .stdin :
138- self .server_process .stdin .write (cmd + '\n ' )
139- self .server_process .stdin .flush ()
140- if cmd != "stop" : # Avoid logging the stop command twice
141- self .output_callback (f"> { cmd } \n " , "info" )
142- else :
143- self .output_callback ("Cannot send command: server stdin is not available.\n " , "error" )
156+ self .server_process .stdin .write (f"{ command } \n " )
157+ self .server_process .stdin .flush ()
158+ self .output_callback (f"> { command } \n " , "info" )
144159 except (IOError , ValueError ) as e :
145- self .output_callback (f"Failed to send command: { e } \n " , "error" )
160+ self .output_callback (f"Error sending command: { e } \n " , "error" )
146161 else :
147- self .output_callback ("Cannot send command: server is not running.\n " , "warning" )
162+ self .output_callback ("Cannot send command: server is not running or stdin is not available.\n " , "warning" )
163+
164+ def update_ram (self , ram_max , ram_min , ram_unit ):
165+ self .ram_max = ram_max
166+ self .ram_min = ram_min
167+ self .ram_unit = ram_unit
168+ self .output_callback (f"RAM settings updated to { ram_min } -{ ram_max } { ram_unit } . Changes will apply on next restart.\n " , "info" )
148169
149170 def get_pid (self ):
150171 if self .server_process :
0 commit comments