Skip to content

Commit

Permalink
Add javadocs (CAD get better at reading code)
Browse files Browse the repository at this point in the history
  • Loading branch information
The Judge committed Apr 12, 2024
1 parent 7b5ae4d commit 16090a8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
70 changes: 63 additions & 7 deletions src/main/java/pojlib/api/API_V1.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand All @@ -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
Expand All @@ -115,20 +158,33 @@ 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);
}

/**
* 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);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/pojlib/instance/InstanceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pojlib/instance/MinecraftInstances.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 16090a8

Please sign in to comment.