Fixed ship autosave

This commit is contained in:
LemADEC 2016-08-11 09:44:57 +02:00
parent 8980d1e53d
commit e1058cb10d

View file

@ -394,6 +394,20 @@ public class JumpSequencer extends AbstractSequencer {
private void state_borders() { private void state_borders() {
LocalProfiler.start("Jump.borders"); LocalProfiler.start("Jump.borders");
if (WarpDriveConfig.LOGGING_JUMP) {
WarpDrive.logger.info(this + " Checking ship borders...");
}
StringBuilder reason = new StringBuilder();
if (!ship.checkBorders(reason)) {
String msg = reason.toString();
disable(msg);
ship.messageToAllPlayersOnShip(msg);
LocalProfiler.stop();
return;
}
try { try {
// Generate unique file name // Generate unique file name
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH'h'mm'm'ss's'SSS"); SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd_HH'h'mm'm'ss's'SSS");
@ -401,8 +415,8 @@ public class JumpSequencer extends AbstractSequencer {
String schematicFileName; String schematicFileName;
do { do {
Date now = new Date(); Date now = new Date();
schematicFileName = shipName + "_" + sdfDate.format(now); schematicFileName = WarpDriveConfig.G_SCHEMALOCATION + "/auto/" + shipName + "_" + sdfDate.format(now) + ".schematic";
} while (new File(WarpDriveConfig.G_SCHEMALOCATION + "/auto/" + schematicFileName + ".schematic").exists()); } while (new File(schematicFileName).exists());
// Save header // Save header
NBTTagCompound schematic = new NBTTagCompound(); NBTTagCompound schematic = new NBTTagCompound();
@ -421,32 +435,18 @@ public class JumpSequencer extends AbstractSequencer {
schematic.setTag("ship", tagCompoundShip); schematic.setTag("ship", tagCompoundShip);
writeNBTToFile(schematicFileName, schematic); writeNBTToFile(schematicFileName, schematic);
if (WarpDriveConfig.LOGGING_JUMP) { if (WarpDriveConfig.LOGGING_JUMP) {
// WarpDrive.logger.info(this + " Ship saved as " + schematicFileName); // WarpDrive.logger.info(this + " Ship saved as " + schematicFileName);
} }
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
if (WarpDriveConfig.LOGGING_JUMP) {
WarpDrive.logger.info(this + " Checking ship borders...");
}
StringBuilder reason = new StringBuilder();
if (!ship.checkBorders(reason)) {
String msg = reason.toString();
disable(msg);
ship.messageToAllPlayersOnShip(msg);
LocalProfiler.stop();
return;
}
msCounter = System.currentTimeMillis(); msCounter = System.currentTimeMillis();
LocalProfiler.stop(); LocalProfiler.stop();
} }
private void writeNBTToFile(String fileName, NBTTagCompound nbttagcompound) { private void writeNBTToFile(String fileName, NBTTagCompound nbttagcompound) {
WarpDrive.logger.info(this + " writeNBTToFile " + fileName); WarpDrive.logger.info(this + " Saving ship state prior to jump in " + fileName);
try { try {
File file = new File(fileName); File file = new File(fileName);