package com.gmail.Lecrayen.Platinum.MMO.Commands.Region;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.gmail.Lecrayen.Platinum.API.MainCommand;
import com.gmail.Lecrayen.Platinum.API.Subcommand;
import com.gmail.Lecrayen.Platinum.MMO.MMO;
import com.gmail.Lecrayen.Platinum.MMO.Selection;
import com.gmail.Lecrayen.Platinum.MMO.Zone;
import com.gmail.Lecrayen.Platinum.MMO.DataLibrary.SelectionManager;
import com.gmail.Lecrayen.Platinum.MMO.Exceptions.ZoneAreaDivideException;
import com.gmail.Lecrayen.Platinum.MMO.Exceptions.ZoneAreaOverlapException;

public class RegionNew implements Subcommand {

	private String description = "Create a new region with your selection";
	private MainCommand main;
	private String name = "new";
	private String permission = "platinum.region.new";
	private boolean playeronly = true;
	private String usage = "/region new";

	public RegionNew(MainCommand maincommand) {
		main = maincommand;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public MainCommand getMainCommand() {
		return main;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String getPermission() {
		return permission;
	}

	@Override
	public String getUsage() {
		return usage;
	}

	@Override
	public boolean isPlayerOnly() {
		return playeronly;
	}

	@Override
	public void run(CommandSender sender, String[] args) {
		Player p = (Player) sender;
		Selection s = SelectionManager.getSelection(p.getUniqueId());
		if (!s.isComplete()) {
			p.sendMessage("§4[Error]:§f You have not made a selection");
			return;
		}
		try {
			MMO.zone_manager.addRegion(new Zone(s.getArea(), p));
			p.sendMessage("§2[Info]:§f You have created a region");
		} catch (ZoneAreaDivideException e) {
			p.sendMessage("§4[Error]:§f Your selection overlaps a lot or home without encompassing it");
		} catch (ZoneAreaOverlapException e) {
			p.sendMessage("§4[Error]:§f Your selection overlaps another region");
		}
	}
}
