0

Made @AutoRegisterListener functional

This commit is contained in:
Pepich 2017-02-01 12:48:02 +01:00
parent 3485973249
commit d572b652aa

View File

@ -2,11 +2,14 @@ package com.redstoner.coremods.ModuleLoader;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
import com.nemez.cmdmgr.Command; import com.nemez.cmdmgr.Command;
import com.nemez.cmdmgr.Command.AsyncType; import com.nemez.cmdmgr.Command.AsyncType;
import com.nemez.cmdmgr.CommandManager; import com.nemez.cmdmgr.CommandManager;
import com.redstoner.annotations.AutoRegisterListener;
import com.redstoner.annotations.Debugable; import com.redstoner.annotations.Debugable;
import com.redstoner.annotations.Version; import com.redstoner.annotations.Version;
import com.redstoner.coremods.debugger.Debugger; import com.redstoner.coremods.debugger.Debugger;
@ -18,7 +21,7 @@ import com.redstoner.modules.Module;
/** The module loader, mother of all modules. Responsible for loading and taking care of all modules. /** The module loader, mother of all modules. Responsible for loading and taking care of all modules.
* *
* @author Pepich */ * @author Pepich */
@Version(major = 1, minor = 1, revision = 0, compatible = -1) @Version(major = 1, minor = 1, revision = 1, compatible = -1)
public final class ModuleLoader implements CoreModule public final class ModuleLoader implements CoreModule
{ {
private static ModuleLoader instance; private static ModuleLoader instance;
@ -63,9 +66,14 @@ public final class ModuleLoader implements CoreModule
{ {
if (m.enabled()) if (m.enabled())
continue; continue;
m.onEnable(); if (m.enable())
if (m.enabled()) {
if (m.getClass().isAnnotationPresent(AutoRegisterListener.class) && (m instanceof Listener))
{
Bukkit.getPluginManager().registerEvents((Listener) m, Main.plugin);
}
Utils.log("Loaded module " + m.getClass().getName()); Utils.log("Loaded module " + m.getClass().getName());
}
else else
Utils.error("Failed to load module " + m.getClass().getName()); Utils.error("Failed to load module " + m.getClass().getName());
} }
@ -83,7 +91,20 @@ public final class ModuleLoader implements CoreModule
{ {
if (m.getClass().equals(clazz)) if (m.getClass().equals(clazz))
{ {
return m.enable(); if (m.enable())
{
if (m.getClass().isAnnotationPresent(AutoRegisterListener.class) && (m instanceof Listener))
{
Bukkit.getPluginManager().registerEvents((Listener) m, Main.plugin);
}
Utils.log("Loaded module " + m.getClass().getName());
return true;
}
else
{
Utils.error("Failed to load module " + m.getClass().getName());
return false;
}
} }
} }
try try
@ -92,8 +113,19 @@ public final class ModuleLoader implements CoreModule
modules.add(m); modules.add(m);
m.onEnable(); m.onEnable();
if (m.enabled()) if (m.enabled())
{
if (m.getClass().isAnnotationPresent(AutoRegisterListener.class) && (m instanceof Listener))
{
Bukkit.getPluginManager().registerEvents((Listener) m, Main.plugin);
}
Utils.log("Loaded module " + m.getClass().getName()); Utils.log("Loaded module " + m.getClass().getName());
return m.enabled(); return true;
}
else
{
Utils.error("Failed to load module " + m.getClass().getName());
return false;
}
} }
catch (InstantiationException | IllegalAccessException e) catch (InstantiationException | IllegalAccessException e)
{ {