From 16090a8b60b775bcc25a63d86ae881e473e560f2 Mon Sep 17 00:00:00 2001 From: The Judge Date: Fri, 12 Apr 2024 11:23:09 -0700 Subject: [PATCH] Add javadocs (CAD get better at reading code) --- src/main/java/pojlib/api/API_V1.java | 70 +++++++++++++++++-- .../java/pojlib/instance/InstanceHandler.java | 4 ++ .../pojlib/instance/MinecraftInstances.java | 2 +- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/src/main/java/pojlib/api/API_V1.java b/src/main/java/pojlib/api/API_V1.java index 819e5927..869ca41a 100644 --- a/src/main/java/pojlib/api/API_V1.java +++ b/src/main/java/pojlib/api/API_V1.java @@ -49,21 +49,47 @@ public static MinecraftMeta.MinecraftVersion[] getMinecraftVersions() { return MinecraftMeta.getVersions(); } + /** + * Add a mod to an instance + * + * @param instances Acquired from {@link pojlib.api.API_V1#loadAll(String)} + * @param instance Acquired from {@link pojlib.api.API_V1#createNewInstance(Activity, String, String, boolean, MinecraftMeta.MinecraftVersion, InstanceHandler.ModLoader, String)} + * or {@link pojlib.api.API_V1#load(MinecraftInstances, String)} + * @param gameDir .minecraft directory + * @param name Mod name + * @param version Mod version + * @param url Mod download URL + */ public static void addMod(MinecraftInstances instances, MinecraftInstances.Instance instance, - String home, String name, String version, String url) { - InstanceHandler.addMod(instances, instance, home, name, version, url); + String gameDir, String name, String version, String url) { + InstanceHandler.addMod(instances, instance, gameDir, name, version, url); } + /** + * Check if an instance has a mod + * + * @param instance Acquired from {@link pojlib.api.API_V1#createNewInstance(Activity, String, String, boolean, MinecraftMeta.MinecraftVersion, InstanceHandler.ModLoader, String)} + * or {@link pojlib.api.API_V1#load(MinecraftInstances, String)} + * @param name Mod name + * @return True if the mod is already in the instance + */ public static boolean hasMod(MinecraftInstances.Instance instance, String name) { return InstanceHandler.hasMod(instance, name); } /** - * @return if the operation succeeds + * Remove a mod from an instance + * + * @param instances Acquired from {@link pojlib.api.API_V1#loadAll(String)} + * @param instance Acquired from {@link pojlib.api.API_V1#createNewInstance(Activity, String, String, boolean, MinecraftMeta.MinecraftVersion, InstanceHandler.ModLoader, String)} + * or {@link pojlib.api.API_V1#load(MinecraftInstances, String)} + * @param gameDir .minecraft directory + * @param name Mod name + * @return True if the mod was deleted */ public static boolean removeMod(MinecraftInstances instances, MinecraftInstances.Instance instance, - String home, String name) { - return InstanceHandler.removeMod(instances, instance, home, name); + String gameDir, String name) { + return InstanceHandler.removeMod(instances, instance, gameDir, name); } public static MinecraftMeta.MinecraftVersion[] getQCSupportedVersions() throws IOException { @@ -84,10 +110,26 @@ public static MinecraftInstances loadAll(String gameDir) { return InstanceHandler.load(gameDir); } + /** + * Load a specific instance by name + * + * @param instances Acquired from {@link pojlib.api.API_V1#loadAll(String)} + * @param name Name of the instance + * @return The instance, or null if an instance with name does not exist + */ public static MinecraftInstances.Instance load(MinecraftInstances instances, String name) { return instances.load(name); } + /** + * Delete an instance + * NOTE: Only deletes the instance, not the correlated mods for said instance + * + * @param instances Acquired from {@link pojlib.api.API_V1#loadAll(String)} + * @param instance Instance object + * @param gameDir .minecraft directory. + * @return True if it deletes successfully, false otherwise. + */ public static boolean deleteInstance(MinecraftInstances instances, MinecraftInstances.Instance instance, String gameDir) { return InstanceHandler.delete(instances, instance, gameDir); } @@ -98,6 +140,7 @@ public static boolean deleteInstance(MinecraftInstances instances, MinecraftInst * @param activity The active android activity * @param instanceName The name of the instance being created - can be anything, used for identification * @param home The base directory where minecraft should be setup + * @param useDefaultMods Use QC's default mods for the version (Core mods are automatically included) * @param minecraftVersion The version of minecraft to install * @param modLoader The mod loader to install * @return A minecraft instance object @@ -115,6 +158,14 @@ public static MinecraftInstances.Instance createNewInstance(Activity activity, S } } + /** + * Launch an instance + * + * @param activity Android activity object + * @param account Account object + * @param instance Instance object from {@link pojlib.api.API_V1#createNewInstance(Activity, String, String, boolean, MinecraftMeta.MinecraftVersion, InstanceHandler.ModLoader, String)} + * or {@link pojlib.api.API_V1#load(MinecraftInstances, String)} + */ public static void launchInstance(Activity activity, MinecraftAccount account, MinecraftInstances.Instance instance) { InstanceHandler.launchInstance(activity, account, instance); } @@ -122,13 +173,18 @@ public static void launchInstance(Activity activity, MinecraftAccount account, M /** * Logs the user out * - * @param activity The base directory where minecraft should be setup - * @return True if logout was successful + * @param activity The base directory where minecraft should be setup + * @return True if logout was successful */ public static boolean logout(Activity activity) { return MinecraftAccount.logout(activity); } + /** + * Start the login process + * + * @param activity Android activity object + */ public static void login(Activity activity) { ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); diff --git a/src/main/java/pojlib/instance/InstanceHandler.java b/src/main/java/pojlib/instance/InstanceHandler.java index 68c6911e..7ad03c2f 100644 --- a/src/main/java/pojlib/instance/InstanceHandler.java +++ b/src/main/java/pojlib/instance/InstanceHandler.java @@ -156,6 +156,10 @@ public static boolean removeMod(MinecraftInstances instances, MinecraftInstances } if(oldInfo != null) { + // Delete the mod + File modFile = new File(gameDir + "/mods/" + instance.modsDirName + "/" + name + ".jar"); + modFile.delete(); + instance.mods.remove(oldInfo); GsonUtils.objectToJsonFile(gameDir + "/instances.json", instances); } diff --git a/src/main/java/pojlib/instance/MinecraftInstances.java b/src/main/java/pojlib/instance/MinecraftInstances.java index 95572396..b5db3b2b 100644 --- a/src/main/java/pojlib/instance/MinecraftInstances.java +++ b/src/main/java/pojlib/instance/MinecraftInstances.java @@ -100,7 +100,7 @@ public void updateMods(String gameDir) { continue; } - File mod = new File(gameDir + "/mods/" + modsDirName + "/" + info.name); + File mod = new File(gameDir + "/mods/" + modsDirName + "/" + info.name + ".jar"); DownloadUtils.downloadFile(info.url, mod); } }