2020-10-27 21:56:05 +00:00
|
|
|
package me.totalfreedom.plex.rank;
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
2020-10-28 03:49:56 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
2020-10-27 21:56:05 +00:00
|
|
|
import me.totalfreedom.plex.Plex;
|
|
|
|
import me.totalfreedom.plex.rank.enums.Rank;
|
|
|
|
import me.totalfreedom.plex.util.PlexLog;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
public class RankManager
|
|
|
|
{
|
2020-10-28 03:49:56 +00:00
|
|
|
private final File defaultRanks;
|
2020-10-27 21:56:05 +00:00
|
|
|
|
|
|
|
public RankManager()
|
|
|
|
{
|
|
|
|
defaultRanks = new File(new File(Plex.get().getDataFolder() + File.separator + "ranks"), "default-ranks.json");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void generateDefaultRanks()
|
|
|
|
{
|
|
|
|
if (defaultRanks.exists())
|
|
|
|
{
|
|
|
|
return;
|
2020-10-28 03:49:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-10-27 21:56:05 +00:00
|
|
|
defaultRanks.createNewFile();
|
|
|
|
|
|
|
|
List<DefaultRankObj> ranks = Lists.newArrayList();
|
|
|
|
for (Rank rank : Rank.values())
|
|
|
|
{
|
|
|
|
ranks.add(new DefaultRankObj(rank));
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject obj = new JSONObject();
|
|
|
|
if (obj.length() == 0)
|
|
|
|
{
|
|
|
|
obj.put("ranks", ranks);
|
|
|
|
|
|
|
|
FileWriter writer = new FileWriter(defaultRanks);
|
|
|
|
writer.append(obj.toString(4));
|
|
|
|
writer.flush();
|
|
|
|
writer.close();
|
|
|
|
PlexLog.log("Generating default-ranks.json");
|
|
|
|
}
|
2020-10-28 03:49:56 +00:00
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
2020-10-27 21:56:05 +00:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|