2016-05-12 19:40:39 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
2018-07-31 07:01:29 +00:00
|
|
|
import java.io.*;
|
2016-05-12 19:40:39 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import static me.totalfreedom.totalfreedommod.util.FUtil.SAVED_FLAGS_FILENAME;
|
|
|
|
|
|
|
|
public class SavedFlags extends FreedomService
|
|
|
|
{
|
|
|
|
|
|
|
|
public SavedFlags(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public Map<String, Boolean> getSavedFlags()
|
|
|
|
{
|
|
|
|
Map<String, Boolean> flags = null;
|
|
|
|
|
|
|
|
File input = new File(TotalFreedomMod.plugin().getDataFolder(), SAVED_FLAGS_FILENAME);
|
|
|
|
if (input.exists())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
try (FileInputStream fis = new FileInputStream(input); ObjectInputStream ois = new ObjectInputStream(fis))
|
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
flags = (HashMap<String, Boolean>)ois.readObject();
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
FLog.severe(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getSavedFlag(String flag) throws Exception
|
|
|
|
{
|
|
|
|
Boolean flagValue = null;
|
|
|
|
|
|
|
|
Map<String, Boolean> flags = getSavedFlags();
|
|
|
|
|
|
|
|
if (flags != null)
|
|
|
|
{
|
|
|
|
if (flags.containsKey(flag))
|
|
|
|
{
|
|
|
|
flagValue = flags.get(flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flagValue != null)
|
|
|
|
{
|
|
|
|
return flagValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSavedFlag(String flag, boolean value)
|
|
|
|
{
|
|
|
|
Map<String, Boolean> flags = getSavedFlags();
|
|
|
|
|
|
|
|
if (flags == null)
|
|
|
|
{
|
|
|
|
flags = new HashMap<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.put(flag, value);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder(), SAVED_FLAGS_FILENAME));
|
|
|
|
final ObjectOutputStream oos = new ObjectOutputStream(fos);
|
|
|
|
oos.writeObject(flags);
|
|
|
|
oos.close();
|
|
|
|
fos.close();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
FLog.severe(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|