If we have converted data, save everything after JailIO is loaded.

This might solve #26 but I'm not closing it yet as this is untested.
This commit is contained in:
graywolf336 2014-05-03 01:12:26 -05:00
parent 42d0e7983f
commit ef5dfe3815
3 changed files with 34 additions and 2 deletions

View File

@ -643,6 +643,21 @@ public class JailIO {
pl.getLogger().severe("Failed to load the jail " + j.getName() + " as the world '" + j.getWorldName() + "' does not exist (is null). Did you remove this world?"); pl.getLogger().severe("Failed to load the jail " + j.getName() + " as the world '" + j.getWorldName() + "' does not exist (is null). Did you remove this world?");
} }
/** Saves everything about a jail, don't usually call this. */
public void saveEverything() {
long st = System.currentTimeMillis();
for(Jail j : pl.getJailManager().getJails()) {
saveJail(j);
for(Cell c : j.getCells()) {
saveCell(j, c);
}
}
pl.debug("Saving everything took " + (System.currentTimeMillis() - st) + " millis.");
}
/** /**
* Saves the provided {@link Jail jail} to the storage system we are using. * Saves the provided {@link Jail jail} to the storage system we are using.
* *

View File

@ -51,8 +51,8 @@ public class JailMain extends JavaPlugin {
//Try to load the old stuff before we load anything, esp the storage stuff //Try to load the old stuff before we load anything, esp the storage stuff
LegacyManager lm = new LegacyManager(this); LegacyManager lm = new LegacyManager(this);
if(lm.doWeNeedToConvert()) { if(lm.doWeNeedToConvert()) {
boolean converted = lm.convertOldData(); lm.convertOldData();
if(!converted) getLogger().severe("We was unable to convert some, or all, of the old data."); if(!lm.wasAnythingConverted()) getLogger().severe("We was unable to convert some, or all, of the old data.");
} }
io = new JailIO(this); io = new JailIO(this);
@ -67,6 +67,11 @@ public class JailMain extends JavaPlugin {
io.loadJails(); io.loadJails();
//If we converted something, let's save EVERYTHING including the cells
if(lm.wasAnythingConverted()) {
io.saveEverything();
}
cmdHand = new CommandHandler(this); cmdHand = new CommandHandler(this);
jh = new JailHandler(this); jh = new JailHandler(this);
pm = new PrisonerManager(this); pm = new PrisonerManager(this);

View File

@ -27,9 +27,11 @@ import com.graywolf336.jail.enums.Settings;
public class LegacyManager { public class LegacyManager {
private JailMain pl; private JailMain pl;
private YamlConfiguration global; private YamlConfiguration global;
private boolean wasConverted;
public LegacyManager(JailMain plugin) { public LegacyManager(JailMain plugin) {
this.pl = plugin; this.pl = plugin;
this.wasConverted = false;
} }
/** Returns true/false if the old config, global.yml, exists and needs to be converted. */ /** Returns true/false if the old config, global.yml, exists and needs to be converted. */
@ -37,6 +39,15 @@ public class LegacyManager {
return new File(pl.getDataFolder(), "global.yml").exists(); return new File(pl.getDataFolder(), "global.yml").exists();
} }
/**
* Returns true if we converted anything and it was successful.
*
* @return true if everything converted successfully, was if not.
*/
public boolean wasAnythingConverted() {
return this.wasConverted;
}
public boolean convertOldData() { public boolean convertOldData() {
File f = new File(pl.getDataFolder(), "global.yml"); File f = new File(pl.getDataFolder(), "global.yml");
@ -64,6 +75,7 @@ public class LegacyManager {
loadOldConfig(); loadOldConfig();
loadOldData(); loadOldData();
moveOldConfigs(); moveOldConfigs();
this.wasConverted = true;
pl.getLogger().info("...finished converting configs and data."); pl.getLogger().info("...finished converting configs and data.");
return true; return true;
}catch (Exception e) { }catch (Exception e) {