Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.expdev.gkitpvp.persist.json;
- import com.google.gson.Gson;
- import me.expdev.gkitpvp.GKitPvPPlugin;
- import me.expdev.gkitpvp.GLocation;
- import me.expdev.gkitpvp.utils.DiscUtil;
- import java.io.File;
- /**
- * Project created by ExpDev
- */
- public class JSONSpawn extends JSONPoints {
- // Info on how to persist
- private Gson gson;
- private File file;
- public JSONSpawn() {
- file = new File(GKitPvPPlugin.p.getDataFolder(), "spawn.json");
- gson = GKitPvPPlugin.gson;
- }
- public Gson getGson() {
- return gson;
- }
- public void setGson(Gson gson) {
- this.gson = gson;
- }
- public void forceSave() {
- forceSave(true);
- }
- public void forceSave(boolean sync) {
- saveCore(file, this.spawn, sync);
- }
- private boolean saveCore(File target, GLocation data, boolean sync) {
- return DiscUtil.writeCatch(target, this.gson.toJson(data), sync);
- }
- public void load() {
- GLocation spawn = this.loadCore();
- if (spawn == null) {
- return;
- }
- this.spawn = spawn;
- GKitPvPPlugin.p.log("Loaded spawn.");
- }
- private GLocation loadCore() {
- if (!this.file.exists()) {
- return null;
- }
- String content = DiscUtil.readCatch(this.file);
- if (content == null) {
- return null;
- }
- GLocation data = this.gson.fromJson(content, GLocation.class);
- saveCore(this.file, data, true); // Update the flatfile
- return data;
- }
- }
Add Comment
Please, Sign In to add comment