Initial async saving on auto save and force save.
This commit is contained in:
parent
f76fc190fd
commit
1a94e89558
@ -80,5 +80,7 @@ public abstract class Board {
|
|||||||
|
|
||||||
public abstract boolean forceSave();
|
public abstract boolean forceSave();
|
||||||
|
|
||||||
|
public abstract boolean forceSave(boolean sync);
|
||||||
|
|
||||||
public abstract boolean load();
|
public abstract boolean load();
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ public abstract class FPlayers {
|
|||||||
|
|
||||||
public abstract void forceSave();
|
public abstract void forceSave();
|
||||||
|
|
||||||
|
public abstract void forceSave(boolean sync);
|
||||||
|
|
||||||
public abstract FPlayer getByOfflinePlayer(OfflinePlayer player);
|
public abstract FPlayer getByOfflinePlayer(OfflinePlayer player);
|
||||||
|
|
||||||
public abstract FPlayer getById(String string);
|
public abstract FPlayer getById(String string);
|
||||||
|
@ -37,6 +37,8 @@ public abstract class Factions {
|
|||||||
|
|
||||||
public abstract void forceSave();
|
public abstract void forceSave();
|
||||||
|
|
||||||
|
public abstract void forceSave(boolean sync);
|
||||||
|
|
||||||
public static Factions getInstance() {
|
public static Factions getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ public class P extends MPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postAutoSave() {
|
public void postAutoSave() {
|
||||||
Board.getInstance().forceSave();
|
//Board.getInstance().forceSave(); Not sure why this was there as it's called after the board is already saved.
|
||||||
Conf.save();
|
Conf.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ public class CmdSaveAll extends FCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void perform() {
|
public void perform() {
|
||||||
FPlayers.getInstance().forceSave();
|
FPlayers.getInstance().forceSave(false);
|
||||||
Factions.getInstance().forceSave();
|
Factions.getInstance().forceSave(false);
|
||||||
Board.getInstance().forceSave();
|
Board.getInstance().forceSave(false);
|
||||||
Conf.save();
|
Conf.save();
|
||||||
msg(TL.COMMAND_SAVEALL_SUCCESS);
|
msg(TL.COMMAND_SAVEALL_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,9 @@ public class SaveTask implements Runnable {
|
|||||||
}
|
}
|
||||||
running = true;
|
running = true;
|
||||||
p.preAutoSave();
|
p.preAutoSave();
|
||||||
Factions.getInstance().forceSave();
|
Factions.getInstance().forceSave(false);
|
||||||
FPlayers.getInstance().forceSave();
|
FPlayers.getInstance().forceSave(false);
|
||||||
Board.getInstance().forceSave();
|
Board.getInstance().forceSave(false);
|
||||||
p.postAutoSave();
|
p.postAutoSave();
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.massivecraft.factions.FLocation;
|
|||||||
import com.massivecraft.factions.P;
|
import com.massivecraft.factions.P;
|
||||||
import com.massivecraft.factions.zcore.persist.MemoryBoard;
|
import com.massivecraft.factions.zcore.persist.MemoryBoard;
|
||||||
import com.massivecraft.factions.zcore.util.DiscUtil;
|
import com.massivecraft.factions.zcore.util.DiscUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@ -63,14 +64,30 @@ public class JSONBoard extends MemoryBoard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean forceSave() {
|
public boolean forceSave() {
|
||||||
//Factions.log("Saving board to disk");
|
return forceSave(true);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
public boolean forceSave(boolean sync) {
|
||||||
DiscUtil.write(file, P.p.gson.toJson(dumpAsSaveFormat()));
|
if (sync) {
|
||||||
} catch (Exception e) {
|
try {
|
||||||
e.printStackTrace();
|
DiscUtil.write(file, P.p.gson.toJson(dumpAsSaveFormat()));
|
||||||
P.p.log("Failed to save the board to disk.");
|
} catch (Exception e) {
|
||||||
return false;
|
e.printStackTrace();
|
||||||
|
P.p.log("Failed to save the board to disk.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(P.p, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
DiscUtil.write(file, P.p.gson.toJson(dumpAsSaveFormat()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
P.p.log("Failed to save the board to disk.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -51,13 +51,27 @@ public class JSONFPlayers extends MemoryFPlayers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void forceSave() {
|
public void forceSave() {
|
||||||
Map<String, JSONFPlayer> entitiesThatShouldBeSaved = new HashMap<String, JSONFPlayer>();
|
forceSave(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forceSave(boolean sync) {
|
||||||
|
final Map<String, JSONFPlayer> entitiesThatShouldBeSaved = new HashMap<String, JSONFPlayer>();
|
||||||
for (FPlayer entity : this.fPlayers.values()) {
|
for (FPlayer entity : this.fPlayers.values()) {
|
||||||
if (((MemoryFPlayer) entity).shouldBeSaved()) {
|
if (((MemoryFPlayer) entity).shouldBeSaved()) {
|
||||||
entitiesThatShouldBeSaved.put(entity.getId(), (JSONFPlayer) entity);
|
entitiesThatShouldBeSaved.put(entity.getId(), (JSONFPlayer) entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.saveCore(this.file, entitiesThatShouldBeSaved);
|
|
||||||
|
if (sync) {
|
||||||
|
saveCore(file, entitiesThatShouldBeSaved);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(P.p, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
saveCore(file, entitiesThatShouldBeSaved);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean saveCore(File target, Map<String, JSONFPlayer> data) {
|
private boolean saveCore(File target, Map<String, JSONFPlayer> data) {
|
||||||
|
@ -53,12 +53,25 @@ public class JSONFactions extends MemoryFactions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void forceSave() {
|
public void forceSave() {
|
||||||
Map<String, JSONFaction> entitiesThatShouldBeSaved = new HashMap<String, JSONFaction>();
|
forceSave(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forceSave(boolean sync) {
|
||||||
|
final Map<String, JSONFaction> entitiesThatShouldBeSaved = new HashMap<String, JSONFaction>();
|
||||||
for (Faction entity : this.factions.values()) {
|
for (Faction entity : this.factions.values()) {
|
||||||
entitiesThatShouldBeSaved.put(entity.getId(), (JSONFaction) entity);
|
entitiesThatShouldBeSaved.put(entity.getId(), (JSONFaction) entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveCore(this.file, entitiesThatShouldBeSaved);
|
if (sync) {
|
||||||
|
saveCore(file, entitiesThatShouldBeSaved);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(P.p, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
saveCore(file, entitiesThatShouldBeSaved);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean saveCore(File target, Map<String, JSONFaction> entities) {
|
private boolean saveCore(File target, Map<String, JSONFaction> entities) {
|
||||||
|
Loading…
Reference in New Issue
Block a user