package emergencylanding.k.exst.modules;

import java.util.*;

import emergencylanding.k.exst.mods.IMod;
import emergencylanding.k.exst.mods.Mods;

public final class ModuleSystem {
    private static final Class<IModule> IMODULE_CLASS = IModule.class;

    private static ArrayList<IModule> modules = new ArrayList<IModule>();

    private ModuleSystem() {
        throw new AssertionError("Please don't create the module system.");
    }

    public static void loadModulesFromMods() {
        List<IMod> loaded = Mods.getLoadedMods();
        for (IMod m : loaded) {
            if (m instanceof IModule) {
                IModule im = (IModule) m;
                modules.add(im);
            }
        }
    }

    /**
     * Gets the registered modules for the given binary class name.
     * 
     * @param fullBinaryName
     *            - the full binary name for the parent class
     * @return an array of {@link IModule} instances whose getClass() method
     *         either returns the same class represented by the full binary name
     *         or a class that extends that class.
     */
    public static IModule[] getRegisteredModules(String fullBinaryName) {
        Class<?> fbnClass = null;
        try {
            fbnClass = Class.forName(fullBinaryName);
        } catch (ClassNotFoundException e1) {
            System.err.println("Module class " + fullBinaryName
                    + " does not exist, returning empty.");
        }
        if (!IMODULE_CLASS.isAssignableFrom(fbnClass)) {
            throw new ClassCastException(fullBinaryName + " does not extend "
                    + IMODULE_CLASS);
        }
        if (fbnClass == null) {
            return new IModule[0];
        }
        ArrayList<IModule> matched = new ArrayList<IModule>();
        for (IModule m : modules) {
            if (fbnClass.isInstance(m)) {
                matched.add(m);
            }
        }
        return matched.toArray(new IModule[0]);
    }
}

@@ -35,16 +35,48 @@
 dules;%0A%0A
+import java.lang.reflect.Array;%0A
 import j
@@ -1151,23 +1151,37 @@
  static 
+%3CT extends 
 IModule
+%3E T
 %5B%5D getRe
@@ -1200,304 +1200,83 @@
 les(
-String fullBinaryName) %7B%0A        Class%3C?%3E fbnClass = null;%0A        try %7B%0A            fbnClass = Class.forName(fullBinaryName);%0A        %7D catch (ClassNotFoundException e1) %7B%0A            System.err.println(%22Module class %22 + fullBinaryName%0A                    + %22 does not exist, returning empty.
+%0A            Class%3CT%3E moduleClass) %7B%0A        @SuppressWarnings(%22unchecked
 %22)
-;
 %0A   
@@ -1284,208 +1284,79 @@
     
-%7D%0A        if (!IMODULE_CLASS.isAssignableFrom(fbnClass)) %7B%0A            throw new ClassCastException(fullBinaryName + %22 does not extend %22%0A                    + IMODULE_CLASS);%0A        %7D%0A        if (fbn
+T%5B%5D array = (T%5B%5D) Array.newInstance(moduleClass, 0);%0A        if (module
 Clas
@@ -1387,30 +1387,21 @@
  return 
-new IModule%5B0%5D
+array
 ;%0A      
@@ -1523,11 +1523,14 @@
 if (
-fbn
+module
 Clas
@@ -1639,22 +1639,13 @@
 ray(
-new IModule%5B0%5D
+array
 );%0A 

Use module class instead of FBN