2013-12-27 23:59:59 +01:00
|
|
|
package appeng.util;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import appeng.api.util.IConfigManager;
|
2014-02-17 01:50:25 +01:00
|
|
|
import appeng.core.AELog;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public class ConfigManager implements IConfigManager
|
|
|
|
{
|
|
|
|
|
|
|
|
HashMap<Enum, Enum> Settings = new HashMap();
|
|
|
|
IConfigManagerHost target;
|
|
|
|
|
|
|
|
public ConfigManager(IConfigManagerHost tile) {
|
|
|
|
target = tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* read all settings using config manager.
|
|
|
|
*
|
|
|
|
* @param tagCompound
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
|
|
|
for (Enum key : Settings.keySet())
|
|
|
|
{
|
2014-02-17 01:50:25 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( tagCompound.hasKey( key.name() ) )
|
|
|
|
{
|
|
|
|
String value = tagCompound.getString( key.name() );
|
|
|
|
|
|
|
|
Enum oldValue = Settings.get( key );
|
|
|
|
Enum newValue = Enum.valueOf( oldValue.getClass(), value );
|
|
|
|
|
|
|
|
putSetting( key, newValue );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* save all settings using config manager.
|
|
|
|
*
|
|
|
|
* @param tagCompound
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (Enum e : Settings.keySet())
|
|
|
|
{
|
2013-12-30 06:52:36 +01:00
|
|
|
tagCompound.setString( e.name(), Settings.get( e ).toString() );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Set<Enum> getSettings()
|
|
|
|
{
|
|
|
|
return Settings.keySet();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void registerSetting(Enum settingName, Enum defaultValue)
|
|
|
|
{
|
|
|
|
Settings.put( settingName, defaultValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enum getSetting(Enum settingName)
|
|
|
|
{
|
|
|
|
Enum oldValue = Settings.get( settingName );
|
|
|
|
|
|
|
|
if ( oldValue != null )
|
|
|
|
return oldValue;
|
|
|
|
|
|
|
|
throw new RuntimeException( "Invalid Config setting" );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Enum putSetting(Enum settingName, Enum newValue)
|
|
|
|
{
|
|
|
|
Enum oldValue = getSetting( settingName );
|
|
|
|
Settings.put( settingName, newValue );
|
2014-02-17 01:50:25 +01:00
|
|
|
target.updateSetting( this, settingName, newValue );
|
2013-12-27 23:59:59 +01:00
|
|
|
return oldValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|