0

Made loader only register commands if the module was loaded successfully

This commit is contained in:
Pepich 2017-02-02 18:52:11 +01:00
parent 0fe41a40a9
commit 94d5b609ff

View File

@ -21,7 +21,7 @@ import com.redstoner.modules.Module;
/** The module loader, mother of all modules. Responsible for loading and taking care of all modules.
*
* @author Pepich */
@Version(major = 1, minor = 2, revision = 0, compatible = -1)
@Version(major = 1, minor = 3, revision = 0, compatible = -1)
public final class ModuleLoader implements CoreModule
{
private static ModuleLoader instance;
@ -48,7 +48,6 @@ public final class ModuleLoader implements CoreModule
{
Module module = clazz.newInstance();
modules.add(module);
CommandManager.registerCommand(module.getCommandString(), module, Main.plugin);
}
catch (InstantiationException | IllegalAccessException e)
{
@ -61,20 +60,21 @@ public final class ModuleLoader implements CoreModule
public static final void enableModules()
{
Debugger.notifyMethod();
for (Module m : modules)
for (Module module : modules)
{
if (m.enabled())
if (module.enabled())
continue;
if (m.enable())
if (module.enable())
{
if (m.getClass().isAnnotationPresent(AutoRegisterListener.class) && (m instanceof Listener))
CommandManager.registerCommand(module.getCommandString(), module, Main.plugin);
if (module.getClass().isAnnotationPresent(AutoRegisterListener.class) && (module instanceof Listener))
{
Bukkit.getPluginManager().registerEvents((Listener) m, Main.plugin);
Bukkit.getPluginManager().registerEvents((Listener) module, Main.plugin);
}
Utils.log("Loaded module " + m.getClass().getName());
Utils.log("Loaded module " + module.getClass().getName());
}
else
Utils.error("Failed to load module " + m.getClass().getName());
Utils.error("Failed to load module " + module.getClass().getName());
}
}