Skip to content

Commit

Permalink
core.sk:25 - fix typo, missing []
Browse files Browse the repository at this point in the history
  • Loading branch information
cooffeeRequired committed Feb 1, 2025
1 parent a39e844 commit 5cfb512
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static def callAPI(String cmd) {
tasks.register("runRemote") {
doLast {
callAPI("reload+confirm")
sleep(10000)
callAPI("gendocs")
/* sleep(10000)
callAPI("gendocs")*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ch.njol.skript.classes.Changer;
import ch.njol.util.coll.CollectionUtils;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import cz.coffeerequired.SkJson;
import cz.coffeerequired.support.SkriptUtils;
Expand All @@ -19,12 +20,16 @@ public class JSONTypeDefaultChanger implements Changer<JsonElement> {
return switch (mode) {
// case RESET, REMOVE, REMOVE_ALL -> CollectionUtils.array(Object[].class);
case REMOVE -> CollectionUtils.array(JsonPath.class);
case ADD -> CollectionUtils.array(Object.class, Object[].class);
default -> null;
};
}

@Override
public void change(JsonElement[] what, @Nullable Object[] delta, ChangeMode mode) {

SkJson.debug("JSONTypeDefaultChanger changed %s, %s", Arrays.toString(what), Arrays.toString(delta));

if (mode == Changer.ChangeMode.REMOVE) {

SkJson.debug("@[WHAT]1: " + Arrays.toString(what));
Expand Down Expand Up @@ -54,6 +59,18 @@ public void change(JsonElement[] what, @Nullable Object[] delta, ChangeMode mode
}
}
}
} else if (mode == Changer.ChangeMode.ADD) {
JsonElement jsonElement = what[0];
if (jsonElement == null) {
return;
}
if (jsonElement instanceof JsonArray array) {
for (Object o : delta) {
array.add(GsonParser.toJson(o));
}
}


}
}
}
4 changes: 4 additions & 0 deletions src/main/java/cz/coffeerequired/modules/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public void change(JsonPath[] what, @Nullable Object[] delta, ChangeMode changeM
SerializedJson serializedJson = new SerializedJson(path.getInput());
var converted = Arrays.stream(delta).map(GsonParser::toJson).toArray(JsonElement[]::new);

SkJson.debug("converted %s", converted);

SkJson.debug("Keys: %s", path.getKeys());

IntStream.range(0, converted.length).forEach(idx -> {
var json = converted[idx];
var result = serializedJson.searcher.keyOrIndex(path.getKeys());
Expand Down

0 comments on commit 5cfb512

Please sign in to comment.