ARRChecker 1.1.0

Now exposes a list of ARR mods through in case other devs want to add
this as a dependency. Also prints that list in the console.
pull/1/head
Caroline Bell 2020-04-12 01:59:52 -07:00
parent 6426de1b76
commit fc630971b7
2 changed files with 29 additions and 10 deletions

View File

@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.8.2 loader_version=0.8.2
# Mod Properties # Mod Properties
mod_version = 1.0.0 mod_version = 1.1.0
maven_group = com.halotroop maven_group = com.halotroop
archives_base_name = arrchecker archives_base_name = arrchecker

View File

@ -1,5 +1,8 @@
package com.halotroop.arrchecker; package com.halotroop.arrchecker;
import java.util.ArrayList;
import java.util.List;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.ModContainer;
@ -7,14 +10,16 @@ import net.fabricmc.loader.api.metadata.ModMetadata;
public class ARRChecker implements ModInitializer public class ARRChecker implements ModInitializer
{ {
private static List<String> arrMods = new ArrayList<String>();
@Override @Override
public void onInitialize() public void onInitialize()
{ {
Boolean invalidLicenseFound = false; arrMods.clear();
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) for (ModContainer mod : FabricLoader.getInstance().getAllMods())
{ {
ModMetadata modMeta = mod.getMetadata(); ModMetadata modMeta = mod.getMetadata();
// Assume all authors don't know how capitalization works // Assume all authors don't know how capitalization works, and don't use an array for the string!
String modLicense = modMeta.getLicense().toString().toLowerCase().replace('[', ' ').replace(']', ' ').strip(); String modLicense = modMeta.getLicense().toString().toLowerCase().replace('[', ' ').replace(']', ' ').strip();
// Create a constant of the mod name and ID to be used multiple times: Don't use an array for the string! // Create a constant of the mod name and ID to be used multiple times: Don't use an array for the string!
String modNameAndID = (modMeta.getName() + " (" + modMeta.getId() + ")").replace('[', ' ').replace(']', ' ').strip(); String modNameAndID = (modMeta.getName() + " (" + modMeta.getId() + ")").replace('[', ' ').replace(']', ' ').strip();
@ -25,13 +30,13 @@ public class ARRChecker implements ModInitializer
{ {
// If no license is found, assume mod is not correctly licensed, and therefore, not modpack-friendly. // If no license is found, assume mod is not correctly licensed, and therefore, not modpack-friendly.
System.out.println(modNameAndID + " has no license! It may be ARR!"); System.out.println(modNameAndID + " has no license! It may be ARR!");
invalidLicenseFound = true; arrMods.add(modMeta.getId());
} }
else if (modLicense == "all rights reserved" || modLicense == "arr" || modLicense.contains("copyright")) else if (modLicense == "all rights reserved" || modLicense == "arr" || modLicense.contains("copyright"))
{ {
// If license is All Rights Reserved, or copyright is attributed, assume mod is not modpack-friendly. // If license is All Rights Reserved, or copyright is attributed, assume mod is not modpack-friendly.
System.out.println(modNameAndID + " is ARR. Do not use it( in a modpack)!"); System.out.println(modNameAndID + " is ARR. Do not use it( in a modpack)!");
invalidLicenseFound = true; arrMods.add(modMeta.getId());
} }
else else
{ {
@ -50,14 +55,28 @@ public class ARRChecker implements ModInitializer
{ {
// If a valid license is not found, print crayon warning. // If a valid license is not found, print crayon warning.
System.out.println(modNameAndID + " may have a crayon license! It is: " + modLicense); System.out.println(modNameAndID + " may have a crayon license! It is: " + modLicense);
}
// If a valid license is not found, assume mod is not modpack-friendly. // If a valid license is not found, assume mod is not modpack-friendly.
invalidLicenseFound = modLicenseInvalid; arrMods.add(modMeta.getId());
} }
} }
else System.out.println("Minecraft isn't a mod, but in case you didn't know, it's ARR!\n"
+ "Don't distribute it!");
}
if (invalidLicenseFound) System.err.println("This/these mod(s) may not be suitable for a modpack!");
} }
} }
if (!arrMods.isEmpty())
{
String invalidMods = "";
for (String mod : arrMods)
{
invalidMods = invalidMods
+ (invalidMods.isBlank() ? mod
: arrMods.get(arrMods.size() - 1).equals(mod) ? (" and " + mod)
: (", " + mod));
}
if (!invalidMods.isBlank()) System.out.println(arrMods.size() == 1 ?
"This mod" : "These mods" + " may not be suitable for a modpack:\n" + invalidMods);
}
System.out.println("Minecraft isn't a mod, but in case you didn't know, it's ARR!\n" + "Don't distribute it!");
}
public static List<String> getARRMods()
{ return arrMods; }
}