Fixed bugs.

This commit is contained in:
Harrison Deng 2021-04-01 20:43:29 -05:00
parent 9f7f7287d3
commit 053670ea0a

View File

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