private Mod loadCustomMod(URLClassLoader loader, String className) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { Class<?> cl = null; try { cl = loader.loadClass(className); } catch (NoClassDefFoundError e) { Logger.log(Logger.LOG_MOD, "WARNING: skipping %s: %s", className, e.toString()); } if (cl != null && !cl.isInterface() && Mod.class.isAssignableFrom(cl)) { int flags = cl.getModifiers(); if (!Modifier.isAbstract(flags) && Modifier.isPublic(flags)) { return newModInstance(cl.asSubclass(Mod.class)); } } return null; }
static Mod newModInstance(Class<? extends Mod> modClass) { Mod mod = null; try { mod = modClass .getConstructor(MinecraftVersion.class) .newInstance(MCPatcher.minecraft.getVersion()); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { try { mod = modClass.newInstance(); } catch (Exception e1) { e1.printStackTrace(); } } return mod; }