File tree Expand file tree Collapse file tree
src/main/java/io/github/syst3ms/skriptparser/variables Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ public class VariableMap {
1818
1919 private final Map <String , Object > map = new HashMap <>(); // Ordering is not important right now
2020
21+ public Map <String , Object > getMap () {
22+ return this .map ;
23+ }
24+
2125 private static String [] splitList (String name ) {
2226 return Pattern .compile (Pattern .quote (Variables .LIST_SEPARATOR )).split (name );
2327 }
Original file line number Diff line number Diff line change @@ -56,6 +56,24 @@ public static ReentrantLock getLock() {
5656
5757 public static void shutdown () {
5858 for (VariableStorage storage : STORAGES ) {
59+ // Write all variables to their storages
60+ // This needs to be done on shutdown to make sure changes to an object
61+ // are properly serialized and saved after their initial save
62+ variableMap .getMap ().forEach ((key , object ) -> {
63+ if (!storage .accept (key )) return ;
64+
65+ SerializedVariable serialized = storage .serialize (key , object );
66+ if (serialized != null ) {
67+ SerializedVariable .Value value = serialized .value ();
68+ if (value == null ) {
69+ storage .save (key , null , null );
70+ } else {
71+ storage .save (key , value .type (), value .data ());
72+ }
73+ }
74+
75+ });
76+ // Close storage
5977 try {
6078 storage .close ();
6179 } catch (IOException e ) {
You can’t perform that action at this time.
0 commit comments