diff --git a/scripts/gen.py b/scripts/gen.py index 5a34e22..383676a 100644 --- a/scripts/gen.py +++ b/scripts/gen.py @@ -4,7 +4,7 @@ import xml.etree.ElementTree as ET import requests import shutil -DEFAULT_BUKKIT_VER = "LATEST" +DEFAULT_SPIGOT_VER = "LATEST" POM_NAMESPACE = "http://maven.apache.org/POM/4.0.0" DEV_SERVER_PATH="development_server/" MVN_CMD = "mvn -B archetype:generate -DgroupId={groupId} -DartifactId={artifactId} -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4"; @@ -43,18 +43,18 @@ def project_gen() -> int: return 1 print("Step 2) Modify pom.xml") - bukkitver = input("bukkit dependency version (default: \"{0}\"): ".format(DEFAULT_BUKKIT_VER)) - if (len(bukkitver) == 0): bukkitver = DEFAULT_BUKKIT_VER + spigotver = input("Spigot dependency version (default: \"{0}\"): ".format(DEFAULT_SPIGOT_VER)) + if (len(spigotver) == 0): spigotver = DEFAULT_SPIGOT_VER - bukkitvercheck = input("Entered \"{0}\". Is this fine? (Y/n)".format(bukkitver)) - if (len(bukkitvercheck) == 0): bukkitvercheck = "y" - while (bukkitvercheck.lower() != "y"): - if bukkitvercheck.lower() == "n": - bukkitver = input("bukkit dependency version (Maven Dep. Ver.): ") - bukkitvercheck = input("Entered \"{0}\". Is this fine? (Y/n)".format(bukkitver)) + spigotvercheck = input("Using \"{0}\". Is this fine? (Y/n)".format(spigotver)) + if (len(spigotvercheck) == 0): spigotvercheck = "y" + while (spigotvercheck.lower() != "y"): + if spigotvercheck.lower() == "n": + spigotver = input("Spigot dependency version (Maven Dep. Ver.): ") + spigotvercheck = input("Entered \"{0}\". Is this fine? (Y/n)".format(spigotver)) else: - bukkitvercheck = input("Please enter \"y\" to continue, or \"n\" to enter version again: ") - print("Using version: \"{0}\"".format(bukkitver)) + spigotvercheck = input("Please enter \"y\" to continue, or \"n\" to enter version again: ") + print("Using version: \"{0}\"".format(spigotver)) pompath = "{0}/pom.xml".format(artifactId); ET.register_namespace("", POM_NAMESPACE) @@ -68,15 +68,15 @@ def project_gen() -> int: pomroot.append(repositorieselem) - bukkitdep = ET.Element("dependency") - ET.SubElement(bukkitdep, "groupId").text = "org.bukkit" - ET.SubElement(bukkitdep, "artifactId").text = "bukkit" - ET.SubElement(bukkitdep, "version").text = bukkitver - ET.SubElement(bukkitdep, "type").text = "jar" - ET.SubElement(bukkitdep, "scope").text = "provided" + spigotdep = ET.Element("dependency") + ET.SubElement(spigotdep, "groupId").text = "org.spigotmc" + ET.SubElement(spigotdep, "artifactId").text = "spigot-api" + ET.SubElement(spigotdep, "version").text = spigotver + ET.SubElement(spigotdep, "type").text = "jar" + ET.SubElement(spigotdep, "scope").text = "provided" dependencies = pomroot.find("{" + POM_NAMESPACE + "}" + "dependencies") - dependencies.append(bukkitdep) + dependencies.append(spigotdep) pomxml.write(pompath) @@ -110,31 +110,31 @@ def gen_dev_server() -> int: print("Step 2) Generate server JAR with BuildTools.jar") - bukkitver = input("Bukkit version to use (default: \"{0}\"): ".format(DEFAULT_SERVER_VER)) - if (len(bukkitver) == 0): bukkitver = DEFAULT_SERVER_VER - bukkitververify = input("Attempt to use \"{0}\"? (Y/n)".format(bukkitver)) - if (len(bukkitververify) == 0): bukkitververify = "y" - while bukkitververify.lower() != "y": - if (bukkitververify.lower() == "n"): - bukkitver = input("Bukkit version to use: ") - bukkitververify = input("Attempt to use \"{0}\"? (Y/n)".format(bukkitver)) + spigotver = input("Spigot version to use (buildtools rev.) (default: \"{0}\"): ".format(DEFAULT_SERVER_VER)) + if (len(spigotver) == 0): spigotver = DEFAULT_SERVER_VER + spigotververify = input("Attempt to use \"{0}\"? (Y/n)".format(spigotver)) + if (len(spigotververify) == 0): spigotververify = "y" + while spigotververify.lower() != "y": + if (spigotververify.lower() == "n"): + spigotver = input("Spigot version to use: ") + spigotververify = input("Attempt to use \"{0}\"? (Y/n)".format(spigotver)) else: - bukkitververify = input("Attempt to use \"{0}\"? Please enter \"y\" or \"n\": ".format(bukkitver)) + spigotververify = input("Attempt to use \"{0}\"? Please enter \"y\" or \"n\": ".format(spigotver)) - if os.system(BUILDTOOLS_CMD.format(ver = bukkitver)) != 0: + if os.system(BUILDTOOLS_CMD.format(ver = spigotver)) != 0: print("Error while running build tools.") return 1 print("Step 3) Moving JARs and cleaning up.") print("Moving generated JAR file.") - if bukkitver == DEFAULT_SERVER_VER: + if spigotver == DEFAULT_SERVER_VER: direntries = os.listdir() for entry in direntries: if (entry.startswith("spigot") and entry.endswith(".jar")): shutil.move(entry, "../spigot.jar") else: - shutil.move("spigot-{1}.jar".format(bukkitver), "../spigot.jar") + shutil.move("spigot-{0}.jar".format(spigotver), "../spigot.jar") os.chdir("../") print("Deleting \"{0}\".".format(BUILDTOOLS_DIR)) @@ -146,7 +146,7 @@ def gen_dev_server() -> int: def reset() -> None: pomxmldir = find_pomxmldir() - if os.path.exists(pomxmldir): + if len(pomxmldir) != 0: shutil.rmtree(pomxmldir) print("Deleted Maven project directory.") @@ -163,10 +163,14 @@ def find_pomxmldir() -> str: for directory in directories: if os.path.isdir(directory) and "pom.xml" in os.listdir(directory): return directory + return "" + +def __printhelp(): + print("usage: {0} ".format(sys.argv[0])) if __name__ == "__main__": if len(sys.argv) != 2: - print("usage: {0} ".format(sys.argv[0])) + __printhelp() exit(1) else: if sys.argv[1] == "setup": @@ -177,4 +181,7 @@ if __name__ == "__main__": elif sys.argv[1] == "server": if gen_dev_server() != 0: exit(1) elif sys.argv[1] == "reset": - reset() \ No newline at end of file + reset() + else: + __printhelp() + exit(1) \ No newline at end of file