package io.github.vayleryn.vaylerynessentials;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;

public class PortcullisManager {
	
	private boolean entityMovingEnabled;
	private int hoistingDelay, droppingDelay;
	private Set<Material> portcullisMaterials, powerBlocks;
	private boolean allowFloating, allPowerBlocksAllowed;
	private static final int DEFAULT_HOISTING_DELAY = 40, DEFAULT_DROPPING_DELAY = 10;
	private static final Set<Material> DEFAULT_PORTCULLIS_MATERIALS = new HashSet<Material>(Arrays.asList(Material.FENCE, Material.IRON_FENCE, Material.NETHER_FENCE));
	private static final boolean DEFAULT_ALLOW_FLOATING = true;
	
	public PortcullisManager(VaylerynEssentials plugin) {
		plugin.saveDefaultPortcullisConfig();
		FileConfiguration config = plugin.getPortcullisConfig();
		entityMovingEnabled = config.getBoolean("entityMoving");
		hoistingDelay = config.getInt("hoistingDelay");
		droppingDelay = config.getInt("droppingDelay");
		portcullisMaterials = new HashSet<Material>();
		for (String material : config.getStringList("portcullisMaterials")) {
			portcullisMaterials.add(Material.matchMaterial(material));
		}
		portcullisMaterials = Collections.unmodifiableSet(portcullisMaterials);
		allowFloating = config.getBoolean("allowFloating");
		powerBlocks = new HashSet<Material>();
		for (String material : config.getStringList("powerBlocks")) {
			powerBlocks.add(Material.matchMaterial(material));
		}
		powerBlocks = Collections.unmodifiableSet(powerBlocks);
		allPowerBlocksAllowed = powerBlocks.isEmpty();
		List<String> warnings = new ArrayList<String>();
		if (hoistingDelay != DEFAULT_HOISTING_DELAY) {
			warnings.add("hoisting speed " + hoistingDelay);
		}
		if (droppingDelay != DEFAULT_DROPPING_DELAY) {
			warnings.add("dropping speed " + droppingDelay);
		}
		if (!portcullisMaterials.equals(DEFAULT_PORTCULLIS_MATERIALS)) {
			warnings.add("portcullis materials " + portcullisMaterials);
		}
		if (allowFloating != DEFAULT_ALLOW_FLOATING) {
			warnings.add("floating not allowed");
		}
		if (!allPowerBlocksAllowed) {
			warnings.add("power blocks allowed " + powerBlocks);
		}
		if (!warnings.isEmpty()) {
			StringBuilder sb = new StringBuilder("[PorteCoulissante] Non-standard configuration items loaded from config file: ");
			boolean first = true;
			for (String warning : warnings) {
				if (first) {
					first = false;
				} else {
					sb.append(", ");
				}
				sb.append(warning);
			}
		}
	}
	
	public boolean isEntityMovingEnabled() {
		return entityMovingEnabled;
	}
	
	public int getDroppingDelay() {
		return droppingDelay;
	}
	
	public int getHoistingDelay() {
		return hoistingDelay;
	}
	
	public Set<Material> getPortcullisMaterials() {
		return portcullisMaterials;
	}
	
	public Set<Material> getPowerBlocks() {
		return powerBlocks;
	}
	
	public boolean isAllowFloating() {
		return allowFloating;
	}
	
	public boolean isAllPowerBlocksAllowed() {
		return allPowerBlocksAllowed;
	}
	
}

@@ -45,61 +45,8 @@
 s;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.Arrays;%0A
 impo
@@ -71,16 +71,16 @@
 ctions;%0A
+
 import j
@@ -101,31 +101,8 @@
 et;%0A
-import java.util.List;%0A
 impo
@@ -437,320 +437,8 @@
 ed;%0A
-%09private static final int DEFAULT_HOISTING_DELAY = 40, DEFAULT_DROPPING_DELAY = 10;%0A%09private static final Set%3CMaterial%3E DEFAULT_PORTCULLIS_MATERIALS = new HashSet%3CMaterial%3E(Arrays.asList(Material.FENCE, Material.IRON_FENCE, Material.NETHER_FENCE));%0A%09private static final boolean DEFAULT_ALLOW_FLOATING = true;%0A%09%0A
 %09pub
@@ -1278,24 +1278,24 @@
 werBlocks);%0A
+
 %09%09allPowerBl
@@ -1335,914 +1335,8 @@
 ();%0A
-%09%09List%3CString%3E warnings = new ArrayList%3CString%3E();%0A%09%09if (hoistingDelay != DEFAULT_HOISTING_DELAY) %7B%0A%09%09%09warnings.add(%22hoisting speed %22 + hoistingDelay);%0A%09%09%7D%0A%09%09if (droppingDelay != DEFAULT_DROPPING_DELAY) %7B%0A%09%09%09warnings.add(%22dropping speed %22 + droppingDelay);%0A%09%09%7D%0A%09%09if (!portcullisMaterials.equals(DEFAULT_PORTCULLIS_MATERIALS)) %7B%0A%09%09%09warnings.add(%22portcullis materials %22 + portcullisMaterials);%0A%09%09%7D%0A%09%09if (allowFloating != DEFAULT_ALLOW_FLOATING) %7B%0A%09%09%09warnings.add(%22floating not allowed%22);%0A%09%09%7D%0A%09%09if (!allPowerBlocksAllowed) %7B%0A%09%09%09warnings.add(%22power blocks allowed %22 + powerBlocks);%0A%09%09%7D%0A%09%09if (!warnings.isEmpty()) %7B%0A%09%09%09StringBuilder sb = new StringBuilder(%22%5BPorteCoulissante%5D Non-standard configuration items loaded from config file: %22);%0A%09%09%09boolean first = true;%0A%09%09%09for (String warning : warnings) %7B%0A%09%09%09%09if (first) %7B%0A%09%09%09%09%09first = false;%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09sb.append(%22, %22);%0A%09%09%09%09%7D%0A%09%09%09%09sb.append(warning);%0A%09%09%09%7D%0A%09%09%7D%0A
 %09%7D%0A%09

Remove warnings on portcullises