package com.mickare.xserver;

import java.io.IOException;
import java.util.logging.Logger;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.plugin.java.JavaPlugin;

import com.mickare.xserver.Exception.NotInitializedException;

public class XServerPlugin extends JavaPlugin {
	
	private Logger log;
	
	@Override
	public void onDisable() {
		log = this.getLogger();
		log.info("---------------------------------");
		log.info("------------ XServer ------------");
		log.info("----------  disabling  ----------");
		
		try {
			ServerMain.getInstance().stop();
		} catch (IOException | NotInitializedException e) {
			this.onDisable();
		}
		
		log.info(getDescription().getName() + " disabled!");
	}
	
	@Override
	public void onEnable() {		
		log = this.getLogger();
		log.info("---------------------------------");
		log.info("------------ XServer ------------");
		log.info("----------  enabling   ----------");
		
		this.saveDefaultConfig();
		
		try {
			ConfigServers.initialize(this); 
		} catch (InvalidConfigurationException e) {
			log.info(e.getMessage());
			this.getPluginLoader().disablePlugin(this);
			return;
		}
		
		EventHandler.initialize(this);
		try {
			MessageFactory.initialize(ConfigServers.getInstance());
		} catch (NotInitializedException e1) {
			log.info(e1.getMessage());
			this.getPluginLoader().disablePlugin(this);
		}
		
		try {
			ServerMain.initialize(ConfigServers.getInstance().getHomeServer());
		} catch (NotInitializedException e) {
			log.info(e.getMessage());
		}
		
		try {
			ServerMain.getInstance().start();
		} catch (IOException | NotInitializedException e) {
			log.info(e.getMessage());
			this.getPluginLoader().disablePlugin(this);
		}
		
		log.info(getDescription().getName() + " enabled!");
	}
	
	
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    	if(cmd.getName().equalsIgnoreCase("xserverreload")){
			try {
				ConfigServers.getInstance().reload();
			} catch (InvalidConfigurationException e) {
				sender.sendMessage(e.getMessage());
			} catch (NotInitializedException e) {
				sender.sendMessage(e.getMessage());
			}
    		return true;
    	}
    	return false; 
    }


	
}

@@ -722,24 +722,46 @@
 %0A%09%09%09
-this.onDisabl
+log.severe(%22Cause: %22 + e.getMessag
 e()
+)
 ;%0A%09%09
@@ -1160,37 +1160,51 @@
 ion e) %7B%0A%09%09%09log.
-info(
+severe(%22%5BERROR%5D%22 + 
 e.getMessage());
@@ -1417,21 +1417,35 @@
 %0A%09%09%09log.
-info(
+severe(%22%5BERROR%5D%22 + 
 e1.getMe
@@ -1493,32 +1493,43 @@
 lePlugin(this);%0A
+%09%09%09return;%0A
 %09%09%7D%0A%09%09%0A%09%09try %7B%0A%09
@@ -1637,37 +1637,51 @@
 ion e) %7B%0A%09%09%09log.
-info(
+severe(%22%5BERROR%5D%22 + 
 e.getMessage());
@@ -1673,32 +1673,43 @@
 .getMessage());%0A
+%09%09%09return;%0A
 %09%09%7D%0A%09%09%0A%09%09try %7B%0A%09
@@ -1805,21 +1805,35 @@
 %0A%09%09%09log.
-info(
+severe(%22%5BERROR%5D%22 + 
 e.getMes
@@ -1888,16 +1888,27 @@
 (this);%0A
+%09%09%09return;%0A
 %09%09%7D%0A%09%09%0A%09

Error Output