I'm writing a custom loading system for my mod. The loading system will load classes from a zip that have a specified annotation, and then call a load method. The problem is java cannot find the method in the class that has it, in which I've done some searching, and found that you need an instance of the class to execute the method.
How can I get an instance of the class in the zip file in order to invoke the method?
This code is supposed to load and execute the method from within the development environment, but the actual loader does a similar thing. Upon load and discovery of the class, it throws a NoSuchMethodException, saying that it cannot find the method in java.lang.Class.
Class clazz = classLoader.loadClass("net.minecraft.src.MyClass");
if(clazz.isAnnotationPresent(MyAnnotation.class))
{
this.loadedPlugins.add(clazz);
b = false;
System.out.println(header + "Loaded Plugin with ID: " + ((MyAnnotation)clazz.getAnnotation(MyAnnotation.class)).pluginID());
System.out.println(header + "Class loading will be disabled in a future update!");
Method method = clazz.getDeclaredMethod("preLoad", PluginPreLoadEvent.class);
method.setAccessible(true);
method.invoke(clazz.getClass(), new PluginPreLoadEvent(Minecraft.getMinecraft(), MyClass.currentSide));
System.out.println(MyClass.header + "PreLoad initialized.");
}
How can I get an instance of the class in the zip file in order to invoke the method?
This code is supposed to load and execute the method from within the development environment, but the actual loader does a similar thing. Upon load and discovery of the class, it throws a NoSuchMethodException, saying that it cannot find the method in java.lang.Class.
Click Here to view my WIP Mod!
Currently developing a Tech/Space mod. PM if you can/want to help!