Clean Up Code

master
macbrayne 2021-09-11 00:53:17 +02:00 committed by GitHub
parent cbb521b835
commit 29062719d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 95 deletions

View File

@ -16,9 +16,6 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}+build.+:v2" mappings "net.fabricmc:yarn:${project.yarn_mappings}+build.+:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}+build.+" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}+build.+"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them. // You may need to force-disable transitiveness on them.
} }

View File

@ -8,10 +8,6 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.8.2 loader_version=0.8.2
# Mod Properties # Mod Properties
mod_version = 1.1.1 mod_version = 1.2
maven_group = com.halotroop maven_group = com.halotroop
archives_base_name = arrchecker archives_base_name = arrchecker
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.5.1+build.294-1.15

View File

@ -7,76 +7,71 @@ 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;
import net.fabricmc.loader.api.metadata.ModMetadata; import net.fabricmc.loader.api.metadata.ModMetadata;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ARRChecker implements ModInitializer public class ARRChecker implements ModInitializer {
{ private static final List<String> arrMods = new ArrayList<>();
private static List<String> arrMods = new ArrayList<String>(); private static final Logger LOGGER = LogManager.getLogger("arrchecker");
@Override @Override
public void onInitialize() public void onInitialize() {
{
arrMods.clear(); 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, and don't use an array for the string! // 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(']', ' ').trim(); String modLicense = modMeta.getLicense().toString().toLowerCase().replace('[', ' ').replace(']', ' ').trim();
// 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(']', ' ').trim(); String modNameAndID = (modMeta.getName() + " (" + modMeta.getId() + ")").replace('[', ' ').replace(']', ' ').trim();
// Give a different warning for Minecraft itself. // Give a different warning for Minecraft itself.
if (modMeta.getId() != "minecraft") if (!modMeta.getId().equals("minecraft") && !modMeta.getId().equals("java")) {
{ if (modLicense.isEmpty()) {
if (modLicense == null || modLicense.isEmpty() || modLicense.isEmpty())
{
// 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!"); LOGGER.warn(modNameAndID + " has no license! It may be ARR!");
arrMods.add(modMeta.getId()); arrMods.add(modMeta.getId());
} } else if (modLicense.equals("all rights reserved") || modLicense.equals("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)!"); LOGGER.warn(modNameAndID + " is ARR. Do not use it in a modpack!");
arrMods.add(modMeta.getId()); arrMods.add(modMeta.getId());
} } else {
else
{
String[] validLicenses = String[] validLicenses =
{ {
"gpl", "mit", "cc0", "apache", "unlicense", "mpl", // Short form names "gpl", "mit", "cc0", "apache", "unlicense", "mpl", // Short form names
"gnu public license", "mozilla public license", "creative commons" // Long form (incorrect, but check anyway) "gnu public license", "mozilla public license", "creative commons" // Long form (incorrect, but check anyway)
}; };
Boolean modLicenseInvalid = true; boolean modLicenseInvalid = true;
for (String validLicense : validLicenses) for (String validLicense : validLicenses) {
{
// If a valid license is found, set invalid to false, and stop checking // If a valid license is found, set invalid to false, and stop checking
if (!(modLicenseInvalid = !modLicense.contains(validLicense))) break; if (!(modLicenseInvalid = !modLicense.contains(validLicense))) break;
} }
if (modLicenseInvalid) if (modLicenseInvalid) {
{
// 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); LOGGER.warn(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.
arrMods.add(modMeta.getId()); arrMods.add(modMeta.getId());
} }
} }
} }
} }
if (!arrMods.isEmpty()) if (!arrMods.isEmpty()) {
{ StringBuilder invalidMods = new StringBuilder();
String invalidMods = ""; for (int i = 0, arrModsSize = arrMods.size(); i < arrModsSize; i++) {
for (String mod : arrMods) String mod = arrMods.get(i);
{ if (invalidMods.length() > 0) {
invalidMods = invalidMods boolean isLastElement = i == arrModsSize - 1;
+ (invalidMods.isEmpty() ? mod invalidMods.append(isLastElement ? " and " : ", ");
: arrMods.get(arrMods.size() - 1).equals(mod) ? (" and " + mod)
: (", " + mod));
} }
if (!invalidMods.isEmpty()) System.out.println(arrMods.size() == 1 ? invalidMods.append(mod);
"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!"); if (invalidMods.length() != 0) {
LOGGER.error(arrMods.size() == 1 ? "This mod" : "These mods" +
" may not be suitable for a modpack:\n" + invalidMods);
}
}
LOGGER.warn("Minecraft isn't a mod, but in case you didn't know, it's ARR!\nDon't distribute it!");
} }
public static List<String> getARRMods() public static List<String> getARRMods() {
{ return arrMods; } return arrMods;
}
} }

View File

@ -1,13 +0,0 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.fabricmc.example.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
],
"injectors": {
"defaultRequire": 1
}
}

View File

@ -23,13 +23,9 @@
"com.halotroop.arrchecker.ARRChecker" "com.halotroop.arrchecker.ARRChecker"
] ]
}, },
"mixins": [
"arrchecker.mixins.json"
],
"depends": { "depends": {
"fabricloader": ">=0.7.4", "fabricloader": ">=0.7.4",
"fabric": "*",
"minecraft": "*" "minecraft": "*"
}, },
"suggests": { "suggests": {