diff --git a/src/io/github/packserver/RegPlug/Main.java b/src/io/github/packserver/RegPlug/Main.java index e2233419124c2b12880eeeea13e7a6ce134fbbf3..e8e7ca0cfdc40adde5e2438fbc049e99454efb9b 100644 --- a/src/io/github/packserver/RegPlug/Main.java +++ b/src/io/github/packserver/RegPlug/Main.java @@ -9,28 +9,56 @@ package io.github.packserver.RegPlug; import java.io.IOException; +import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener { - // Fired when plugin is disabled - @Override - public void onDisable() { + /** + * Global debug mode + */ + static Boolean DEBUG; - } + /** + * Plugin instance + */ + static Main plugin; - // Fired when plugin is first enabled + /** + * Fired when plugin is first enabled + */ @Override public void onEnable() { + // Create plugin instance and hand it to plugin + plugin = this; + // Try to run websocket server try { - WebServer.runServer(); WebsocketServer.runServer(); } catch (InterruptedException | IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } - this.getCommand("reg").setExecutor(new RegistrationExecutorThingy(this)); + // Debug mode + // Find if we are in debug mode or not + InputStream in = getClass().getResourceAsStream("/config.yml"); + FileConfiguration config = YamlConfiguration.loadConfiguration(in); + DEBUG = config.getBoolean("debug"); + } + + /** + * Fired when plugin is disabled + */ + @Override + public void onDisable() { + try { + WebsocketServer.server.stop(); + } catch (IOException | InterruptedException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } } }