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

import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.Response;

public class RequestExecutorCommand extends AbstractRequestExecutor {

	public RequestExecutorCommand() {
		super("command");
		// TODO Auto-generated constructor stub
	}

	@Override
	protected Response run(String data) {
		
		plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
			String command;
			public void run() {
				try
				{
					boolean succes = plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command);
					 
					if (!succes)
						plugin.getLogger().warning("La commande ne peut pas s'exécuter : /"+command);
				}
				catch (Exception e)
				{
					plugin.getLogger().severe(e.getMessage());
				}
				
				
			}

			public Runnable init(String cmd) {
				command = cmd;
				return this;
			}
			
			
		}.init(data));
		
		Response rep = new Response();
		rep.good = true;
		rep.data = "";
		
		
		return rep;
	}

}
