package net.mc_pandacraft.java.plugin.pandacraftutils.config;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import org.bukkit.World;

import net.mc_pandacraft.java.plugin.pandacraftutils.config.elements.WorldBorderConfigEntry;

public class WorldBorderConfig extends AbstractConfig {
	
	private HashMap<String, WorldBorderConfigEntry> config;
	
	public WorldBorderConfig() throws IOException {
		super("worldborder.txt", FileType.FILE);
		
		
		List<String> configLines = getFileLines(true, true, true);
		
		config = new HashMap<String, WorldBorderConfigEntry>();
		
		for (String line : configLines) {
			String[] lineSplit = line.split(" ");
			if (lineSplit.length != 4) {
				warning("mauvait format de ligne : "+line);
				continue;
			}
			if (lineSplit[0].equals("")) {
				warning("mauvait format de ligne : "+line);
				continue;
			}
			
			String worldName = lineSplit[0];
			float x, z, r;
			
			try {
				x = Float.parseFloat(lineSplit[1]);
				z = Float.parseFloat(lineSplit[2]);
				r = Float.parseFloat(lineSplit[3]);
			} catch (NumberFormatException e) {
				warning("mauvait format de ligne : "+line);
				continue;
			}
			
			config.put(worldName, new WorldBorderConfigEntry(x, z, r));
			
		}
		
		
		
		
		
	}
	
	
	public WorldBorderConfigEntry getEntry(String world) {
		return config.get(world);
	}
	
	public WorldBorderConfigEntry getEntry(World world) {
		return getEntry(world.getName());
	}
	
	
	
	
	
}
