package net.Broken.RestApi; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.reflections.Reflections; import java.util.HashMap; import java.util.Set; public class ApiCommandLoader { public static HashMap apiCommands = new HashMap<>(); private static Logger logger = LogManager.getLogger(); public static void load(){ logger.info("Loading Api Command..."); Reflections reflections = new Reflections("net.Broken.RestApi.Command"); Set> modules = reflections.getSubTypesOf(CommandInterface.class); logger.info("Find " + modules.size() + " Command:"); for (Class apiClass : modules) { String reference = apiClass.getName(); String[] splited = reference.split("\\."); String name = splited[splited.length-1].toUpperCase(); logger.info("..." + name); try { apiCommands.put(name, apiClass.newInstance()); } catch (InstantiationException | IllegalAccessException e) { logger.error("Failed to load " + name + "!"); } } } }