Better save system

This commit is contained in:
Olof Larsson 2011-03-22 22:31:04 +01:00
parent 39a02f0fd4
commit 8bab4540cd
12 changed files with 37 additions and 42 deletions

View File

@ -51,7 +51,6 @@ public class Board {
}
worldCoordIds.get(flocation.getWorldName()).put(flocation.getCoordString(), id);
save();
}
public static void setFactionAt(Faction faction, FLocation flocation) {
@ -63,7 +62,6 @@ public class Board {
return;
}
worldCoordIds.get(flocation.getWorldName()).remove(flocation.getCoordString());
save();
}
// Is this coord NOT completely surrounded by coords claimed by the same faction?
@ -171,7 +169,7 @@ public class Board {
// -------------------------------------------- //
public static boolean save() {
Factions.log("Saving board to disk");
//Factions.log("Saving board to disk");
try {
DiscUtil.write(file, Factions.gson.toJson(worldCoordIds));

View File

@ -67,7 +67,8 @@ public class Conf {
// -------------------------------------------- //
public static boolean save() {
Factions.log("Saving config to disk.");
//Factions.log("Saving config to disk.");
try {
DiscUtil.write(file, Factions.gson.toJson(new Conf()));
} catch (IOException e) {

View File

@ -164,7 +164,6 @@ public class FPlayer {
public void setTitle(String title) {
this.title = title;
save();
}
public String getName() {
@ -335,7 +334,6 @@ public class FPlayer {
int millisPerMinute = 60*1000;
this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
//this.save(); // This would save to often. So we save this on player quit instead.
}
public void onDeath() {
@ -386,8 +384,6 @@ public class FPlayer {
}
Faction.delete(myFaction.getId());
}
FPlayer.save();
FPlayer.save();
}
// -------------------------------------------- //
@ -454,7 +450,7 @@ public class FPlayer {
}
public static boolean save() {
Factions.log("Saving players to disk");
//Factions.log("Saving players to disk");
// We only wan't to save the vplayers with non default values
Map<String, FPlayer> vplayersToSave = new HashMap<String, FPlayer>();

View File

@ -59,7 +59,6 @@ public class Faction {
public void setOpen(boolean isOpen) {
open = isOpen;
save();
}
public String getTag() {
@ -79,7 +78,6 @@ public class Faction {
str = str.toUpperCase();
}
this.tag = str;
save();
}
public String getDescription() {
@ -88,7 +86,6 @@ public class Faction {
public void setDescription(String value) {
this.description = value;
save();
}
// -------------------------------
@ -124,7 +121,6 @@ public class Faction {
} else {
this.relationWish.put(otherFaction.getId(), relation);
}
Faction.save();
}
public Relation getRelation(Faction otherFaction) {
@ -215,18 +211,6 @@ public class Faction {
return ret;
}
/*
public void removeFollower(FPlayer follower) {
if (this.id != follower.factionId) {
return; // safety check
}
this.invites.remove(follower.id);
follower.resetFactionData();
follower.save();
this.save();
}*/
public ArrayList<Player> getOnlinePlayers() {
ArrayList<Player> ret = new ArrayList<Player>();
for (Player player: Factions.instance.getServer().getOnlinePlayers()) {
@ -314,7 +298,7 @@ public class Faction {
//----------------------------------------------//
public static boolean save() {
Factions.log("Saving factions to disk");
//Factions.log("Saving factions to disk");
try {
DiscUtil.write(file, Factions.gson.toJson(instances));
@ -403,9 +387,5 @@ public class Faction {
// Clean the fplayers
FPlayer.clean();
// SAVE files
Board.save();
FPlayer.save();
}
}

View File

@ -52,6 +52,9 @@ import com.nijikokun.bukkit.Permissions.Permissions;
import me.taylorkelly.help.Help;
/**
* The data is saved to disk every 30min and on plugin disable.
*/
public class Factions extends JavaPlugin {
// -------------------------------------------- //
// Fields
@ -134,16 +137,18 @@ public class Factions extends JavaPlugin {
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_DAMAGED, this.blockListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACED, this.blockListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_INTERACT, this.blockListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_INTERACT, this.blockListener, Event.Priority.Normal, this);
// Register recurring tasks
long saveTicks = 20 * 60 * 30; // Approximately every 30 min
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new SaveTask(), saveTicks, saveTicks);
log("=== INIT DONE (Took "+(System.currentTimeMillis()-timeInitStart)+"ms) ===");
}
@Override
public void onDisable() {
FPlayer.save();
Faction.save();
Board.save();
saveAll();
log("Disabled");
}
@ -232,5 +237,15 @@ public class Factions extends JavaPlugin {
public static void log(Level level, String msg) {
Logger.getLogger("Minecraft").log(level, "["+instance.getDescription().getFullName()+"] "+msg);
}
// -------------------------------------------- //
// Save all
// -------------------------------------------- //
public static void saveAll() {
FPlayer.save();
Faction.save();
Board.save();
}
}

View File

@ -0,0 +1,12 @@
package com.bukkit.mcteam.factions;
public class SaveTask implements Runnable {
//TODO are they removed on disable?
@Override
public void run() {
Factions.saveAll();
}
}

View File

@ -47,8 +47,6 @@ public class FCommandCreate extends FBaseCommand {
faction.setTag(tag);
me.setRole(Role.ADMIN);
me.setFaction(faction);
Faction.save();
FPlayer.save();
for (FPlayer follower : FPlayer.getAllOnline()) {
follower.sendMessage(me.getNameAndRelevant(follower)+Conf.colorSystem+" created a new faction "+faction.getTag(follower));

View File

@ -50,7 +50,6 @@ public class FCommandDeinvite extends FBaseCommand {
}
myFaction.deinvite(you);
Faction.save();
you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" revoked your invitation to "+myFaction.getTag(you));
myFaction.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" revoked "+you.getNameAndRelevant(me)+"'s"+Conf.colorSystem+" invitation.");

View File

@ -34,6 +34,7 @@ public class FCommandDescription extends FBaseCommand {
}
me.getFaction().setDescription(TextUtil.implode(parameters));
// Broadcast the description to everyone
for (FPlayer fplayer : FPlayer.getAllOnline()) {
fplayer.sendMessage("The faction "+fplayer.getRelationColor(me)+me.getFaction().getTag()+Conf.colorSystem+" changed their description to:");

View File

@ -50,7 +50,6 @@ public class FCommandInvite extends FBaseCommand {
}
myFaction.invite(you);
Faction.save();
you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" invited you to "+myFaction.getTag(you));
myFaction.sendMessage(me.getNameAndRelevant(me)+Conf.colorSystem+" invited "+you.getNameAndRelevant(me)+Conf.colorSystem+" to your faction.");

View File

@ -3,7 +3,6 @@ package com.bukkit.mcteam.factions.commands;
import java.util.ArrayList;
import com.bukkit.mcteam.factions.Conf;
import com.bukkit.mcteam.factions.FPlayer;
import com.bukkit.mcteam.factions.Faction;
public class FCommandJoin extends FBaseCommand {
@ -53,7 +52,6 @@ public class FCommandJoin extends FBaseCommand {
me.resetFactionData();
me.setFaction(faction);
faction.deinvite(me);
FPlayer.save();
}
}

View File

@ -51,8 +51,6 @@ public class FCommandKick extends FBaseCommand {
myFaction.deinvite(you);
you.resetFactionData();
FPlayer.save();
Faction.save();
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" kicked "+you.getNameAndRelevant(myFaction)+Conf.colorSystem+" from the faction! :O");
you.sendMessage(me.getNameAndRelevant(you)+Conf.colorSystem+" kicked you from "+myFaction.getTag(you)+Conf.colorSystem+"! :O");