Skip to content

Commit 6cef7fc

Browse files
authored
Merge pull request #15 from SkriptDev/dev/patch
Dev/patch
2 parents 613e2c7 + 43f9faa commit 6cef7fc

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/main/java/io/github/syst3ms/skriptparser/expressions/ExprContextValue.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, ParseContex
8383
}
8484
return false;
8585
} else if (state != info.getState()) {
86-
logger.error("The time state of this context value (" + state.toString().toLowerCase() + ") is incorrect", ErrorType.SEMANTIC_ERROR);
87-
return false;
86+
// TODO might find a way to re-implement this later
87+
//logger.error("The time state of this context value (" + state.toString().toLowerCase() + ") is incorrect", ErrorType.SEMANTIC_ERROR);
88+
continue;
8889
} else if (parserState.isRestrictingExpressions() && parserState.forbidsSyntax(ExprContextValue.class)) {
8990
logger.setContext(ErrorContext.RESTRICTED_SYNTAXES);
9091
logger.error("The enclosing section does not allow the use of context expressions.", ErrorType.SEMANTIC_ERROR);

src/main/java/io/github/syst3ms/skriptparser/variables/VariableMap.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

src/main/java/io/github/syst3ms/skriptparser/variables/VariableStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ boolean accept(@Nullable String variableName) {
300300
public <T> SerializedVariable serialize(String name, @Nullable T value) {
301301
if (value == null)
302302
return new SerializedVariable(name, null);
303-
Type<T> type = (Type<T>) TypeManager.getByClassExact(value.getClass()).orElse(null);
303+
Type<T> type = (Type<T>) TypeManager.getByClass(value.getClass()).orElse(null);
304304
if (type == null) return null;
305305
//throw new UnsupportedOperationException("Class '" + value.getClass().getName() + "' cannot be serialized. No type registered.");
306306
TypeSerializer<T> serializer = type.getSerializer().orElse(null);

src/main/java/io/github/syst3ms/skriptparser/variables/Variables.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)