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();
{ // Assume all authors don't know how capitalization works, and don't use an array for the string!
ModMetadata modMeta = mod.getMetadata(); String modLicense = modMeta.getLicense().toString().toLowerCase().replace('[', ' ').replace(']', ' ').trim();
// Assume all authors don't know how capitalization works, and 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 modLicense = modMeta.getLicense().toString().toLowerCase().replace('[', ' ').replace(']', ' ').trim(); String modNameAndID = (modMeta.getName() + " (" + modMeta.getId() + ")").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! // Give a different warning for Minecraft itself.
String modNameAndID = (modMeta.getName() + " (" + modMeta.getId() + ")").replace('[', ' ').replace(']', ' ').trim(); if (!modMeta.getId().equals("minecraft") && !modMeta.getId().equals("java")) {
// Give a different warning for Minecraft itself. if (modLicense.isEmpty()) {
if (modMeta.getId() != "minecraft") // If no license is found, assume mod is not correctly licensed, and therefore, not modpack-friendly.
{ LOGGER.warn(modNameAndID + " has no license! It may be ARR!");
if (modLicense == null || modLicense.isEmpty() || modLicense.isEmpty()) arrMods.add(modMeta.getId());
{ } else if (modLicense.equals("all rights reserved") || modLicense.equals("arr") || modLicense.contains("copyright")) {
// If no license is found, assume mod is not correctly licensed, and therefore, not modpack-friendly. // If license is All Rights Reserved, or copyright is attributed, assume mod is not modpack-friendly.
System.out.println(modNameAndID + " has no license! It may be ARR!"); LOGGER.warn(modNameAndID + " is ARR. Do not use it in a modpack!");
arrMods.add(modMeta.getId()); arrMods.add(modMeta.getId());
} } else {
else if (modLicense == "all rights reserved" || modLicense == "arr" || modLicense.contains("copyright")) String[] validLicenses =
{ {
// If license is All Rights Reserved, or copyright is attributed, assume mod is not modpack-friendly. "gpl", "mit", "cc0", "apache", "unlicense", "mpl", // Short form names
System.out.println(modNameAndID + " is ARR. Do not use it( in a modpack)!"); "gnu public license", "mozilla public license", "creative commons" // Long form (incorrect, but check anyway)
arrMods.add(modMeta.getId()); };
} boolean modLicenseInvalid = true;
else for (String validLicense : validLicenses) {
{ // If a valid license is found, set invalid to false, and stop checking
String[] validLicenses = if (!(modLicenseInvalid = !modLicense.contains(validLicense))) break;
{ }
"gpl", "mit", "cc0", "apache", "unlicense", "mpl", // Short form names if (modLicenseInvalid) {
"gnu public license", "mozilla public license", "creative commons" // Long form (incorrect, but check anyway) // If a valid license is not found, print crayon warning.
}; LOGGER.warn(modNameAndID + " may have a crayon license! It is: " + modLicense);
Boolean modLicenseInvalid = true; // If a valid license is not found, assume mod is not modpack-friendly.
for (String validLicense : validLicenses) arrMods.add(modMeta.getId());
{ }
// If a valid license is found, set invalid to false, and stop checking }
if (!(modLicenseInvalid = !modLicense.contains(validLicense))) break; }
} }
if (modLicenseInvalid) if (!arrMods.isEmpty()) {
{ StringBuilder invalidMods = new StringBuilder();
// If a valid license is not found, print crayon warning. for (int i = 0, arrModsSize = arrMods.size(); i < arrModsSize; i++) {
System.out.println(modNameAndID + " may have a crayon license! It is: " + modLicense); String mod = arrMods.get(i);
// If a valid license is not found, assume mod is not modpack-friendly. if (invalidMods.length() > 0) {
arrMods.add(modMeta.getId()); boolean isLastElement = i == arrModsSize - 1;
} invalidMods.append(isLastElement ? " and " : ", ");
} }
} invalidMods.append(mod);
} }
if (!arrMods.isEmpty()) if (invalidMods.length() != 0) {
{ LOGGER.error(arrMods.size() == 1 ? "This mod" : "These mods" +
String invalidMods = ""; " may not be suitable for a modpack:\n" + invalidMods);
for (String mod : arrMods) }
{ }
invalidMods = invalidMods LOGGER.warn("Minecraft isn't a mod, but in case you didn't know, it's ARR!\nDon't distribute it!");
+ (invalidMods.isEmpty() ? mod }
: arrMods.get(arrMods.size() - 1).equals(mod) ? (" and " + mod)
: (", " + mod));
}
if (!invalidMods.isEmpty()) 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() 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": {