From 14f187c32dbf393508b36fb0720f1d87afe11166 Mon Sep 17 00:00:00 2001 From: DNx Date: Sun, 20 Sep 2015 20:15:36 +0700 Subject: [PATCH] start working on modules --- src/main/java/fr/xephi/authme/AuthMe.java | 27 +++++++++++++------ .../java/fr/xephi/authme/modules/Module.java | 24 +++++++---------- .../xephi/authme/modules/ModuleManager.java | 20 +++++++++++--- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index c6385f3e1..0cf325976 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -15,6 +15,7 @@ import fr.xephi.authme.converter.Converter; import fr.xephi.authme.converter.ForceFlatToSqlite; import fr.xephi.authme.datasource.*; import fr.xephi.authme.listener.*; +import fr.xephi.authme.modules.ModuleManager; import fr.xephi.authme.plugin.manager.BungeeCordMessage; import fr.xephi.authme.plugin.manager.EssSpawn; import fr.xephi.authme.process.Management; @@ -24,7 +25,6 @@ import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Spawn; import net.milkbowl.vault.permission.Permission; import net.minelink.ctplus.CombatTagPlus; - import org.apache.logging.log4j.LogManager; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -64,15 +64,22 @@ public class AuthMe extends JavaPlugin { public DataSource database; private JsonCache playerBackup; public OtherAccounts otherAccounts; - public Permission permission; - public Essentials ess; public Location essentialsSpawn; - public MultiverseCore multiverse; public LookupService lookupService; - public CombatTagPlus combatTagPlus = null; public boolean legacyChestShop = false; public boolean antibotMod = false; public boolean delayedAntiBot = true; + + // Hooks TODO: move into modules + public Permission permission; + public Essentials ess; + public MultiverseCore multiverse; + public CombatTagPlus combatTagPlus; + + // Manager + private ModuleManager moduleManager; + + // TODO: Create Manager for fields below public ConcurrentHashMap sessions = new ConcurrentHashMap<>(); public ConcurrentHashMap captcha = new ConcurrentHashMap<>(); public ConcurrentHashMap cap = new ConcurrentHashMap<>(); @@ -101,6 +108,9 @@ public class AuthMe extends JavaPlugin { authme = this; // TODO: split the plugin in more modules + moduleManager = new ModuleManager(this); + int loaded = moduleManager.loadModules(); + // TODO: remove vault as hard dependency PluginManager pm = server.getPluginManager(); @@ -312,16 +322,17 @@ public class AuthMe extends JavaPlugin { // Do backup on stop if enabled if (Settings.isBackupActivated && Settings.isBackupOnStop) { - Boolean Backup = new PerformBackup(this).doBackup(); + boolean Backup = new PerformBackup(this).doBackup(); if (Backup) ConsoleLogger.info("Backup performed correctly."); else ConsoleLogger.showError("Error while performing the backup!"); } + // Unload modules + moduleManager.unloadModules(); + // Disabled correctly ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " disabled!"); - - authme = null; } // Stop/unload the server/plugin as defined in the configuration diff --git a/src/main/java/fr/xephi/authme/modules/Module.java b/src/main/java/fr/xephi/authme/modules/Module.java index 6011097af..ab30e5ef9 100644 --- a/src/main/java/fr/xephi/authme/modules/Module.java +++ b/src/main/java/fr/xephi/authme/modules/Module.java @@ -1,28 +1,24 @@ package fr.xephi.authme.modules; -import fr.xephi.authme.AuthMe; +public abstract class Module { -public interface Module { - - public String getName(); - - public AuthMe getInstanceOfAuthMe(); - - public Module getInstance(); - - public enum ModuleType { + enum ModuleType { MANAGER, MYSQL, REDIS, ACTIONS, CONVERTERS, EMAILS, - CUSTOM; + CUSTOM } - public ModuleType getType(); + public abstract String getName(); - public boolean load(); + public abstract ModuleType getType(); - public boolean unload(); + public void load() { + } + + public void unload() { + } } diff --git a/src/main/java/fr/xephi/authme/modules/ModuleManager.java b/src/main/java/fr/xephi/authme/modules/ModuleManager.java index f3c7df3c4..32d4d1fa6 100644 --- a/src/main/java/fr/xephi/authme/modules/ModuleManager.java +++ b/src/main/java/fr/xephi/authme/modules/ModuleManager.java @@ -10,6 +10,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Enumeration; +import java.util.Iterator; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -111,10 +112,23 @@ public class ModuleManager { return count; } + public void unloadModule(String name) { + Iterator it = modules.iterator(); + while (it.hasNext()) { + Module m = it.next(); + if (m.getName().equalsIgnoreCase(name)) { + m.unload(); + it.remove(); + return; + } + } + } + public void unloadModules() { - for (Module m : modules) { - m.unload(); - modules.remove(m); + Iterator it = modules.iterator(); + while (it.hasNext()) { + it.next().unload(); + it.remove(); } }