From fc630971b7d04866426e1ccd694380b516c049d8 Mon Sep 17 00:00:00 2001 From: halotroop2288 Date: Sun, 12 Apr 2020 01:59:52 -0700 Subject: [PATCH] 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. --- gradle.properties | 2 +- .../com/halotroop/arrchecker/ARRChecker.java | 37 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2dc1165..b709f25 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.8.2 # Mod Properties - mod_version = 1.0.0 + mod_version = 1.1.0 maven_group = com.halotroop archives_base_name = arrchecker diff --git a/src/main/java/com/halotroop/arrchecker/ARRChecker.java b/src/main/java/com/halotroop/arrchecker/ARRChecker.java index 144f6ca..f0d89ac 100644 --- a/src/main/java/com/halotroop/arrchecker/ARRChecker.java +++ b/src/main/java/com/halotroop/arrchecker/ARRChecker.java @@ -1,5 +1,8 @@ package com.halotroop.arrchecker; +import java.util.ArrayList; +import java.util.List; + import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; @@ -7,14 +10,16 @@ import net.fabricmc.loader.api.metadata.ModMetadata; public class ARRChecker implements ModInitializer { + private static List arrMods = new ArrayList(); + @Override public void onInitialize() { - Boolean invalidLicenseFound = false; + arrMods.clear(); for (ModContainer mod : FabricLoader.getInstance().getAllMods()) { 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(); // 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(); @@ -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. 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")) { // 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)!"); - invalidLicenseFound = true; + arrMods.add(modMeta.getId()); } else { @@ -50,14 +55,28 @@ public class ARRChecker implements ModInitializer { // If a valid license is not found, print crayon warning. 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. + arrMods.add(modMeta.getId()); } - // If a valid license is not found, assume mod is not modpack-friendly. - invalidLicenseFound = modLicenseInvalid; } } - 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 getARRMods() + { return arrMods; } }