From 55d13e627630ee156d2437ca9f78307fbc376ef3 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Tue, 13 Feb 2024 18:36:31 +0100 Subject: [PATCH] Created the ServerVersionManager.java --- .../mcdash/api/ServerVersionManager.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/java/de/gnmyt/mcdash/api/ServerVersionManager.java diff --git a/src/main/java/de/gnmyt/mcdash/api/ServerVersionManager.java b/src/main/java/de/gnmyt/mcdash/api/ServerVersionManager.java new file mode 100644 index 0000000..31318ce --- /dev/null +++ b/src/main/java/de/gnmyt/mcdash/api/ServerVersionManager.java @@ -0,0 +1,54 @@ +package de.gnmyt.mcdash.api; + +import de.gnmyt.mcdash.MCDashWrapper; + +import java.io.File; + +public class ServerVersionManager { + + private static final Logger Logger = new Logger(ServerVersionManager.class); + private final File versionFolder; + + /** + * Creates a new ServerVersionManager. + *

+ * This will create the version folder if it doesn't exist + *

+ */ + public ServerVersionManager() { + versionFolder = MCDashWrapper.getDataSource("versions"); + + if (!versionFolder.exists() && !versionFolder.mkdirs()) { + Logger.error("An error occurred while creating the version folder"); + } + } + + /** + * Installs a specific version of the minecraft server software + * + * @param software the software + * @param version the version + */ + public void installVersion(String software, String version) { + // TODO: Implement this method + } + + /** + * Gets the path of a specific version of a software + * + * @param software the software + * @param version the version + * @return the path of the version + */ + public String getPath(String software, String version) { + File file = new File(versionFolder, software + "-" + version + ".jar"); + + if (!file.exists()) { + installVersion(software, version); + return getPath(software, version); + } + + return file.getAbsolutePath(); + } + +}