package uk.co.eluinhost.ultrahardcore.features.portals;

import org.bukkit.TravelAgent;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerPortalEvent;
import uk.co.eluinhost.configuration.ConfigManager;
import uk.co.eluinhost.ultrahardcore.features.UHCFeature;

public class PortalsFeature extends UHCFeature {

    /**
     * Changes the radius portals will connect, normal when disabled
     */
    public PortalsFeature() {
        super("PortalRanges","Change the radius portals can spawn in");
    }

    /**
     * When a portal event happends
     * @param entityPortalEvent the portal event
     */
    @EventHandler
    public void onPortalEvent(PlayerPortalEvent entityPortalEvent) {
        //if we're enabled
        if (isEnabled()) {
            //get the config
            FileConfiguration config = ConfigManager.getInstance().getConfig();

            //create a travel agent for the portal
            TravelAgent ta = entityPortalEvent.getPortalTravelAgent();

            //if they're in the nether
            if (entityPortalEvent.getPlayer().getWorld().getEnvironment() == World.Environment.NETHER) {

                //set data from the nether
                ta.setCanCreatePortal(config.getBoolean(ConfigNodes.PORTAL_RANGES_FROM_NETHER_ALLOWED));
                ta.setCreationRadius(config.getInt(ConfigNodes.PORTAL_RANGES_FROM_NETHER_CREATION));
                ta.setSearchRadius(config.getInt(ConfigNodes.PORTAL_RANGES_FROM_NETHER_SEARCH));
            } else {

                //set the data to the nether
                ta.setCanCreatePortal(config.getBoolean(ConfigNodes.PORTAL_RANGES_TO_NETHER_ALLOWED));
                ta.setCreationRadius(config.getInt(ConfigNodes.PORTAL_RANGES_TO_NETHER_CREATION));
                ta.setSearchRadius(config.getInt(ConfigNodes.PORTAL_RANGES_TO_NETHER_SEARCH));
            }
        }
    }
}

@@ -407,24 +407,153 @@
 CFeature %7B%0A%0A
+    public static final String FROM_NETHER_NODE = %22from_nether.%22;%0A    public static final String TO_NETHER_NODE = %22to_nether.%22;%0A%0A
     /**%0A    
@@ -1457,53 +1457,50 @@
 ean(
-ConfigNodes.PORTAL_RANGES_FROM_NETHER_ALLOWED
+getBaseConfig()+FROM_NETHER_NODE+%22allowed%22
 ));%0A
@@ -1554,54 +1554,57 @@
 Int(
-ConfigNodes.PORTAL_RANGES_FROM_NETHER_CREATION
+getBaseConfig()+FROM_NETHER_NODE+%22creation_range%22
 ));%0A
@@ -1656,52 +1656,55 @@
 Int(
-ConfigNodes.PORTAL_RANGES_FROM_NETHER_SEARCH
+getBaseConfig()+FROM_NETHER_NODE+%22search_range%22
 ));%0A
@@ -1830,51 +1830,48 @@
 ean(
-ConfigNodes.PORTAL_RANGES_TO_NETHER_ALLOWED
+getBaseConfig()+TO_NETHER_NODE+%22allowed%22
 ));%0A
@@ -1925,52 +1925,55 @@
 Int(
-ConfigNodes.PORTAL_RANGES_TO_NETHER_CREATION
+getBaseConfig()+TO_NETHER_NODE+%22creation_range%22
 ));%0A
@@ -2025,50 +2025,53 @@
 Int(
-ConfigNodes.PORTAL_RANGES_TO_NETHER_SEARCH
+getBaseConfig()+TO_NETHER_NODE+%22search_range%22
 ));%0A

update portals feature