/* 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.bukkit.arborianquests.scriptapi;

import com.jcwhatever.bukkit.arborianquests.ArborianQuests;
import com.jcwhatever.bukkit.arborianquests.locations.ScriptLocation;
import com.jcwhatever.bukkit.generic.scripting.IEvaluatedScript;
import com.jcwhatever.bukkit.generic.scripting.IScriptApiInfo;
import com.jcwhatever.bukkit.generic.scripting.api.GenericsScriptApi;
import com.jcwhatever.bukkit.generic.scripting.api.IScriptApiObject;
import com.jcwhatever.bukkit.generic.utils.PreCon;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;

import javax.annotation.Nullable;

@IScriptApiInfo(
        variableName = "locations",
        description = "Get quest scriptable locations.")
public class ScriptLocations extends GenericsScriptApi {

    /**
     * Constructor.
     *
     * @param plugin The owning plugin
     */
    public ScriptLocations(Plugin plugin) {
        super(plugin);
    }

    @Override
    public IScriptApiObject getApiObject(IEvaluatedScript script) {
        return new ApiObject();
    }

    public static class ApiObject implements IScriptApiObject {

        @Override
        public void reset() {
            // do nothing
        }

        /**
         * Get a quest script location by name.
         *
         * @param name  The name of the location.
         */
        @Nullable
        public Location get(String name) {
            PreCon.notNullOrEmpty(name);

            ScriptLocation result = ArborianQuests.getPlugin().getScriptLocationManager().getLocation(name);
            if (result == null)
                return null;

            return result.getLocation();
        }
    }
}

@@ -1720,24 +1720,25 @@
 ils.PreCon;%0A
+%0A
 import org.b
@@ -1783,24 +1783,47 @@
 in.Plugin;%0A%0A
+import java.util.List;%0A
 import javax
@@ -1886,17 +1886,22 @@
 Name = %22
-l
+questL
 ocations
@@ -2902,16 +2902,243 @@
        %7D
+%0A%0A        /**%0A         * Get all script location objects.%0A         */%0A        public List%3CScriptLocation%3E getScriptLocations() %7B%0A            return ArborianQuests.getPlugin().getScriptLocationManager().getLocations();%0A        %7D
 %0A    %7D%0A%7D

add getScriptLocations method