Log incompatible mod class loaders

This commit is contained in:
Anuken 2021-07-29 09:16:53 -04:00
parent 4734261097
commit ccb973d1dd

View File

@ -785,6 +785,17 @@ public class Mods implements Loadable{
loader = platform.loadJar(sourceFile, mainLoader);
mainLoader.addChild(loader);
Class<?> main = Class.forName(mainClass, true, loader);
//detect mods that incorrectly package mindustry in the jar
if((main.getSuperclass().getName().equals("mindustry.mod.Plugin") || main.getSuperclass().getName().equals("mindustry.mod.Mod")) &&
main.getSuperclass().getClassLoader() != Mod.class.getClassLoader()){
throw new IllegalArgumentException(
"This mod/plugin has loaded Mindustry dependencies from its own class loader. " +
"You are incorrectly including Mindustry dependencies in the mod JAR - " +
"make sure Mindustry is declared as `compileOnly` in Gradle, and that the JAR is created with `runtimeClasspath`!"
);
}
metas.put(main, meta);
mainMod = (Mod)main.getDeclaredConstructor().newInstance();
}else{