pingex
/
DiscordBot
Archived
1
0
Fork 0

Modules can now unregister.

master
Pingex aka Raphaël 9 years ago
parent 3826632288
commit 90a0a76ac4

@ -22,7 +22,14 @@ public abstract class AbstractModule
ModulesRegistry.register(this);
client.getDispatcher().registerListener(this);
logger = Logger.getLogger(this.getClass().getName());
logger.info("Loading module " + this.getClass().getName());
this.client = client;
}
/**
* Disable this module.
*/
public void shutdown()
{
ModulesRegistry.unregister(this);
}
}

@ -1,6 +1,7 @@
package net.pingex.discordbot;
import java.util.ArrayList;
import java.util.logging.Logger;
/**
* Class which keeps track of all known loaded modules
@ -12,15 +13,31 @@ class ModulesRegistry
*/
private static ArrayList<AbstractModule> datastore = new ArrayList<>();
/**
* Logger
*/
private static Logger LOGGER = Logger.getLogger(ModulesRegistry.class.getName());
/**
* Action to register a loaded module
* @param toRegister Module to register
*/
public static void register(AbstractModule toRegister)
{
LOGGER.info("Registering module " + toRegister.getClass().getName());
datastore.add(toRegister);
}
/**
* Remove the target module from the list (if it crashed for example)
* @param target Module to remove
*/
public static void unregister(AbstractModule target)
{
LOGGER.info("Unregistering module " + target.getClass().getName());
datastore.remove(target);
}
/**
* Returns of the whole registry
* @return A clone of the whole registry, to avoid damaging the original registry