Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.bitbucket.antflga.Fractal.modules;
- import org.bitbucket.antflga.Fractal.Wrapper;
- import org.bitbucket.antflga.Fractal.modules.classes.TestModule;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- //Created by Antflga on 7/2/2014 at 10:45 PM for Fractal
- @SuppressWarnings("unused")
- public class ModuleHandler {
- private static final ModuleHandler instance = new ModuleHandler();
- public ModuleHandler(){
- loadModules();
- setupModules();
- }
- public static ModuleHandler getInstance()
- {
- return instance;
- }
- public List<BaseModule> modules = new ArrayList<>();
- private List<? extends BaseModule> modules2 = new ArrayList<>();
- private void addModules(BaseModule... LeModules) {
- Collections.addAll(modules, LeModules);
- }
- public BaseModule getModByClassName(String name)
- {
- for (BaseModule mod : modules)
- {
- if (mod.getClass().getSimpleName().toLowerCase().trim()
- .equals(name.toLowerCase().trim()))
- {
- return mod;
- }
- }
- return null;
- }
- public BaseModule getModByName(String name)
- {
- for (BaseModule mod : modules)
- {
- if (mod.getName().trim().equalsIgnoreCase(name.trim())
- || mod.toString().trim().equalsIgnoreCase(name.trim()))
- {
- return mod;
- }
- }
- return null;
- }
- public BaseModule findMod(Class <? extends BaseModule > clazz)
- {
- for (BaseModule mod : modules)
- {
- if (mod.getClass() == clazz)
- {
- return mod;
- }
- }
- return null;
- }
- public BaseModule findMod(String name)
- {
- BaseModule mod = Wrapper.getInstance().getModInstance().getModByName(name);
- if (mod != null)
- {
- return mod;
- }
- mod = Wrapper.getInstance().getModInstance().getModByClassName(name);
- return mod;
- }
- /** public void getAnnotationData(){
- for(BaseModule m : modules) {
- if(m.getClass().isAnnotationPresent(Module.class)) {
- Module annotation = m.getClass().getDeclaredAnnotation(Module.class);
- m.name = annotation.moduleName();
- m.description = annotation.moduleDescription();
- m.key = annotation.key();
- m.moduleType = annotation.moduleType();
- m.isVisible = annotation.isVisible();
- } else {
- throw new RuntimeException(String.format("Module %s does not have the @Module annotation, pls fix kthnxyou", m.getClass().getSimpleName()));
- }
- }
- }**/
- private void loadModules() {
- modules.add(new TestModule());
- }
- @SuppressWarnings("unchecked")
- public void setupModules() {
- for(BaseModule m : modules) {
- if(m.getClass().isAnnotationPresent(Module.class)) {
- Module annotation = m.getClass().getDeclaredAnnotation(Module.class);
- m.name = annotation.moduleName();
- m.description = annotation.moduleDescription();
- m.key = annotation.key();
- m.moduleType = annotation.moduleType();
- m.isVisible = annotation.isVisible();
- } else {
- throw new RuntimeException(String.format("Module %s does not have the @Module annotation, pls fix kthnxyou", m.getClass().getSimpleName()));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement