package ljfa.tntutils;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

import net.minecraftforge.common.config.Configuration;
import scala.actors.threadpool.Arrays;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class Config {
    public static Configuration conf;

    public static final String CATEGORY_GENERAL = "general";
    
    public static boolean replaceTNT;
    public static boolean explosionCommand;
    public static boolean spareTileEntities;
    public static Set<String> blacklist;
    public static boolean blacklistActive;
    
    public static void loadConfig(File file) {
        if(conf == null)
            conf = new Configuration(file);
        
        conf.load();
        loadValues();
        
        FMLCommonHandler.instance().bus().register(new ChangeHandler());
    }
    
    public static void loadValues() {
        replaceTNT = conf.getBoolean("preventChainExplosions", CATEGORY_GENERAL, true, "Prevent explosions from triggering TNT");
        explosionCommand = conf.getBoolean("addExplosionCommand", CATEGORY_GENERAL, true, "Adds the \"/explosion\" command");
        spareTileEntities = conf.getBoolean("spareTileEntites", CATEGORY_GENERAL, false, "Makes explosions not destroy tile entities");
        blacklist = processBlacklist(conf.getStringList("destructionBlacklist", CATEGORY_GENERAL, new String[0], "A list of blocks that will never be destroyed by explosions"));
        blacklistActive = blacklist.size() != 0;
        //----------------
        if(conf.hasChanged())
            conf.save();
    }
    
    private static Set<String> processBlacklist(String[] array) {
        Set<String> set = new HashSet<String>(2 * array.length);
        for(String name: array)
            set.add("tile." + name);
        return set;
    }
    
    /** Reloads the config values upon change */
    public static class ChangeHandler {
        @SubscribeEvent
        public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
            if(event.modID.equals(Reference.MODID))
                loadValues();
        }
    }
}

@@ -1007,24 +1007,35 @@
 conf.get
-Boolean(
+(CATEGORY_GENERAL, 
 %22prevent
@@ -1051,34 +1051,16 @@
 osions%22,
- CATEGORY_GENERAL,
  true, %22
@@ -1099,16 +1099,56 @@
 ng TNT%22)
+.setRequiresMcRestart(true).getBoolean()
 ;%0A      
@@ -1176,24 +1176,35 @@
 conf.get
-Boolean(
+(CATEGORY_GENERAL, 
 %22addExpl
@@ -1217,34 +1217,16 @@
 ommand%22,
- CATEGORY_GENERAL,
  true, %22
@@ -1262,90 +1262,123 @@
 nd%22)
-;%0A        spareTileEntities = conf.getBoolean(%22spareTileEntites%22, CATEGORY_GENERAL
+.setRequiresMcRestart(true).getBoolean();%0A        spareTileEntities = conf.get(CATEGORY_GENERAL, %22spareTileEntites%22
 , fa
@@ -1427,16 +1427,29 @@
 tities%22)
+.getBoolean()
 ;%0A      
@@ -1491,19 +1491,27 @@
 .get
-StringList(
+(CATEGORY_GENERAL, 
 %22des
@@ -1533,26 +1533,8 @@
 st%22,
- CATEGORY_GENERAL,
  new
@@ -1607,16 +1607,32 @@
 osions%22)
+.getStringList()
 );%0A     

Switch to the other config get-function variant