Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions engine/src/main/java/org/destinationsol/game/SaveManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -61,16 +63,19 @@ protected SaveManager() { }
public static void writeShips(HullConfig hull, float money, List<SolItem> itemsList, Hero hero, HullConfigManager hullConfigManager) {
String hullName = hullConfigManager.getName(hull);

writeMercs(hero, hullConfigManager);
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
writeMercs(hero, hullConfigManager);

String items = itemsToString(itemsList);
String items = itemsToString(itemsList);

Vector2 pos = hero.getPosition();
Vector2 pos = hero.getPosition();

String waypoints = waypointsToString(hero.getWaypoints());
String waypoints = waypointsToString(hero.getWaypoints());

IniReader.write(Const.SAVE_FILE_NAME, "hull", hullName, "money", (int) money, "items", items,
"x", pos.x, "y", pos.y, "waypoints", waypoints, "version", Const.VERSION);
IniReader.write(Const.SAVE_FILE_NAME, "hull", hullName, "money", (int) money, "items", items,
"x", pos.x, "y", pos.y, "waypoints", waypoints, "version", Const.VERSION);
return null;
});
}

private static String waypointsToString(ArrayList<Waypoint> waypoints) {
Expand Down Expand Up @@ -261,12 +266,16 @@ public static void saveWorld(WorldConfig worldConfig) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String stringToWrite = gson.toJson(world);

try (PrintWriter writer = new PrintWriter(fileName, "UTF-8")) {
writer.write(stringToWrite);
logger.debug("Successfully saved the world file");
} catch (FileNotFoundException | UnsupportedEncodingException e) {
logger.error("Could not save world file", e);
}
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
try (PrintWriter writer = new PrintWriter(fileName, "UTF-8")) {
writer.write(stringToWrite);
logger.debug("Successfully saved the world file");
} catch (FileNotFoundException | UnsupportedEncodingException e) {
logger.error("Could not save world file", e);
}

return null;
});
}

/**
Expand Down