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

import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

public class CommandBroadcast extends AbstractCommandExecutor {
	public CommandBroadcast() {
		super("broadcast");
		
		// classe qui gère deux commandes (presque identiques)
        plugin.getCommand("broadcastperm").setExecutor(this);
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		if (args.length == 0) return false;
		
		
		if (label.equalsIgnoreCase("broadcast"))
		{
			plugin.broadcast(ChatColor.translateAlternateColorCodes('&', StringUtils.join(args, ' ')), true);
			return true;
		}
		
		// ici, il s'agit de /broadcastperm
		if (args.length > 2) return false;
		
		String perm = args[0];
		args[0] = null;
		

		plugin.broadcast(ChatColor.translateAlternateColorCodes('&', StringUtils.join(args, ' ')), true, perm);
		
		
		return true;
	}

}
