package com.gmail.nossr50.config;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

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

import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.metrics.MetricsManager;

public abstract class ConfigLoader {
    protected static final mcMMO plugin = mcMMO.p;
    protected String fileName;
    protected File configFile;
    protected FileConfiguration config;

    public ConfigLoader(String relativePath, String fileName) {
        this.fileName = fileName;
        configFile = new File(plugin.getDataFolder(), relativePath + File.separator + fileName);
        loadFile();
    }

    public ConfigLoader(String fileName) {
        this.fileName = fileName;
        configFile = new File(plugin.getDataFolder(), fileName);
        loadFile();
    }

    protected void loadFile() {
        if (!configFile.exists()) {
            plugin.getLogger().info("Creating mcMMO " + fileName + " File...");
            createFile();
        }
        else {
            plugin.getLogger().info("Loading mcMMO " + fileName + " File...");
        }

        config = YamlConfiguration.loadConfiguration(configFile);
    }

    protected abstract void loadKeys();

    protected void createFile() {
        if (configFile.exists()) {
            return;
        }

        configFile.getParentFile().mkdirs();

        InputStream inputStream = plugin.getResource(fileName);

        if (inputStream != null) {
            try {
                copyStreamToFile(inputStream, configFile);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        else {
            plugin.getLogger().severe("Missing resource file: '" + fileName + "' please notify the plugin authors");
        }
    }

    private static void copyStreamToFile(InputStream inputStream, File file) throws Exception {
        OutputStream outputStream = new FileOutputStream(file);

        int read = 0;
        byte[] bytes = new byte[1024];

        while ((read = inputStream.read(bytes)) != -1) {
            outputStream.write(bytes, 0, read);
        }

        inputStream.close();
        outputStream.close();
    }
}

@@ -34,72 +34,8 @@
 %0D%0A%0D%0A
-import java.io.BufferedReader;%0D%0Aimport java.io.BufferedWriter;%0D%0A
 impo
@@ -90,36 +90,8 @@
 m;%0D%0A
-import java.io.FileWriter;%0D%0A
 impo
@@ -134,132 +134,20 @@
 .io.
-InputStreamReader;%0D%0Aimport java.io.OutputStream;%0D%0Aimport java.util.HashMap;%0D%0Aimport java.util.HashSet;%0D%0Aimport java.util.Set
+OutputStream
 ;%0D%0A%0D
@@ -299,63 +299,8 @@
 MO;%0D
-%0Aimport com.gmail.nossr50.util.metrics.MetricsManager;%0D
 %0A%0D%0Ap

Remove unused imports.