0

Expanded functionality to allow more control in the module

This commit is contained in:
Pepich 2017-03-10 13:45:14 +01:00
parent 7b21e33aac
commit 63edc545e8

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import com.nemez.cmdmgr.Command; import com.nemez.cmdmgr.Command;
@ -13,15 +14,17 @@ 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;
import com.redstoner.exceptions.MissingVersionException;
import com.redstoner.misc.Main; import com.redstoner.misc.Main;
import com.redstoner.misc.Utils; import com.redstoner.misc.Utils;
import com.redstoner.misc.VersionHelper;
import com.redstoner.modules.CoreModule; import com.redstoner.modules.CoreModule;
import com.redstoner.modules.Module; 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 = 2, minor = 0, revision = 0, compatible = -1) @Version(major = 3, minor = 0, revision = 0, compatible = 2)
public final class ModuleLoader implements CoreModule public final class ModuleLoader implements CoreModule
{ {
private static ModuleLoader instance; private static ModuleLoader instance;
@ -68,12 +71,8 @@ public final class ModuleLoader implements CoreModule
{ {
if (module.onEnable()) if (module.onEnable())
{ {
CommandManager.registerCommand(module.getCommandString(), module, Main.plugin); if (VersionHelper.isCompatible(VersionHelper.create(2, 0, 0, -1), module.getClass()))
if (module.getClass().isAnnotationPresent(AutoRegisterListener.class) CommandManager.registerCommand(module.getCommandString(), module, Main.plugin);
&& (module instanceof Listener))
{
Bukkit.getPluginManager().registerEvents((Listener) module, Main.plugin);
}
modules.put(module, true); modules.put(module, true);
Utils.log("Loaded module " + module.getClass().getName()); Utils.log("Loaded module " + module.getClass().getName());
} }
@ -86,6 +85,28 @@ public final class ModuleLoader implements CoreModule
e.printStackTrace(); e.printStackTrace();
} }
} }
Utils.log("Modules enabled, running post initialization.");
for (Module module : modules.keySet())
{
if (modules.get(module))
{
try
{
if (VersionHelper.isCompatible(VersionHelper.create(3, 0, 0, 3), module.getClass()))
{
module.postEnable();
}
}
catch (MissingVersionException e)
{
e.printStackTrace();
}
if (module.getClass().isAnnotationPresent(AutoRegisterListener.class) && (module instanceof Listener))
{
Bukkit.getPluginManager().registerEvents((Listener) module, Main.plugin);
}
}
}
} }
/** This method enables a specific module. If no module with that name is known to the loader yet it will be added to the list. /** This method enables a specific module. If no module with that name is known to the loader yet it will be added to the list.
@ -188,6 +209,10 @@ public final class ModuleLoader implements CoreModule
if (modules.get(module)) if (modules.get(module))
{ {
module.onDisable(); module.onDisable();
if (module.getClass().isAnnotationPresent(AutoRegisterListener.class) && (module instanceof Listener))
{
HandlerList.unregisterAll((Listener) module);
}
} }
} }
} }