Java module library is a lightweight library that allows for a modular extensive design
The api is a class used by both the main application and modules (plugins). This class should have direct or indirect access to anything you want to be accessible in the external modules.
An example on how to create a bridge to the loader:
package com.mylo.usedlibrary;
import com.mylo.modlib.loader.SimpleLoader;
import java.util.List;
/*
A really basic mod loader
*/
public class LoadMods {
public static List<CustomMod> loadMods(){
return new SimpleLoader<CustomMod>().loadModules().getLoadedMods();
}
}
An example mod base class:
package com.mylo.usedlibrary;
import com.mylo.modlib.modbase.Mod;
/*
a custom mod class using an interface,
so you could even have this extend a
class made by you.
*/
public abstract class CustomMod implements Mod {
public abstract String anotherString();
}
To make a custom loader you start by extending "com.mylo.modlib.loader.SimpleLoader". You could simply change modRoot (the mod folder to check) and modMainLink (the mod's .mod file by default).
Begin by importing the api you made at the previous steps.
Main class loading all modules and calling functions example:
package com.mylo.ModuleExample;
import com.mylo.usedlibrary.CustomMod;
import com.mylo.usedlibrary.LoadMods;
public class Main {
public static void main(String[] args){
System.out.println("Starting module load");
for (CustomMod mod: LoadMods.loadMods()){//from before, loadmods gives a list of CustomMod
System.out.println("Loaded Module: " + mod.getName());//mod.getName is built in, used for sorting on your end
System.out.println("Module's custom string: " + mod.anotherString());//mod.anotherString was added with the CustomMod
System.out.println("-----------------------------------------------------------");
}
System.out.println("Done");
}
}
All modules require the api you made at the previous steps
package com.mylo.exampleMod;
import com.mylo.modlib.modbase.ModMain;
import java.util.Arrays;
import java.util.List;
public class Main extends ModMain {
@Override
public List getModules() {
return Arrays.asList(new TestMod());
//this just instantiates the test mod created in the next step
}
}
package com.mylo.exampleMod;
import com.mylo.usedlibrary.CustomMod;
public class TestMod extends CustomMod {
@Override
public String getName() {//getName is from the base mod class
return "TestMod";
}
@Override
public String anotherString() {//anotherString is from CustomMod
return "Another String Lmao";
}
}
To then install the module, grab the compiled .class files, put them in a folder with a .mod file in the root with the path to the mod loader class. As would be in a meta-inf/manifest.mf file, but this isn't a jar, so you simply specify it in a .mod file. if you want a version that loads mods from a jar or a zip, you're free to make a fork.
Licensed under MIT License.