package net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors;

import org.bukkit.ChatColor;

import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx;
import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.Response;

public class RequestExecutorChatSend extends AbstractRequestExecutor {
	
	public RequestExecutorChatSend() {
		super("chat_send");
	}

	@Override
	protected Response run(String data) {
		
		String[] dataSplit = data.split(" ", 2);
		if (dataSplit.length != 2)
			return new Response(false, "bad_data : at least one space");
		
		PermissionUser permUser = PermissionsEx.getUser(dataSplit[0]);
		
		if (permUser == null)
			return new Response(false, "user_not_exist : user is not registered in permission plugin");
		
		String displayName = permUser.getPrefix() + permUser.getName() + permUser.getSuffix();
		
		
		String finalMessage = "["+ChatColor.GRAY+"Console"+ChatColor.RESET+"]<"+displayName+ChatColor.RESET+"> "+dataSplit[1];
		
		plugin.broadcast(ChatColor.translateAlternateColorCodes('&', finalMessage), false);
		
		return new Response(true, "");
	}
	
	

}
