package me.craftiii4.Rounds.Commands;

import java.util.List;

import me.craftiii4.Rounds.Rounds;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

public class CreateArena {
	
	public static void CommandYes(Rounds plugin, Player player) {

		if (Rounds.placelocationcheck.containsKey(player.getName())) {

			if (!plugin.getArenasConfig().getStringList("ArenaList").contains("set")) {


				player.sendMessage(ChatColor.GOLD
						+ "Creating and saving the rounds arena!");

				Location locationofblock = Rounds.placelocationcheck.get(player
						.getName());
				
				Rounds.placelocationcheck.remove(player.getName());
				
				
				Block centerblock = locationofblock.getBlock();
				
				
				World world = locationofblock.getWorld();

				plugin.getArenasConfig().set("CenterBlock.Location",
						locationofblock.toString());
				
				
				plugin.getArenasConfig().set("CenterBlock.X",
						locationofblock.getBlockX());
				
				
				plugin.getArenasConfig().set("CenterBlock.Y",
						locationofblock.getBlockY());
				
				plugin.getArenasConfig().set("CenterBlock.Z",
						locationofblock.getBlockZ());
				
				plugin.getArenasConfig().set("CenterBlock.Spawn.X",
						locationofblock.getX());
				
				
				plugin.getArenasConfig().set("CenterBlock.Spawn.Y",
						locationofblock.getY());
				
				plugin.getArenasConfig().set("CenterBlock.Spawn.Z",
						locationofblock.getZ());
							
				
				plugin.getArenasConfig().set("World", world.getName());
				

				centerblock.setType(Material.WOOL);

				int bordertest1 = -8;

				while (bordertest1 <= 8) {

					Location leftbottomcorner = locationofblock.getBlock()
							.getLocation();
					leftbottomcorner = leftbottomcorner.add(bordertest1, 0, -6);
					leftbottomcorner.getBlock().setType(Material.WOOL);
					leftbottomcorner.getBlock().setData((byte) 14);

					Location lefttopcorner = locationofblock.getBlock()
							.getLocation();
					lefttopcorner = lefttopcorner.add(bordertest1, 0, 6);
					lefttopcorner.getBlock().setType(Material.WOOL);
					lefttopcorner.getBlock().setData((byte) 14);
					
					Location leftbottomcorner1 = locationofblock.getBlock()
							.getLocation();
					leftbottomcorner1 = leftbottomcorner1.add(bordertest1, 4, -6);
					leftbottomcorner1.getBlock().setTypeId(44);
					leftbottomcorner1.getBlock().setData((byte) 8);

					Location lefttopcorner1 = locationofblock.getBlock()
							.getLocation();
					lefttopcorner1 = lefttopcorner1.add(bordertest1, 4, 6);
					lefttopcorner1.getBlock().setTypeId(44);
					lefttopcorner1.getBlock().setData((byte) 8);
					
					
					bordertest1++;
				}
				int bordertest2 = -6;

				while (bordertest2 <= 6) {

					Location rightbottomcorner = locationofblock.getBlock()
							.getLocation();
					rightbottomcorner = rightbottomcorner.add(8, 0, bordertest2);
					rightbottomcorner.getBlock().setType(Material.WOOL);
					rightbottomcorner.getBlock().setData((byte) 14);

					Location leftbottomcorner = locationofblock.getBlock()
							.getLocation();
					leftbottomcorner = leftbottomcorner.add(-8, 0, bordertest2);
					leftbottomcorner.getBlock().setType(Material.WOOL);
					leftbottomcorner.getBlock().setData((byte) 14);
					
					Location rightbottomcorner1 = locationofblock.getBlock()
							.getLocation();
					rightbottomcorner1 = rightbottomcorner1.add(8, 4, bordertest2);
					rightbottomcorner1.getBlock().setTypeId(44);
					rightbottomcorner1.getBlock().setData((byte) 8);

					Location leftbottomcorner1 = locationofblock.getBlock()
							.getLocation();
					leftbottomcorner1 = leftbottomcorner1.add(-8, 4, bordertest2);
					leftbottomcorner1.getBlock().setTypeId(44);
					leftbottomcorner1.getBlock().setData((byte) 8);
					
					
					bordertest2++;
				}

				int start1 = -7;
				int start2 = -5;

				while (start2 <= 5) {
					start1 = -7;

					while (start1 <= 7) {

						Location middle = locationofblock.getBlock()
								.getLocation();

						Block wool = middle.add(start1, 0, start2).getBlock();
						wool.setType(Material.WOOL);
						
						Location middle1 = locationofblock.getBlock()
								.getLocation();

						Block wool1 = middle1.add(start1, 5, start2).getBlock();
						wool1.setType(Material.GLASS);
						
						start1++;
					}

					start2++;
				}
				
				
				Location middle1 = locationofblock.getBlock()
						.getLocation();

				Block light1 = middle1.add(0, 5, 0).getBlock();
				light1.setType(Material.GLOWSTONE);
				
				Location middle2 = locationofblock.getBlock()
						.getLocation();

				Block light2 = middle2.add(0, 5, 4).getBlock();
				light2.setType(Material.GLOWSTONE);
				
				Location middle3 = locationofblock.getBlock()
						.getLocation();

				Block light3 = middle3.add(0, 5, -4).getBlock();
				light3.setType(Material.GLOWSTONE);
				
				Location middle4 = locationofblock.getBlock()
						.getLocation();

				Block light4 = middle4.add(-6, 5, 0).getBlock();
				light4.setType(Material.GLOWSTONE);
				
				Location middle5 = locationofblock.getBlock()
						.getLocation();

				Block light5 = middle5.add(6, 5, 0).getBlock();
				light5.setType(Material.GLOWSTONE);
				
				Location middle6 = locationofblock.getBlock()
						.getLocation();

				Block light6 = middle6.add(-3, 5, 2).getBlock();
				light6.setType(Material.GLOWSTONE);
				
				Location middle7 = locationofblock.getBlock()
						.getLocation();

				Block light7 = middle7.add(3, 5, 2).getBlock();
				light7.setType(Material.GLOWSTONE);
				
				Location middle8 = locationofblock.getBlock()
						.getLocation();

				Block light8 = middle8.add(-3, 5, -2).getBlock();
				light8.setType(Material.GLOWSTONE);
				
				Location middle9 = locationofblock.getBlock()
						.getLocation();

				Block light9 = middle9.add(3, 5, -2).getBlock();
				light9.setType(Material.GLOWSTONE);
				
				Location middle10 = locationofblock.getBlock()
						.getLocation();

				Block light10 = middle10.add(-6, 5, 4).getBlock();
				light10.setType(Material.GLOWSTONE);
				
				Location middle11 = locationofblock.getBlock()
						.getLocation();

				Block light11 = middle11.add(6, 5, 4).getBlock();
				light11.setType(Material.GLOWSTONE);
				
				Location middle12 = locationofblock.getBlock()
						.getLocation();

				Block light12 = middle12.add(6, 5, -4).getBlock();
				light12.setType(Material.GLOWSTONE);
				
				Location middle13 = locationofblock.getBlock()
						.getLocation();

				Block light13 = middle13.add(-6, 5, -4).getBlock();
				light13.setType(Material.GLOWSTONE);

				
				int glassleft = -7;

				while (glassleft <= 7) {
					
					Location left0 = locationofblock.getBlock()
							.getLocation();
					left0 = left0.add(-9, 0, glassleft);
					left0.getBlock().setTypeId(1);

					Location left1 = locationofblock.getBlock()
							.getLocation();
					left1 = left1.add(-9, 1, glassleft);
					left1.getBlock().setTypeId(44);
					
					Location left2 = locationofblock.getBlock()
							.getLocation();
					left2 = left2.add(-9, 2, glassleft);
					left2.getBlock().setTypeId(20);
					
					Location left3 = locationofblock.getBlock()
							.getLocation();
					left3 = left3.add(-9, 3, glassleft);
					left3.getBlock().setTypeId(44);
					left3.getBlock().setData((byte) 8);
					
					Location right0 = locationofblock.getBlock()
							.getLocation();
					right0 = right0.add(9, 0, glassleft);
					right0.getBlock().setTypeId(1);
					
					Location right1 = locationofblock.getBlock()
							.getLocation();
					right1 = right1.add(9, 1, glassleft);
					right1.getBlock().setTypeId(44);
					
					Location right2 = locationofblock.getBlock()
							.getLocation();
					right2 = right2.add(9, 2, glassleft);
					right2.getBlock().setTypeId(20);
					
					Location right3 = locationofblock.getBlock()
							.getLocation();
					right3 = right3.add(9, 3, glassleft);
					right3.getBlock().setTypeId(44);
					right3.getBlock().setData((byte) 8);
					
					glassleft++;
				}
				
				int glassleft2 = -8;

				while (glassleft2 <= 8) {
					
					Location top0 = locationofblock.getBlock()
							.getLocation();
					top0 = top0.add(glassleft2, 0, 7);
					top0.getBlock().setTypeId(1);
					
					Location top1 = locationofblock.getBlock()
							.getLocation();
					top1 = top1.add(glassleft2, 1, 7);
					top1.getBlock().setTypeId(44);
					
					Location top2 = locationofblock.getBlock()
							.getLocation();
					top2 = top2.add(glassleft2, 2, 7);
					top2.getBlock().setTypeId(20);
					
					Location top3 = locationofblock.getBlock()
							.getLocation();
					top3 = top3.add(glassleft2, 3, 7);
					top3.getBlock().setTypeId(44);
					top3.getBlock().setData((byte) 8);
					
					Location bottom0 = locationofblock.getBlock()
							.getLocation();
					bottom0 = bottom0.add(glassleft2, 0, -7);
					bottom0.getBlock().setTypeId(1);
					
					Location bottom1 = locationofblock.getBlock()
							.getLocation();
					bottom1 = bottom1.add(glassleft2, 1, -7);
					bottom1.getBlock().setTypeId(44);
					
					Location bottom2 = locationofblock.getBlock()
							.getLocation();
					bottom2 = bottom2.add(glassleft2, 2, -7);
					bottom2.getBlock().setTypeId(20);
					
					Location bottom3 = locationofblock.getBlock()
							.getLocation();
					bottom3 = bottom3.add(glassleft2, 3, -7);
					bottom3.getBlock().setTypeId(44);
					bottom3.getBlock().setData((byte) 8);
					
					
					
					
					glassleft2++;
				}
				
				
				locationofblock = Rounds.placelocationcheck.get(player
						.getName());

				List<String> list2 = plugin.getArenasConfig().getStringList(
						"ArenaList");
				list2.add("set");
				plugin.getArenasConfig().set("ArenaList", list2);

				plugin.saveArenasConfig();

			} else {
				player.sendMessage(ChatColor.RED
						+ "An arena with that name alreadly exists");
			}
		} else {
			player.sendMessage(ChatColor.RED + "Please pick a location first");
		}

	}


}
