2016-05-12 19:40:39 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
2018-07-31 07:05:28 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
import java.io.ObjectOutputStream;
|
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
|
|
|
|
{
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public Map<String, Boolean> getSavedFlags()
|
|
|
|
{
|
|
|
|
Map<String, Boolean> flags = null;
|
2020-12-26 23:54:15 +00:00
|
|
|
File input = new File(TotalFreedomMod.getPlugin().getDataFolder(), SAVED_FLAGS_FILENAME);
|
2016-05-12 19:40:39 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|