package net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.ping;


import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;

public class CommandPing implements CommandExecutor {
	
	private PandacraftUtils plugin;
	
	public CommandPing(PandacraftUtils pl)
	{
		plugin = pl;
		
        plugin.getCommand("ping").setExecutor(this);
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
	{
		
		if (sender instanceof Player)
		{
			try
			{
				int ping = ((CraftPlayer)(Player)sender).getHandle().ping;
				sender.sendMessage(ChatColor.LIGHT_PURPLE+"Votre ping est de §7"+ping+" ms"+ChatColor.LIGHT_PURPLE+".");
			}
			catch (Exception e)
			{
				sender.sendMessage(ChatColor.RED+"Impossible de récupérer votre ping");
				e.printStackTrace();
			}
			return true;
		}
		else if (sender instanceof ConsoleCommandSender)
		{
			plugin.getServer().dispatchCommand(sender, "list ping");
		}
		
		
		
		
		
		
		
		return true;
	}

}
