Use ModLoadException instead of IllegalArgumentException

This commit is contained in:
Anuken
2021-07-29 09:20:51 -04:00
parent dbebe2ab29
commit a36f872b61
+10 -4
View File
@@ -723,7 +723,7 @@ public class Mods implements Loadable{
if(!metaf.exists()){ if(!metaf.exists()){
Log.warn("Mod @ doesn't have a '[mod/plugin].[h]json' file, skipping.", sourceFile); Log.warn("Mod @ doesn't have a '[mod/plugin].[h]json' file, skipping.", sourceFile);
throw new IllegalArgumentException("Invalid file: No mod.json found."); throw new ModLoadException("Invalid file: No mod.json found.");
} }
ModMeta meta = json.fromJson(ModMeta.class, Jval.read(metaf.readString()).toString(Jformat.plain)); ModMeta meta = json.fromJson(ModMeta.class, Jval.read(metaf.readString()).toString(Jformat.plain));
@@ -750,7 +750,7 @@ public class Mods implements Loadable{
//unload //unload
mods.remove(other); mods.remove(other);
}else{ }else{
throw new IllegalArgumentException("A mod with the name '" + baseName + "' is already imported."); throw new ModLoadException("A mod with the name '" + baseName + "' is already imported.");
} }
} }
@@ -779,7 +779,7 @@ public class Mods implements Loadable{
(meta.getMinMajor() >= 105 || headless) (meta.getMinMajor() >= 105 || headless)
){ ){
if(ios){ if(ios){
throw new IllegalArgumentException("Java class mods are not supported on iOS."); throw new ModLoadException("Java class mods are not supported on iOS.");
} }
loader = platform.loadJar(sourceFile, mainLoader); loader = platform.loadJar(sourceFile, mainLoader);
@@ -789,7 +789,7 @@ public class Mods implements Loadable{
//detect mods that incorrectly package mindustry in the jar //detect mods that incorrectly package mindustry in the jar
if((main.getSuperclass().getName().equals("mindustry.mod.Plugin") || main.getSuperclass().getName().equals("mindustry.mod.Mod")) && if((main.getSuperclass().getName().equals("mindustry.mod.Plugin") || main.getSuperclass().getName().equals("mindustry.mod.Mod")) &&
main.getSuperclass().getClassLoader() != Mod.class.getClassLoader()){ main.getSuperclass().getClassLoader() != Mod.class.getClassLoader()){
throw new IllegalArgumentException( throw new ModLoadException(
"This mod/plugin has loaded Mindustry dependencies from its own class loader. " + "This mod/plugin has loaded Mindustry dependencies from its own class loader. " +
"You are incorrectly including Mindustry dependencies in the mod JAR - " + "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`!" "make sure Mindustry is declared as `compileOnly` in Gradle, and that the JAR is created with `runtimeClasspath`!"
@@ -1028,6 +1028,12 @@ public class Mods implements Loadable{
} }
} }
public static class ModLoadException extends RuntimeException{
public ModLoadException(String message){
super(message);
}
}
public enum ModState{ public enum ModState{
enabled, enabled,
contentErrors, contentErrors,