Add commandbase array

This commit is contained in:
JeremyStar™ 2024-04-30 22:29:00 +02:00
parent 2f9eaffa12
commit 0fb317038a
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -18,6 +18,7 @@
*/ */
package de.pickshadow.plugin.base; package de.pickshadow.plugin.base;
import de.pickshadow.plugin.classes.CommandBase;
import de.pickshadow.plugin.classes.logger.LoggerInstanceImpl; import de.pickshadow.plugin.classes.logger.LoggerInstanceImpl;
import de.pickshadow.plugin.commands.*; import de.pickshadow.plugin.commands.*;
import de.pickshadow.plugin.loaders.ConfigLoader; import de.pickshadow.plugin.loaders.ConfigLoader;
@ -32,6 +33,9 @@ public class PluginInitializer {
// Objects // Objects
private final LoggerInstanceImpl logger; private final LoggerInstanceImpl logger;
// Lists
CommandBase[] commands = new CommandBase[0];
public PluginInitializer() { public PluginInitializer() {
logger = ObjHolder.logger.getInstance(getClass()); logger = ObjHolder.logger.getInstance(getClass());
} }
@ -61,16 +65,14 @@ public class PluginInitializer {
return "Could not update active spelling language"; return "Could not update active spelling language";
} }
// Initialize commands
logger.verb("Initializing commands");
commands = new CommandBase[]{new BroadcastCommand(), new DiscordCommand(), new HomeCommand(), new PluginCommand(), new SystemInformationCommand(), new TrollCommand(), new MsgCommand()};
// Register commands // Register commands
logger.verb("Registering commands"); logger.verb("Registering commands");
try { try {
new BroadcastCommand().registerCommand(); for (CommandBase command : commands) command.registerCommand();
new DiscordCommand().registerCommand();
new HomeCommand().registerCommand();
new PluginCommand().registerCommand();
new SystemInformationCommand().registerCommand();
new TrollCommand().registerCommand();
new MsgCommand().registerCommand();
} catch (NullPointerException e) { } catch (NullPointerException e) {
logger.crash("Could not register plugin commands", e.getStackTrace()); logger.crash("Could not register plugin commands", e.getStackTrace());
} }
@ -92,10 +94,23 @@ public class PluginInitializer {
public void uninitialize() { public void uninitialize() {
logger.info("Uninitializing PSSP"); logger.info("Uninitializing PSSP");
// Close active hunspell instance
logger.verb("Closing Hunspell instance"); logger.verb("Closing Hunspell instance");
ObjHolder.spellingHelper.setActiveLanguage(null); ObjHolder.spellingHelper.setActiveLanguage(null);
// Save player data
logger.verb("Saving player data"); logger.verb("Saving player data");
for (UUID uuid : ObjHolder.playerDataLoader.getLoadedUUIDs()) ObjHolder.playerDataLoader.savePlayerData(uuid); for (UUID uuid : ObjHolder.playerDataLoader.getLoadedUUIDs()) ObjHolder.playerDataLoader.savePlayerData(uuid);
// Unregister commands
logger.verb("Unregistering commands");
try {
for (CommandBase command : commands) command.unregisterCommand();
} catch (NullPointerException e) {
logger.crash("Could not unregister plugin commands", e.getStackTrace(), true);
}
logger.info("Uninitialized PSSP"); logger.info("Uninitialized PSSP");
} }
} }