Skip to content

Commit

Permalink
1.3-3 Linux support v1
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jul 2, 2024
1 parent 3bf51bc commit 53820b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
9 changes: 9 additions & 0 deletions java.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@
JAVA_EXEC = 'java.exe'
elif os.name == 'posix':
JAVA_EXEC = 'java'
async def recursive_chmod(directory, mode):
for root, dirs, files in os.walk(directory):
for d in dirs:
os.chmod(os.path.join(root, d), mode)
for f in files:
os.chmod(os.path.join(root, f), mode)

class Java(HSL):

def __init__(self):
super().__init__()

async def getJavaVersion(self,mcVersion: str) -> str:
'''
get java version
Expand Down Expand Up @@ -68,6 +76,7 @@ async def downloadJava(self,javaVersion,path) -> bool:
if downloadFile(url,filename):
with zipfile.ZipFile(filename,'r') as file:
file.extractall(path)
await recursive_chmod(path,0o755)
os.remove(filename)
return True
return False
Expand Down
25 changes: 16 additions & 9 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class Server(HSL):
"""
Server Class
"""

def pathJoin(self,path: str):
return os.path.join(self.path,path)

def readLine(self, process, output_queue: Queue):
for line in iter(process.stdout.readline, b''):
try:
Expand Down Expand Up @@ -47,6 +51,7 @@ def input(self, process, input_queue: Queue):

def check_process(self, process):
return psutil.pid_exists(process.pid)

def __init__(self, *, name: str, type: str, path: str, javaPath: str, maxRam: str, data={}):
super().__init__()
self.name = name
Expand All @@ -58,27 +63,29 @@ def __init__(self, *, name: str, type: str, path: str, javaPath: str, maxRam: st
def run(self):
if 'startup_cmd' in self.data:
subprocess.Popen(self.data['startup_cmd'],cwd=self.path)

jvm_setting: str = ''
if 'jvm_setting' in self.data:
jvm_setting: str = ' ' + self.data['jvm_setting']

if os.name == 'posix':
javaexecPath = r'./../../' + self.javaPath if not self.config.direct_mode else r'./' + self.javaPath
else:
javaexecPath = self.javaPath
match self.type:
case 'vanilla':
run_command = f'{self.javaPath} -Dfile.encoding=utf-8 -Xmx{self.maxRam} -jar server.jar'
case 'paper':
run_command = f'{self.javaPath} -Dfile.encoding=utf-8 -Xmx{self.maxRam} -jar server.jar'
case 'fabric':
run_command = f'{self.javaPath} -Dfile.encoding=utf-8 -Xmx{self.maxRam} -jar server.jar'
case 'vanilla' | 'paper' | 'fabric':
run_command = f'{javaexecPath} -Dfile.encoding=utf-8 -Xmx{self.maxRam} -jar server.jar'
case 'forge':
mcVersion = self.data['mcVersion']
forgeVersion = self.data['forgeVersion']
mcMajorVersion = int(mcVersion.split('.')[1])
if mcMajorVersion >= 17:
if os.name == 'nt':
run_command = f'{self.javaPath}{jvm_setting} -Dfile.encoding=utf-8 -Xmx{self.maxRam} @user_jvm_args.txt @libraries/net/minecraftforge/forge/{mcVersion}-{forgeVersion}/win_args.txt %*'
run_command = f'{javaexecPath}{jvm_setting} -Dfile.encoding=utf-8 -Xmx{self.maxRam} @user_jvm_args.txt @libraries/net/minecraftforge/forge/{mcVersion}-{forgeVersion}/win_args.txt %*'
else:
run_command = f'{self.javaPath}{jvm_setting} -Dfile.encoding=utf-8 -Xmx{self.maxRam} @user_jvm_args.txt @libraries/net/minecraftforge/forge/{mcVersion}-{forgeVersion}/unix_args.txt %*'
run_command = f'{javaexecPath}{jvm_setting} -Dfile.encoding=utf-8 -Xmx{self.maxRam} @user_jvm_args.txt @libraries/net/minecraftforge/forge/{mcVersion}-{forgeVersion}/unix_args.txt %*'
if mcMajorVersion < 17:
run_command = f'{self.javaPath} -Dfile.encoding=utf-8 -Xmx{self.maxRam} -jar forge-{mcVersion}-{forgeVersion}.jar'
run_command = f'{javaexecPath} -Dfile.encoding=utf-8 -Xmx{self.maxRam} -jar forge-{mcVersion}-{forgeVersion}.jar'
console.log(f'Run Command: {run_command}')

workdir = self.path
Expand Down

0 comments on commit 53820b6

Please sign in to comment.