From 9cf9fcf4a733b4af616bf9be2548e67ef13f5ee0 Mon Sep 17 00:00:00 2001 From: Mathea Date: Thu, 5 Oct 2023 02:59:25 +0100 Subject: [PATCH] Update Scripts --- main.py | 143 ++++++++++++++++++++++++++++++++++++++++++++++ makerbot.py | 20 ------- oldservermaker.py | 22 +++---- 3 files changed, 155 insertions(+), 30 deletions(-) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..21b4f14 --- /dev/null +++ b/main.py @@ -0,0 +1,143 @@ +import makerbot, oldservermaker +import time +from subprocess import check_output + + +def autoSetup(): + GenerateStartup() + + runner = True + while runner: + print("Attempting to Start jar file") + print("please type Stop into console to finish") + output= check_output(['java', '-jar', 'server.jar']) + decoded = output.decode() + print(decoded + "\n\n\n") + if decoded.find("You need to agree to the EULA in order to run the server") != -1: + file = open("eula.txt","r") + hold =file.read() + file.close() + run = True + while run: + + try: + choice = int(input(hold + "\nDo you agree to the Eula\n1.yes\n2.no\n>")) + if (choice == 1): + run = False + print("Accepting Eula") + file = open("eula.txt","w") + hold = hold.replace("false","true") + print(hold) + file.write(hold) + file.close() + elif (choice ==2): + print("you can't proceed with setting up Mincraft") + return False + + except Exception as e: + + print("\nnot a valid choice\n") + time.sleep(1) + else: + print("\nSuccess your server runs... Exiting\n") + run = False + runner = False + +def ChangeConfig(): + run = True + while run: + try: + choice = int(input("\n1.Lagacy Creation config file(long)\n2.Search file\n3.Exit\n>")) + if choice == 1: + oldservermaker.config() + + elif choice == 2: + search =input("Search Property?") + file = open("server.properties","r") + find = file.read().split("\n") + index = -1 + file.close() + for i in range(0,len(find)): + if find[i].find(search) != -1: + index = i + + if index == -1: + print("not found") + else: + print(find[index] + "\nedit?\n") + edit = input(">") + find[index] = find[index].split("=")[0] + "=" + edit + print(find[index]) + print("Writting") + file = open("server.properties","w") + for item in find: + file.write(item + "\n") + file.close() + + elif choice == 3: + run = False + except: + print("\nnot valid\n") + +def GenerateStartup(): + #get ram in gigabytes + rama =oldservermaker.getSystemRam() + ramamount = int(rama * 0.3 * 1024) + print("using recommend size of " + str(ramamount) + "M") + batch = "echo starting server\njava -Xmx" + str(ramamount) + "M -jar server.jar\necho server stopped" + from sys import platform + if platform == "win32": + # Windows... + file = open("run.bat","w") + file.write(batch) + file.close() + else: + # linux etc..? + file = open("run.sh","w") + file.write(batch) + file.close() + + + + +def main(): + run = True + while run: + + try: + choice = int(input("1.output all Minecraft versions\n2.slient Load\n>")) + if (choice == 1): + run = False + ClassRunner = makerbot.MakerBot(False) + elif (choice ==2): + run = False + ClassRunner = makerbot.MakerBot(True) + + except Exception as e: + + print("\nnot a valid choice\n") + time.sleep(1) + + run = True + while run: + try: + config = int(input("\n1.AutoSetup\n2.ChangeConfig\n3.StartupMaker\n4.Exit\n>")) + if (choice ==1): + autoSetup() + elif (choice ==2) + + elif (choice ==3): + GenerateStartup() + elif (choice ==4): + run = False + quit() + + except Exception as e: + print("\nnot a valid choice\n") + time.sleep(1) + + + +#runs main class +#main() +autoSetup() diff --git a/makerbot.py b/makerbot.py index 7663e5d..844ea3f 100644 --- a/makerbot.py +++ b/makerbot.py @@ -91,23 +91,3 @@ def __init__(self,slient): print("inital Download Complete :3") - -def main(): - run = True - while run: - - try: - choice = int(input("1.output all Minecraft versions\n2.slient Load\n>")) - if (choice == 1): - run = False - ClassRunner = MakerBot(False) - elif (choice ==2): - run = False - ClassRunner = MakerBot(True) - except Exception as e: - print("\nnot a valid choice\n") - time.sleep(1) - - -#runs main class -main() diff --git a/oldservermaker.py b/oldservermaker.py index b91b4f5..047f267 100644 --- a/oldservermaker.py +++ b/oldservermaker.py @@ -221,17 +221,19 @@ def startup(): print("\n\n\n\n") -try: - f = open("server.jar","r") - f.close() - input("press enter to start server....") - serverstart() - print("server stopped") - quit -except: - startup() - +def main(): + try: + f = open("server.jar","r") + f.close() + input("press enter to start server....") + serverstart() + print("server stopped") + quit + except: + startup() +if __name__ == '__main__': + main()