lyonlancer5.xatrocore.utils.XatroLoader.java Source code

Java tutorial

Introduction

Here is the source code for lyonlancer5.xatrocore.utils.XatroLoader.java

Source

/* Copyright (c) 2015 Lance Selga <lyonecro55@gmail.com>
 * 
 * This work is free. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See the COPYING file for more details.
 */
package lyonlancer5.xatrocore.utils;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;

import lyonlancer5.xatrocore.lib.LL5Mod.MLMod;
import lyonlancer5.xatrocore.logging.Logger;

import com.google.common.collect.Maps;

/**
 * @deprecated Work in progress and may be scheduled for removal
 * @version 1.0 beta {@literal <Modification 25>} - Released November 2015
 * @author Lyonlancer5
 */
public class XatroLoader {
    private static final Logger modLoader = Logger.getLogger("XC's Loader");

    /**Loads a given ModLoader-rewritten mod using the given class path
     * @deprecated Not yet implemented
     * @param className the full class name that loads the mod
     * @return True if it found the class and will start loading the mod, false otherwise*/
    public static boolean loadModLoaderMod(String className) {
        if (className.contains("mod_")) {
            try {

                @SuppressWarnings("unchecked")
                Class<? extends MLMod> clazz = (Class<? extends MLMod>) Class.forName(className);
                MLMod theMod = clazz.getConstructor().newInstance();

                HashMap<String, Object> map = Maps.newHashMap();
                map.put("modid", theMod.getModID());
                map.put("name", theMod.getName());
                map.put("version", theMod.getVersion());

                //FMLModContainer container = new FMLModContainer("lyonlancer5.xatrocore.lib.XatroMod", new ModCandidate(file, file, file.isDirectory() ? ContainerType.DIR : ContainerType.JAR), map);
                //container.bindMetadata(MetadataCollection.from(null, ""));
                //FMLClientHandler.instance().addModAsResource(container);

                //theMod.load();

            } catch (ClassNotFoundException e) {
                modLoader.error("No class found with name %s", className);
                return false;
            } catch (IllegalAccessException e) {
                modLoader.error("Unable to access class %s", className);
                return false;
            } catch (IllegalArgumentException e) {
                modLoader.error("Invalid parameter given to class %s", className);
                return false;
            } catch (InvocationTargetException e) {
                modLoader.error("Load method error on class %s", className);
                return false;
            } catch (NoSuchMethodException e) {
                modLoader.error("No load method found on class %s", className);
                return false;
            } catch (SecurityException e) {
                modLoader.error("Security error on class %s", className);
                return false;
            } catch (InstantiationException e) {
                modLoader.error("Unable to instantiate class %s", className);
            }
            return true;
        }
        return false;
    }

    /**Loads a given ModLoader-rewritten mod using the given class
     * @param mainClass the class that implements {@link BaseMod}
     * @deprecated Not yet implemented
     * @return True if it found the class and will start loading the mod, false otherwise*/
    public static boolean loadModLoaderMod(Class<? extends MLMod> mainClass) {
        return loadModLoaderMod(mainClass.getName());
    }

}