package me.craftiii4.Rounds.PossibleRounds;

import java.util.List;

import me.craftiii4.Rounds.GetBlockUnderneath;
import me.craftiii4.Rounds.PickRounds;
import me.craftiii4.Rounds.Rounds;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

public class AAAToDoCheckered {
	private static int time = 35;
	static int example1;
	static int delay = 0;
	static int right1 = 7;
	static int left1 = -7;
	public static void startRoundOne45(final Rounds plugin) {
		
		int currentround = plugin.getDataConfig().getInt("Rounds.CurrentLevel");
		int newround = currentround + 1;
		
		int howmanyplayers = plugin.getDataConfig().getStringList("PlayersPlaying").size();
		int togo = 0;
    	
		while (howmanyplayers > togo) {
			String playername = plugin.getDataConfig().getStringList("PlayersPlaying").get(togo);
			Player player1 = Bukkit.getPlayer(playername);
			
			if (!player1.equals(null)) {
				player1.sendMessage(ChatColor.GREEN + "Starting " + ChatColor.GOLD + "Round " + ChatColor.DARK_PURPLE + newround + ChatColor.GREEN + " - Checkered - Medium - @duffbunny");
			
			}
			togo++;
		}
		
		
		plugin.getDataConfig().set("Rounds.CurrentLevel", currentround + 1);
		GetBlockUnderneath.started = true;
		delay = 0;
		example1 = plugin.getServer().getScheduler()
				.scheduleAsyncRepeatingTask(plugin, new Runnable() {
					public void run() {
						if (time == 30) {
							//final int centerx = plugin.getArenasConfig()
							//		.getInt("CenterBlock.X");
							//final int centery = plugin.getArenasConfig()
							//		.getInt("CenterBlock.Y");
							//final int centerz = plugin.getArenasConfig()
							//		.getInt("CenterBlock.Z");

							//final String world = plugin.getArenasConfig()
							//		.getString("World");
							
							
							
							
							
						}
					


						if (time == 0) {
							stopexample1(plugin);

						}
						time--;
						if (time < -10) {
							time = 0;
						}
						if (Rounds.stop.equals("ForceStop")) {
							stopexample2(plugin);
						}
						if (Rounds.alldead == true) {
							stopexample3(plugin);
						}
					}

					
				}, 00L, 20L);
				
	}
	
	public static void stopexample1(final Rounds plugin) {
		plugin.getServer().getScheduler().cancelTask(example1);
		Bukkit.getScheduler().cancelTask(example1);
		time = 32;
		plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

		    public void run() {
		    	
				int howmanyplayers = plugin.getDataConfig().getStringList("PlayersPlaying").size();
				int togo = 0;
				int currentround = plugin.getDataConfig().getInt("Rounds.CurrentLevel");
				
				while (howmanyplayers > togo) {
					String playername = plugin.getDataConfig().getStringList("PlayersPlaying").get(togo);
					Player player = Bukkit.getPlayer(playername);
					
					if (!player.equals(null)) {
						int newround = currentround + 1;
						player.sendMessage(ChatColor.GOLD + "Weldone at completeing Round " + ChatColor.DARK_PURPLE + currentround +  ChatColor.GOLD + ", get ready for round " + ChatColor.DARK_PURPLE + newround);
					}
					togo++;
				}
				
				//
		    	
		    }
		}, 150L);
		
		plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

		    public void run() {
		    	
				int howmanyplayers = plugin.getDataConfig().getStringList("PlayersPlaying").size();
				int togo = 0;
				//int currentround = plugin.getDataConfig().getInt("Rounds.CurrentLevel");
		    	
				while (howmanyplayers > togo) {
					
					String playername = plugin.getDataConfig().getStringList("PlayersPlaying").get(togo);
					Player player = Bukkit.getPlayer(playername);
					
					if (!player.equals(null)) {
						if (player.isOnline()) {
						//int newround = currentround + 1;
						player.sendMessage(ChatColor.AQUA + "------------" + ChatColor.GOLD + " [" + ChatColor.LIGHT_PURPLE + " Rounds " + ChatColor.GOLD + "] " + ChatColor.AQUA + "----------");
						}
						}
					togo++;
				}
				
				int currentround = plugin.getDataConfig().getInt("Rounds.CurrentLevel");
				int newround = currentround + 1;
				PickRounds.PickRound(plugin, newround);
		    }
		    	
		}, 250L);
		
	}
	
	public static void stopexample3(Rounds plugin) {
		plugin.getServer().getScheduler().cancelTask(example1);
		Bukkit.getScheduler().cancelTask(example1);
		time = 32;
		GetBlockUnderneath.running = false;
		Rounds.stop = "Run";
		
		//
		
		int howmanyplayers = plugin.getDataConfig().getStringList("PlayersPlaying").size();
		int togo = 0;
		int currentround = plugin.getDataConfig().getInt("Rounds.CurrentLevel");
		
		while (howmanyplayers > togo) {
			String playername = plugin.getDataConfig().getStringList("PlayersPlaying").get(togo);
			Player player = Bukkit.getPlayer(playername);
			
			if (!player.equals(null)) {
				player.sendMessage(ChatColor.GOLD + "All players are dead! Got to round " + ChatColor.DARK_PURPLE + currentround);
			}
			togo++;
		}
		
		//
		
		
		//
		
		List<String> playing = plugin.getDataConfig()
				.getStringList("PlayersPlaying");
		playing.clear();
		plugin.getDataConfig().set("PlayersPlaying", playing);
		
		
		Rounds.gamerunning.clear();
		Rounds.blockplayer.clear();
		
		plugin.saveDataConfig();
		
	}
	public static void stopexample2(Rounds plugin) {
		plugin.getServer().getScheduler().cancelTask(example1);
		Bukkit.getScheduler().cancelTask(example1);
		time = 32;
		Rounds.stop = "Run";
		GetBlockUnderneath.running = false;
		
		
		
	}

}
