diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fa5ad56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +* text=lf +* eol=lf + +*.yml linguist-detectable=true +*.yml linguist-language=YAML +*.yaml linguist-detectable=true +*.yaml linguist-language=YAML diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e67fb19 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.settings +bin +.classpath +.idea +classes +*.iml +out \ No newline at end of file diff --git a/src/fr/hashtek/spigot/breakffa/BreakFFA.java b/src/fr/hashtek/spigot/breakffa/BreakFFA.java new file mode 100644 index 0000000..9fb183e --- /dev/null +++ b/src/fr/hashtek/spigot/breakffa/BreakFFA.java @@ -0,0 +1,214 @@ +package fr.hashtek.spigot.breakffa; + +import fr.hashtek.hashconfig.HashConfig; +import fr.hashtek.hasherror.HashError; +import fr.hashtek.hashlogger.HashLoggable; +import fr.hashtek.hashlogger.HashLogger; +import fr.hashtek.spigot.breakffa.game.GameManager; +import fr.hashtek.spigot.breakffa.listener.ListenerJoin; +import fr.hashtek.spigot.breakffa.listener.ListenerQuit; +import fr.hashtek.spigot.hashgui.HashGuiManager; +import fr.hashtek.tekore.bukkit.Tekore; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.IOException; + +public class BreakFFA extends JavaPlugin implements HashLoggable { + + private static BreakFFA instance; + private Tekore core; + private HashLogger logger; + + private PluginManager pluginManager; + private HashGuiManager guiManager; + + private HashConfig hashConfig; + + private GameManager gameManager; + + + /** + * Called on server start. + * Core error handling uses System.err.println because + * HashLogger isn't loaded yet. + */ + @Override + public void onEnable() + { + instance = this; + + try { + this.core = Tekore.getInstance(); + } catch (NoClassDefFoundError exception) { + System.err.println("Tekore failed to load, stopping server."); + this.getServer().shutdown(); + return; + } + + this.setupHashLogger(); + this.setupConfig(); + + logger.info(this, "Starting BreakFFA..."); + + this.setupManagers(); + this.registerListeners(); + this.registerCommands(); + + logger.info(this, "BreakFFA loaded."); + } + + /** + * Called on server stop. + */ + @Override + public void onDisable() + { + logger.info(this, "Disabling Lobby..."); + + // ... + + logger.info(this, "Lobby disabled."); + } + + /** + * Creates a new instance of HashConfig, to read configuration files. + * Also creates a new instance of LobbyConfiguration. + */ + private void setupConfig() + { + String configFilename = "config.yml"; + + try { + this.hashConfig = new HashConfig( + this.getClass(), + configFilename, + this.getDataFolder().getPath() + "/" + configFilename, + false + ); + } catch (IOException exception) { + this.logger.fatal(this, "Failed to read config file. Stopping server.", exception); + this.getServer().shutdown(); + } + } + + /** + * Creates an instance of HashLogger. + * Based on Tekore's HashLogger's settings and history. + */ + private void setupHashLogger() + { + final HashLogger coreLogger = this.core.getHashLogger(); + + this.logger = new HashLogger(this, coreLogger.getSettings().getLogLevel(), coreLogger.getHistory()); + } + + /** + * Setups all managers. + */ + private void setupManagers() + { + this.logger.info(this, "Setting up managers..."); + + this.pluginManager = this.getServer().getPluginManager(); + + this.guiManager = new HashGuiManager(this, this.pluginManager); + this.guiManager.setup(); + + this.setupGameManager(); + + this.logger.info(this, "Managers set up!"); + } + + private void setupGameManager() + { + this.logger.info(this, "Setting up Game manager..."); + + this.gameManager = new GameManager(this); + + try { + this.gameManager.setup(this.hashConfig); + } catch (Exception exception) { + HashError.UNKNOWN + .log(this.logger, this, exception); + + this.getServer().shutdown(); + } + + this.logger.info(this, "Game manager set up!"); + } + + /** + * Registers all event listeners. + */ + private void registerListeners() + { + this.logger.info(this, "Registering listeners..."); + + this.pluginManager.registerEvents(new ListenerJoin(this), this); + this.pluginManager.registerEvents(new ListenerQuit(this), this); + + this.logger.info(this, "Listeners loaded!"); + } + + /** + * Registers all command listeners. + */ + private void registerCommands() + { + this.logger.info(this, "Registering commands..."); + + /* ... */ + + this.logger.info(this, "Commands registered!"); + } + + /** + * @return BreakFFA instance + */ + public static BreakFFA getInstance() + { + return instance; + } + + /** + * @return Tekore instance + */ + public Tekore getCore() + { + return this.core; + } + + /** + * @return Logger + */ + public HashLogger getHashLogger() + { + return this.logger; + } + + /** + * @return Configuration manager + */ + public HashConfig getHashConfig() + { + return this.hashConfig; + } + + /** + * @return GUI manager + */ + public HashGuiManager getGUIManager() + { + return this.guiManager; + } + + /** + * @return Game manager + */ + public GameManager getGameManager() + { + return this.gameManager; + } + +} diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..a9f887a --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,4 @@ +name: BreakFFA +author: Lysandre B. +version: 0.0.1-alpha +main: fr.hashtek.spigot.breakffa.BreakFFA \ No newline at end of file