/* This file is part of ArborianQuests for Bukkit, licensed under the MIT License (MIT).
 * 
 * Copyright (c) JCThePants (www.jcwhatever.com)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */


package com.jcwhatever.arborianquests.commands.admin.locations;

import com.jcwhatever.arborianquests.ArborianQuests;
import com.jcwhatever.arborianquests.Lang;
import com.jcwhatever.arborianquests.locations.ScriptLocation;
import com.jcwhatever.arborianquests.locations.ScriptLocationManager;
import com.jcwhatever.nucleus.commands.AbstractCommand;
import com.jcwhatever.nucleus.commands.CommandInfo;
import com.jcwhatever.nucleus.commands.arguments.CommandArguments;
import com.jcwhatever.nucleus.commands.arguments.LocationResponse;
import com.jcwhatever.nucleus.commands.exceptions.CommandException;
import com.jcwhatever.nucleus.managed.language.Localizable;

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

@CommandInfo(
        parent="locations",
        command = "add",
        staticParams = { "locationName", "location" },
        description = "Add a new quest location.",
        paramDescriptions = {
                "locationName= The name of the location. {NAME}",
                "location= The location. {LOCATION}"
        })

public class AddSubCommand extends AbstractCommand {

    @Localizable static final String _LOCATION_ALREADY_EXISTS = "There is already a location with the name '{0}'.";
    @Localizable static final String _FAILED = "Failed to add location.";
    @Localizable static final String _SUCCESS = "Quest location '{0}' created.";

    @Override
    public void execute (CommandSender sender, CommandArguments args) throws CommandException {

        CommandException.checkNotConsole(this, sender);

        final String locationName = args.getName("locationName", 48);

        final ScriptLocationManager manager = ArborianQuests.getScriptLocationManager();

        ScriptLocation scriptLocation = manager.get(locationName);
        if (scriptLocation != null) {
            tellError(sender, Lang.get(_LOCATION_ALREADY_EXISTS), locationName);
            return; // finished
        }

        args.getLocation(sender, "location", new LocationResponse() {

            @Override
            public void onLocationRetrieved(Player p, Location result) {

                ScriptLocation scriptLocation = manager.add(locationName, result);
                if (scriptLocation == null) {
                    tellError(p, Lang.get(_FAILED));
                }
                else {
                    tellSuccess(p, Lang.get(_SUCCESS), locationName);
                }

            }
        });

    }
}

@@ -1737,24 +1737,25 @@
 guments.
+I
 Location
 Response
@@ -1746,24 +1746,23 @@
 Location
-Response
+Handler
 ;%0Aimport
@@ -3254,24 +3254,25 @@
 n%22, new 
+I
 Location
 Response
@@ -3267,16 +3267,15 @@
 tion
-Response
+Handler
 () %7B
@@ -3350,16 +3350,21 @@
 Player p
+layer
 , Locati
@@ -3537,16 +3537,21 @@
 lError(p
+layer
 , Lang.g
@@ -3605,16 +3605,16 @@
  else %7B%0A
-
         
@@ -3638,16 +3638,21 @@
 uccess(p
+layer
 , Lang.g

rename LocationResponse to ILocationHandler