|
18 | 18 | import com.google.gson.JsonPrimitive;
|
19 | 19 | import cz.coffee.skjson.SkJsonElements;
|
20 | 20 | import cz.coffee.skjson.api.FileHandler;
|
| 21 | +import cz.coffee.skjson.api.SkJsonLogger; |
21 | 22 | import cz.coffee.skjson.json.JsonParser;
|
22 | 23 | import cz.coffee.skjson.parser.ParserUtil;
|
| 24 | +import cz.coffee.skjson.utils.ConsoleColors; |
| 25 | +import cz.coffee.skjson.utils.Logger; |
23 | 26 | import cz.coffee.skjson.utils.PatternUtil;
|
24 | 27 | import cz.coffee.skjson.utils.Util;
|
25 | 28 | import org.bukkit.event.Event;
|
@@ -635,46 +638,32 @@ public static class MapJson extends Effect {
|
635 | 638 | private static void toList(@NotNull String name, JsonElement inputJson, boolean isLocal, Event event) {
|
636 | 639 | if (inputJson.isJsonPrimitive()) {
|
637 | 640 | primitive(name, inputJson.getAsJsonPrimitive(), isLocal, event);
|
638 |
| - } else if (inputJson.isJsonObject() || inputJson.isJsonArray()) { |
639 |
| - if (inputJson instanceof JsonArray list) { |
640 |
| - for (int index = 0; index < list.size(); index++) { |
641 |
| - JsonElement element = list.get(index); |
642 |
| - Object parsed = from(element); |
643 |
| - if (parsed == null) { |
644 |
| - if (element.isJsonPrimitive()) { |
645 |
| - primitive(name + (index + 1), element.getAsJsonPrimitive(), isLocal, event); |
646 |
| - } else { |
647 |
| - toList(name + (index + 1) + SEPARATOR, element, isLocal, event); |
648 |
| - } |
649 |
| - } else { |
650 |
| - if (PROJECT_DEBUG && LOGGING_LEVEL > 2) |
651 |
| - info("List-Element &b %s &fParsed? -> &a %s", element, parsed); |
652 |
| - parsed(name + (index + 1), parsed, isLocal, event); |
653 |
| - } |
| 641 | + } else if (inputJson.isJsonObject()) { |
| 642 | + JsonObject jsonObject = inputJson.getAsJsonObject(); |
| 643 | + for (String key : jsonObject.keySet()) { |
| 644 | + JsonElement element = jsonObject.get(key); |
| 645 | + String newName = name + key + SEPARATOR; |
| 646 | + if (element.isJsonPrimitive()) { |
| 647 | + primitive(newName, element.getAsJsonPrimitive(), isLocal, event); |
| 648 | + } else { |
| 649 | + toList(newName, element, isLocal, event); |
| 650 | + } |
| 651 | + } |
| 652 | + } else if (inputJson.isJsonArray()) { |
| 653 | + JsonArray jsonArray = inputJson.getAsJsonArray(); |
| 654 | + for (int i = 0; i < jsonArray.size(); i++) { |
| 655 | + JsonElement element = jsonArray.get(i); |
| 656 | + String newName = name + (i + 1) + SEPARATOR; |
| 657 | + if (element.isJsonPrimitive()) { |
| 658 | + primitive(newName, element.getAsJsonPrimitive(), isLocal, event); |
| 659 | + } else { |
| 660 | + toList(newName, element, isLocal, event); |
654 | 661 | }
|
655 |
| - } else if (inputJson instanceof JsonObject map) { |
656 |
| - map.keySet().stream().filter(Objects::nonNull).forEach(key -> { |
657 |
| - try { |
658 |
| - JsonElement element = map.get(key); |
659 |
| - Object parsed = from(element); |
660 |
| - // parsed means that return a parsed value from BUKKIT/SKRIPT Objects |
661 |
| - if (parsed == null) { |
662 |
| - if (element.isJsonPrimitive()) { |
663 |
| - primitive(name + key, element.getAsJsonPrimitive(), isLocal, event); |
664 |
| - } else { |
665 |
| - toList(name + key + SEPARATOR, element, isLocal, event); |
666 |
| - } |
667 |
| - } else { |
668 |
| - parsed(name + key, parsed, isLocal, event); |
669 |
| - } |
670 |
| - } catch (Exception e) { |
671 |
| - error(e); |
672 |
| - } |
673 |
| - }); |
674 | 662 | }
|
675 | 663 | }
|
676 | 664 | }
|
677 | 665 |
|
| 666 | + |
678 | 667 | static <T> void parsed(String name, T object, boolean isLocal, Event event) {
|
679 | 668 | if (PROJECT_DEBUG && LOGGING_LEVEL > 2) info("PARSED -> (Variable) %s => &e%s", name, object);
|
680 | 669 | Variables.setVariable(name, object, event, isLocal);
|
|
0 commit comments