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

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

import org.apache.commons.lang.StringUtils;
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.command.RemoteConsoleCommandSender;
import org.bukkit.entity.Player;

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

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		if (args.length == 0) return false;
		
		
		String name;
		if (sender instanceof Player)
		{
			// pas de /me pour les mute
			if (EssentialsInterface.isPlayerMuted((Player)sender)) return true;
			
			name = ((Player)sender).getDisplayName()+ChatColor.RESET+" "+ChatColor.ITALIC;
		}
		else if (sender instanceof ConsoleCommandSender
				|| sender instanceof RemoteConsoleCommandSender)
			name = ChatColor.ITALIC+"Le serveur ";
		else
			name = ChatColor.ITALIC+"@ ";
		plugin.getServer().broadcastMessage(name + StringUtils.join(args, ' '));
		
		return true;
	}

}
