Commit 25e59467 authored by whoatemybutter's avatar whoatemybutter

Replace mcautoserver.py with v0.14

parent 1c61160b
#!/usr/bin/env python3
# encoding=utf-8
"""
Quick and easy set up for various McAutoServers.
Quick and easy set up for various Minecraft servers.
__author__ = "WhoAteMyButter"
__contact__ = "https://gitlab.com/whoatemybutte7/"
__credits__ = ["Xephlon - Pyrite", "ITZG - MC Docker"]
__date__ = ["2", "23", "2020"]
__date__ = ["2", "29", "2020"]
__license__ = "GPL v3"
__maintainer__ = "WhoAteMyButter"
__version__ = "0.13"
__version__ = "0.14"
"""
import argparse
import imghdr
......@@ -99,17 +99,19 @@ def download(url=None, outfile=None):
def set_type(opts):
"""Set the type of server, vanilla, forge, etc."""
pre(opts, msg="McAutoServer - Server Type")
if not opts["auto"]:
if not opts["type"]:
opts["type"] = input("What type is this server?\n"
"Default is \"Vanilla\"\n"
"[V]anilla - Unmodified Mojang-provided server\n"
"[F]orge - Mods, no plugins\n"
"[P]aper - Spigot server but with faster performance\n"
"[S]pigot - Competitor to Bukkit, plugins\n"
"[B]ukkit - Plugins, most are compatible with Spigot\n"
"F[a]bric - Newer mod toolchain\n"
"Server type: ").lower().strip()
if not opts["auto"] and not opts["type"]:
opts["type"] = input("What type is this server?\n"
"Default is \"Vanilla\"\n"
"[V]anilla - Unmodified Mojang-provided server\n"
"[F]orge - Mods, no plugins\n"
"[P]aper - Spigot server but with faster performance\n"
"[S]pigot - Competitor to Bukkit, plugins\n"
"[B]ukkit - Plugins, most are compatible with Spigot\n"
"F[a]bric - Newer mod toolchain\n\n"
"Enter \"back\" to exit.\n"
"Server type: ").lower().strip()
if opts["type"] == "back":
exit()
if opts["type"] in ["v"] or not opts["type"]:
if not opts["type"]:
print("No input given, defaulting to \"Vanilla\"")
......@@ -124,25 +126,27 @@ def set_type(opts):
opts["type"] = "bukkit"
elif opts["type"] == "a":
opts["type"] = "fabric"
if opts["type"] == "forge":
if not opts["auto"]:
print("WARNING: "
"Automatically setting up Forge is strongly discouraged\n"
" by the Forge community and its developers.\n"
"You are responsible for any consequences this can bring.\n"
"(also, you might be pelted with eggs.)\n"
"Worst case scenario, Forge bans you import downloading "
"their stuff.\n"
"Are you *STILL* sure you knowingly want to set up Forge?\n\n"
"You will be able to answer in 3 seconds...")
time.sleep(3)
forge_warning = input("Set up Forge Anyway?\n[Y]es/[N]o: ").lower().strip()
if forge_warning in ["yes", "y"]:
opts["type"] = "forge"
else:
input("Aborting.\nPress enter to start over.")
opts["type"] = None
set_type(opts)
if opts["type"] == "forge" and not opts["auto"]:
print("\nWARNING: "
"Automatically setting up Forge is strongly discouraged\n"
" by the Forge community and its developers.\n"
"You are responsible for any consequences this can bring.\n"
"(also, you might be pelted with eggs.)\n"
"Worst case scenario, Forge bans you from downloading their stuff.\n"
"Are you **STILL** sure you knowingly want to set up Forge?\n\n"
"You will be able to answer in 3 seconds...")
time.sleep(1)
print("You will be able to answer in 2 seconds...")
time.sleep(2)
print("You will be able to answer in 1 second...")
time.sleep(1)
forge_warning = input("Set up Forge Anyway?\n[Y]es/[N]o: ").lower().strip()
if forge_warning in ["yes", "y"]:
opts["type"] = "forge"
else:
input("Aborting.\nPress enter to start over.")
opts["type"] = None
set_type(opts)
elif opts["type"] not in ["vanilla", "forge", "paper", "spigot", "bukkit", "fabric"]:
input(f"\"{opts['type'].capitalize()}\" is not a real server type listed.")
if opts["auto"]:
......@@ -161,8 +165,12 @@ def set_version(opts):
"Format your version as a full version, "
"like \"1.14.4\", \"20w08a\", or \"rd-132211\"\n"
f"Default is the latest version available for "
f"{opts['type'].capitalize()}.\n"
f"{opts['type'].capitalize()}.\n\n"
"Enter \"back\" to go to previous step.\n"
"Version/[L]atest: ").strip()
if opts["version"] == "back":
opts["version"], opts["type"] = None, None
set_type(opts)
if opts["version"].lower() == "l" or not opts["version"]:
if not opts["version"]:
print("No input given, defaulting to \"Latest\".")
......@@ -195,6 +203,7 @@ def vers_vanilla(opts):
if opts["version"] == version["id"]:
opts["jar"] = \
str(json.load(download(url=version["url"]))["downloads"]["server"]["url"])
break
if not opts["jar"]:
if not opts["auto"]:
retry_vanilla = input(
......@@ -219,14 +228,15 @@ def vers_forge(opts):
vers_meta = json.load(download(url="https://files.minecraftforge.net"
"/maven/net/minecraftforge/forge"
"/promotions_slim.json"))
forge_latest, forge_recommended = None, None
try:
forge_latest = vers_meta["promos"][opts["version"] + "-latest"]
except (KeyError, IndexError):
forge_latest = None
pass
try:
forge_recommended = vers_meta["promos"][opts["version"] + "-recommended"]
except (KeyError, IndexError):
forge_recommended = None
pass
if forge_recommended is None and forge_latest is None:
input(f"\"{opts['version']}\" is not a valid server version of Forge.\n"
"Press enter to retry.")
......@@ -344,8 +354,12 @@ def set_location(opts):
opts["path"] = input("What is the location of the server going to be?\n"
"Default is \"~/Desktop/mcautoserver-"
f"(type)-(version)-(branch)-(build)/\n"
"Press enter or input \"default\" to use the default.\n"
"Press enter or input \"default\" to use the default.\n\n"
"Enter \"back\" to go to previous step.\n"
"Path: ")
if opts["path"] == "back":
opts["path"], opts["version"] = None, None
set_version(opts)
if opts["path"] == "default" or not opts["path"]:
if not opts["path"]:
print("No input given, using default.")
......@@ -449,8 +463,12 @@ def install(opts):
f" - Build: {str(opts['build']).capitalize()}\n"
f" - Jar URL: \"{str(opts['jar'])}\"\n"
f" - Filename: \"{str(opts['filename'])}\"\n\n\n"
"Proceed with installation?\n"
"Proceed with installation?\n\n"
"Enter \"back\" to go to previous step.\n"
"[Y]es/[N]o: ").lower().strip()
if server_config == "back":
opts["path"], server_config = None, None
set_location(opts)
if not server_config or server_config not in ["yes", "y", "no", "n"]:
input("No valid input given, you must give a choice.\nPress enter to retry.")
install(opts)
......@@ -556,7 +574,7 @@ def config_eula(opts):
def config_world(opts):
"""Configure world imports, from either file or an online URL"""
world_import = str(input("How do you want to import the world?\n"
"[U]RL - Web address"
"[U]RL - Web address\n"
"[F]ile - Archive/directory on your local storage\n"
"Method: ")).strip().lower()
if world_import in ["url", "u"]:
......@@ -570,6 +588,9 @@ def config_world(opts):
else:
with zipfile.ZipFile(download(url=world_import_uri)) as world_archive:
world_archive.extractall(pathlib.Path(opts["path"] / "world/"))
print("Imported from file successfully.")
if not opts["auto"]:
input("Press enter to continue.")
elif world_import in ["file", "f"]:
world_import_uri = pathlib.Path(input(
"Format the file path as the full path, including the drive "
......@@ -591,6 +612,9 @@ def config_world(opts):
else:
input("Your input was neither a directory nor a valid archive file.\n"
"Press enter to retry.")
print("Imported from URI successfully.")
if not opts["auto"]:
input("Press enter to continue.")
else:
input("No valid input given, returning to menu.\nPress enter to continue.")
......@@ -864,7 +888,7 @@ PARSER.add_argument(
"-v",
"--version",
action="version",
version="0.13"
version="McAutoServer v0.14, by WhoAteMyButter"
)
PARSER.add_argument(
"-d",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment