start working on modules

This commit is contained in:
DNx 2015-09-20 20:15:36 +07:00 committed by DNx5
parent c94f9c5cdc
commit 14f187c32d
3 changed files with 46 additions and 25 deletions

View File

@ -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<String, BukkitTask> sessions = new ConcurrentHashMap<>();
public ConcurrentHashMap<String, Integer> captcha = new ConcurrentHashMap<>();
public ConcurrentHashMap<String, String> 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

View File

@ -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() {
}
}

View File

@ -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<Module> 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<Module> it = modules.iterator();
while (it.hasNext()) {
it.next().unload();
it.remove();
}
}