package net.mc_pandacraft.java.plugin.pandacraftutils.commands;

import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.NetworkAPI;
import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.NetworkAPIListener;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

public class CommandAdmin extends AbstractCommandExecutor {

	public CommandAdmin() {
		super("admin");
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label,
			String[] args) {
		
		
		if (args.length == 0){
			sender.sendMessage(ChatColor.GREEN+plugin.getDescription().getFullName());
			NetworkAPIListener nwAPI = NetworkAPIListener.getInstance();
			if (nwAPI.isAlive())
				sender.sendMessage(ChatColor.GREEN+"NetworkAPI écoute au port "+NetworkAPIListener.getInstance().getPort());
			else
				sender.sendMessage(ChatColor.GREEN+"NetworkAPI n'est pas démarré. Voir la console pour les détails, ou faites /admin reload ");
			return true;
		}
		
		if (args[0].equalsIgnoreCase("reload") && args.length >= 2) {
			if (args[1].equalsIgnoreCase("config")) {
				ConfigManager.loadNewInstance();
				sender.sendMessage(ChatColor.GREEN+"La configuration de PandacraftUtils viens d'être rechargée");
				return true;
			}
			
			if (args[1].equalsIgnoreCase("network")) {
				sender.sendMessage(ChatColor.GREEN+"Redémarrage de NetworkAPI");
				NetworkAPI.loadNewInstance();
				sender.sendMessage(ChatColor.GREEN+"Redémarrage terminée");
				return true;
			}
		}
		
		
		return false;
	}


}
