-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(breakffa): Added base structure.
- Loading branch information
0 parents
commit 9f0d8d7
Showing
4 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* text=lf | ||
* eol=lf | ||
|
||
*.yml linguist-detectable=true | ||
*.yml linguist-language=YAML | ||
*.yaml linguist-detectable=true | ||
*.yaml linguist-language=YAML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.settings | ||
bin | ||
.classpath | ||
.idea | ||
classes | ||
*.iml | ||
out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: BreakFFA | ||
author: Lysandre B. | ||
version: 0.0.1-alpha | ||
main: fr.hashtek.spigot.breakffa.BreakFFA |