package com.arckenver.nations.cmdexecutor.nationadmin;

import java.math.BigDecimal;
import java.util.Optional;

import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.economy.account.Account;
import org.spongepowered.api.service.economy.transaction.ResultType;
import org.spongepowered.api.service.economy.transaction.TransactionResult;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import com.arckenver.nations.ConfigHandler;
import com.arckenver.nations.DataHandler;
import com.arckenver.nations.LanguageHandler;
import com.arckenver.nations.NationsPlugin;
import com.arckenver.nations.Utils;
import com.arckenver.nations.object.Nation;
import com.arckenver.nations.object.Point;
import com.arckenver.nations.object.Rect;
import com.arckenver.nations.object.Region;
import com.arckenver.nations.object.Zone;
import com.flowpowered.math.vector.Vector2i;

public class NationadminUnclaimExecutor implements CommandExecutor
{
	public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
	{
		if (src instanceof Player)
		{
			if (!ctx.<String>getOne("nation").isPresent())
			{
				src.sendMessage(Text.of(TextColors.YELLOW, "/na unclaim <nation>"));
				return CommandResult.success();
			}
			Player player = (Player) src;
			String nationName = ctx.<String>getOne("nation").get();
			Nation nation = DataHandler.getNation(nationName);
			if (nation == null)
			{
				src.sendMessage(Text.of(TextColors.RED, LanguageHandler.CB));
				return CommandResult.success();
			}
			Point a = DataHandler.getFirstPoint(player.getUniqueId());
			Point b = DataHandler.getSecondPoint(player.getUniqueId());
			if (a == null || b == null)
			{
				src.sendMessage(Text.of(TextColors.RED, LanguageHandler.EA));
				return CommandResult.success();
			}
			if (!ConfigHandler.getNode("worlds").getNode(a.getWorld().getName()).getNode("enabled").getBoolean())
			{
				src.sendMessage(Text.of(TextColors.RED, LanguageHandler.CS));
				return CommandResult.success();
			}
			Rect rect = new Rect(a, b);
			if (!nation.getRegion().intersects(rect))
			{
				src.sendMessage(Text.of(TextColors.RED, LanguageHandler.EC));
				return CommandResult.success();
			}
			for (Location<World> spawn : nation.getSpawns().values())
			{
				if (rect.isInside(new Vector2i(spawn.getBlockX(), spawn.getBlockZ())))
				{
					src.sendMessage(Text.of(TextColors.RED, LanguageHandler.EF));
					return CommandResult.success();
				}
			}
			for (Zone zone : nation.getZones().values())
			{
				if (zone.getRect().intersects(rect))
				{
					src.sendMessage(Text.of(TextColors.RED, LanguageHandler.HF));
					return CommandResult.success();
				}
			}
			Region claimed = nation.getRegion().copy();
			claimed.removeRect(rect);
			int toUnclaim = nation.getRegion().size() - claimed.size();	

			nation.setRegion(claimed);
			DataHandler.addToWorldChunks(nation);
			DataHandler.saveNation(nation.getUUID());
			src.sendMessage(Text.of(TextColors.AQUA, LanguageHandler.HL));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.CA));
		}
		return CommandResult.success();
	}
}

@@ -53,65 +53,8 @@
 n;%0A%0A
-import java.math.BigDecimal;%0Aimport java.util.Optional;%0A%0A
 impo
@@ -100,24 +100,24 @@
 dException;%0A
+
 import org.s
@@ -387,215 +387,8 @@
 er;%0A
-import org.spongepowered.api.service.economy.account.Account;%0Aimport org.spongepowered.api.service.economy.transaction.ResultType;%0Aimport org.spongepowered.api.service.economy.transaction.TransactionResult;%0A
 impo
@@ -642,32 +642,32 @@
 ns.DataHandler;%0A
+
 import com.arcke
@@ -700,88 +700,8 @@
 er;%0A
-import com.arckenver.nations.NationsPlugin;%0Aimport com.arckenver.nations.Utils;%0A
 impo
@@ -2834,72 +2834,8 @@
 ct);
-%0A%09%09%09int toUnclaim = nation.getRegion().size() - claimed.size();%09
 %0A%0A%09%09

clean imports