package net.mc_pandacraft.java.plugin.pandacraftutils;


import java.sql.SQLException;

import net.mc_pandacraft.java.plugin.pandacraftutils.afk.CommandAfk;
import net.mc_pandacraft.java.plugin.pandacraftutils.calculator.CalculatorManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.chat_analyzer.ChatAnalysisManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.creative.CreativCheatManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.no_pvp.NoPvpProtectManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.login_message.LoginLogoutManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.player_count_list.PacketOutServerInfoListener;
import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.list.CommandList;
import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.me.CommandMe;
import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.ping.CommandPing;
import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.setblock.CommandSetblock;
import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.speed_message.CommandSpeedMessage;
import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.staff_player_help.CommandStaff;
import net.mc_pandacraft.java.plugin.pandacraftutils.spawntime.SpawnTimeManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid.CommandWandSelection;
import net.mc_pandacraft.java.plugin.pandacraftutils.system_analyzer.CommandSystem;
import net.mc_pandacraft.java.util.mysql.DBConnection;

import org.bukkit.plugin.java.JavaPlugin;

public class PandacraftUtils extends JavaPlugin {
	
	private static PandacraftUtils instance;
	public static PandacraftUtils getInstance() { return instance; }
	
	public DBConnection databaseConnection;
	
	public CommandAfk commandAfk;
	public CommandList commandPlayers;
	public CommandSetblock commandSetblock;
	public CommandSystem commandSystem;
	public CommandPing commandPing;
	public CommandMe commandMe;
	public CommandSpeedMessage commandSpeedMessage;
	public CommandWandSelection commandWandSelection;
	public CommandStaff commandStaff;
	
	
	public SpawnTimeManager spawnTimeManager;
	public ChatAnalysisManager chatAnalysisManager;
	public CreativCheatManager creativCheatManager;
	public NoPvpProtectManager noPvpProtectManager;
	public LoginLogoutManager loginLogoutManager;
	public CalculatorManager calculatorManager;
	
	public PacketOutServerInfoListener serverPingListener;

	
	@Override
    public void onEnable(){
		
		instance = this;
		
		try {
			databaseConnection = new DBConnection(ConfigManager.getInstance().Database_host,
											ConfigManager.getInstance().Database_port,
											ConfigManager.getInstance().Database_database,
											ConfigManager.getInstance().Database_username,
											ConfigManager.getInstance().Database_password);
		} catch (ClassNotFoundException | SQLException e) {
			getLogger().severe("Impossible de se connecter à la base de donnée !");
			e.printStackTrace();
		}
		
		commandPlayers = new CommandList(this);
        commandSetblock = new CommandSetblock(this);
		commandAfk = new CommandAfk(this);
		commandSystem = new CommandSystem(this);
		commandPing = new CommandPing(this);
		commandMe = new CommandMe(this);
		commandSpeedMessage = new CommandSpeedMessage(this);	// messages rapides
		commandWandSelection = new CommandWandSelection(this);
		commandStaff = new CommandStaff(this);

		spawnTimeManager = new SpawnTimeManager(this);
		chatAnalysisManager = new ChatAnalysisManager(this);
		creativCheatManager = new CreativCheatManager(this);
		noPvpProtectManager = new NoPvpProtectManager(this);
		loginLogoutManager = new LoginLogoutManager(this);
		calculatorManager = new CalculatorManager(this);
		
		serverPingListener = new PacketOutServerInfoListener(this);
    }
	
	
	@Override
	public void onDisable(){
		commandPlayers = null;
        commandSetblock = null;
        commandAfk = null;
        commandSystem = null;
        commandPing = null;
        commandMe = null;
        commandSpeedMessage = null;
        
        spawnTimeManager = null;
        chatAnalysisManager = null;
        creativCheatManager = null;
        noPvpProtectManager = null;
        calculatorManager = null;
        
        serverPingListener = null;
        
        
        try { databaseConnection.getConnection().close(); } catch (SQLException e) { }
    }

}

