4747import java .io .IOException ;
4848import java .io .PrintWriter ;
4949import java .io .UnsupportedEncodingException ;
50+ import java .security .AccessController ;
51+ import java .security .PrivilegedAction ;
5052import java .util .ArrayList ;
5153import java .util .List ;
5254import java .util .Optional ;
@@ -61,16 +63,19 @@ protected SaveManager() { }
6163 public static void writeShips (HullConfig hull , float money , List <SolItem > itemsList , Hero hero , HullConfigManager hullConfigManager ) {
6264 String hullName = hullConfigManager .getName (hull );
6365
64- writeMercs (hero , hullConfigManager );
66+ AccessController .doPrivileged ((PrivilegedAction <Object >) () -> {
67+ writeMercs (hero , hullConfigManager );
6568
66- String items = itemsToString (itemsList );
69+ String items = itemsToString (itemsList );
6770
68- Vector2 pos = hero .getPosition ();
71+ Vector2 pos = hero .getPosition ();
6972
70- String waypoints = waypointsToString (hero .getWaypoints ());
73+ String waypoints = waypointsToString (hero .getWaypoints ());
7174
72- IniReader .write (Const .SAVE_FILE_NAME , "hull" , hullName , "money" , (int ) money , "items" , items ,
73- "x" , pos .x , "y" , pos .y , "waypoints" , waypoints , "version" , Const .VERSION );
75+ IniReader .write (Const .SAVE_FILE_NAME , "hull" , hullName , "money" , (int ) money , "items" , items ,
76+ "x" , pos .x , "y" , pos .y , "waypoints" , waypoints , "version" , Const .VERSION );
77+ return null ;
78+ });
7479 }
7580
7681 private static String waypointsToString (ArrayList <Waypoint > waypoints ) {
@@ -261,12 +266,16 @@ public static void saveWorld(WorldConfig worldConfig) {
261266 Gson gson = new GsonBuilder ().setPrettyPrinting ().create ();
262267 String stringToWrite = gson .toJson (world );
263268
264- try (PrintWriter writer = new PrintWriter (fileName , "UTF-8" )) {
265- writer .write (stringToWrite );
266- logger .debug ("Successfully saved the world file" );
267- } catch (FileNotFoundException | UnsupportedEncodingException e ) {
268- logger .error ("Could not save world file" , e );
269- }
269+ AccessController .doPrivileged ((PrivilegedAction <Object >) () -> {
270+ try (PrintWriter writer = new PrintWriter (fileName , "UTF-8" )) {
271+ writer .write (stringToWrite );
272+ logger .debug ("Successfully saved the world file" );
273+ } catch (FileNotFoundException | UnsupportedEncodingException e ) {
274+ logger .error ("Could not save world file" , e );
275+ }
276+
277+ return null ;
278+ });
270279 }
271280
272281 /**
0 commit comments