Expanded functionality to allow more control in the module
This commit is contained in:
parent
7b21e33aac
commit
63edc545e8
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.nemez.cmdmgr.Command;
|
||||
@ -13,15 +14,17 @@ import com.redstoner.annotations.AutoRegisterListener;
|
||||
import com.redstoner.annotations.Debugable;
|
||||
import com.redstoner.annotations.Version;
|
||||
import com.redstoner.coremods.debugger.Debugger;
|
||||
import com.redstoner.exceptions.MissingVersionException;
|
||||
import com.redstoner.misc.Main;
|
||||
import com.redstoner.misc.Utils;
|
||||
import com.redstoner.misc.VersionHelper;
|
||||
import com.redstoner.modules.CoreModule;
|
||||
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 = 2, minor = 0, revision = 0, compatible = -1)
|
||||
@Version(major = 3, minor = 0, revision = 0, compatible = 2)
|
||||
public final class ModuleLoader implements CoreModule
|
||||
{
|
||||
private static ModuleLoader instance;
|
||||
@ -68,12 +71,8 @@ public final class ModuleLoader implements CoreModule
|
||||
{
|
||||
if (module.onEnable())
|
||||
{
|
||||
if (VersionHelper.isCompatible(VersionHelper.create(2, 0, 0, -1), module.getClass()))
|
||||
CommandManager.registerCommand(module.getCommandString(), module, Main.plugin);
|
||||
if (module.getClass().isAnnotationPresent(AutoRegisterListener.class)
|
||||
&& (module instanceof Listener))
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents((Listener) module, Main.plugin);
|
||||
}
|
||||
modules.put(module, true);
|
||||
Utils.log("Loaded module " + module.getClass().getName());
|
||||
}
|
||||
@ -86,6 +85,28 @@ public final class ModuleLoader implements CoreModule
|
||||
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.
|
||||
@ -188,6 +209,10 @@ public final class ModuleLoader implements CoreModule
|
||||
if (modules.get(module))
|
||||
{
|
||||
module.onDisable();
|
||||
if (module.getClass().isAnnotationPresent(AutoRegisterListener.class) && (module instanceof Listener))
|
||||
{
|
||||
HandlerList.unregisterAll((Listener) module);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user