Support for jar mods on desktop
This commit is contained in:
@@ -15,6 +15,11 @@ public class Mod{
|
||||
|
||||
}
|
||||
|
||||
/** Called on clientside mods. Load content here. */
|
||||
public void loadContent(){
|
||||
|
||||
}
|
||||
|
||||
/** Register any commands to be used on the server side, e.g. from the console. */
|
||||
public void registerServerCommands(CommandHandler handler){
|
||||
|
||||
|
||||
@@ -460,6 +460,17 @@ public class Mods implements Loadable{
|
||||
/** Creates all the content found in mod files. */
|
||||
public void loadContent(){
|
||||
|
||||
//load class mod content first
|
||||
for(LoadedMod mod : orderedMods()){
|
||||
//hidden mods can't load content
|
||||
if(mod.main != null && !mod.meta.hidden){
|
||||
content.setCurrentMod(mod);
|
||||
mod.main.loadContent();
|
||||
}
|
||||
}
|
||||
|
||||
content.setCurrentMod(null);
|
||||
|
||||
class LoadRun implements Comparable<LoadRun>{
|
||||
final ContentType type;
|
||||
final Fi file;
|
||||
@@ -583,7 +594,7 @@ public class Mods implements Loadable{
|
||||
Fi metaf = zip.child("mod.json").exists() ? zip.child("mod.json") : zip.child("mod.hjson").exists() ? zip.child("mod.hjson") : zip.child("plugin.json");
|
||||
if(!metaf.exists()){
|
||||
Log.warn("Mod @ doesn't have a 'mod.json'/'mod.hjson'/'plugin.json' file, skipping.", sourceFile);
|
||||
throw new IllegalArgumentException("No mod.json found.");
|
||||
throw new IllegalArgumentException("Invalid file: No mod.json found.");
|
||||
}
|
||||
|
||||
ModMeta meta = json.fromJson(ModMeta.class, Jval.read(metaf.readString()).toString(Jformat.plain));
|
||||
@@ -607,9 +618,9 @@ public class Mods implements Loadable{
|
||||
|
||||
//make sure the main class exists before loading it; if it doesn't just don't put it there
|
||||
if(mainFile.exists()){
|
||||
//other platforms don't have standard java class loaders
|
||||
if(!headless && Version.build != -1){
|
||||
throw new IllegalArgumentException("Java class mods are currently unsupported outside of custom builds.");
|
||||
//mobile versions don't support class mods
|
||||
if(mobile){
|
||||
throw new IllegalArgumentException("Java class mods are not supported on mobile.");
|
||||
}
|
||||
|
||||
URLClassLoader classLoader = new URLClassLoader(new URL[]{sourceFile.file().toURI().toURL()}, ClassLoader.getSystemClassLoader());
|
||||
|
||||
Reference in New Issue
Block a user