package goldenapple.omnidrills.config;

import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import goldenapple.omnidrills.reference.Reference;
import goldenapple.omnidrills.util.LogHelper;
import net.minecraftforge.common.config.Configuration;

import java.io.File;

public class ConfigHandler {
    public Configuration config; //public because of OmniDrillsGuiConfig

    public static String energyUnitName;
    public static EnumEnergyUnit energyUnit;

    public ConfigHandler(File file){
        if(config == null) {
            config = new Configuration(file);
        }
        loadConfig();
    }

    private void loadConfig(){
        energyUnitName = config.getString("energyUnit", Configuration.CATEGORY_GENERAL, "RF", "Energy unit to display in tooltips. Valid units: EU, RF, gJ (GalactiCraft Joules), J (Mekanism Joules)", new String[]{"RF", "EU", "gJ", "J"});

        if(energyUnitName.equals("EU")){
            LogHelper.info("Using EU");
            energyUnit = EnumEnergyUnit.EU;
        }else if(energyUnitName.equals("J")){
            LogHelper.info("Using Joules");
            energyUnit = EnumEnergyUnit.J;
        }else if(energyUnitName.equals("gJ")){
            LogHelper.info("Using Galacticraft Joules");
            energyUnit = EnumEnergyUnit.gJ;
        }else {
            LogHelper.info("Using RF");
            energyUnit = EnumEnergyUnit.RF;
        }

        if(config.hasChanged()){
            config.save();
        }
    }

    @SubscribeEvent
    public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event){
        if(event.modID.equals(Reference.MOD_ID)){
            loadConfig();
        }
    }
}

@@ -504,16 +504,36 @@
 ergyUnit
+ = EnumEnergyUnit.RF
 ;%0A%0A    p
@@ -993,48 +993,8 @@
 ))%7B%0A
-            LogHelper.info(%22Using EU%22);%0A
     
@@ -1083,52 +1083,8 @@
 ))%7B%0A
-            LogHelper.info(%22Using Joules%22);%0A
     
@@ -1185,52 +1185,86 @@
     
-LogHelper.info(%22Using Galacticraft Joules%22);
+energyUnit = EnumEnergyUnit.gJ;%0A        %7Delse if(energyUnitName.equals(%22RF%22))%7B
 %0A   
@@ -1292,34 +1292,34 @@
  EnumEnergyUnit.
-gJ
+RF
 ;%0A        %7Delse 
@@ -1317,17 +1317,16 @@
    %7Delse
- 
 %7B%0A      
@@ -1351,62 +1351,54 @@
 fo(%22
-Using RF%22);%0A            energyUnit = EnumEnergyUnit.RF
+Invalid EnergyUnit value. Using default (RF)%22)
 ;%0A  

Fix ConfigHandler