|
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; |
22 | 21 | import cz.coffee.skjson.json.JsonParser;
|
23 | 22 | import cz.coffee.skjson.parser.ParserUtil;
|
24 |
| -import cz.coffee.skjson.utils.ConsoleColors; |
25 |
| -import cz.coffee.skjson.utils.Logger; |
26 | 23 | import cz.coffee.skjson.utils.PatternUtil;
|
27 | 24 | import cz.coffee.skjson.utils.Util;
|
28 | 25 | import org.bukkit.event.Event;
|
@@ -635,56 +632,71 @@ public static class MapJson extends Effect {
|
635 | 632 | private boolean isLocal;
|
636 | 633 | private boolean async;
|
637 | 634 |
|
| 635 | + private static boolean cannotBeParsed(JsonElement element) { |
| 636 | + return from(element) instanceof JsonElement; |
| 637 | + } |
| 638 | + |
| 639 | + |
| 640 | + |
638 | 641 | private static void toList(@NotNull String name, JsonElement inputJson, boolean isLocal, Event event) {
|
639 | 642 | if (inputJson.isJsonPrimitive()) {
|
640 | 643 | primitive(name, inputJson.getAsJsonPrimitive(), isLocal, event);
|
641 | 644 | } else if (inputJson.isJsonObject()) {
|
| 645 | + Object parsed = from(inputJson); |
| 646 | + |
642 | 647 | JsonObject jsonObject = inputJson.getAsJsonObject();
|
643 | 648 | for (String key : jsonObject.keySet()) {
|
644 | 649 | JsonElement element = jsonObject.get(key);
|
645 | 650 | String newName = name + key + SEPARATOR;
|
646 |
| - if (element.isJsonPrimitive()) { |
647 |
| - primitive(newName, element.getAsJsonPrimitive(), isLocal, event); |
648 |
| - } else { |
| 651 | + Object parsed_ = from(element); |
| 652 | + |
| 653 | + if (cannotBeParsed(element)) { |
649 | 654 | toList(newName, element, isLocal, event);
|
| 655 | + } else { |
| 656 | + parsed(newName, parsed_, isLocal, event); |
650 | 657 | }
|
651 | 658 | }
|
652 | 659 | } else if (inputJson.isJsonArray()) {
|
653 | 660 | JsonArray jsonArray = inputJson.getAsJsonArray();
|
654 | 661 | for (int i = 0; i < jsonArray.size(); i++) {
|
655 | 662 | JsonElement element = jsonArray.get(i);
|
656 | 663 | String newName = name + (i + 1) + SEPARATOR;
|
657 |
| - if (element.isJsonPrimitive()) { |
658 |
| - primitive(newName, element.getAsJsonPrimitive(), isLocal, event); |
659 |
| - } else { |
| 664 | + Object parsed = from(element); |
| 665 | + |
| 666 | + if (cannotBeParsed(element)) { |
660 | 667 | toList(newName, element, isLocal, event);
|
| 668 | + } else { |
| 669 | + parsed(newName, parsed, isLocal, event); |
661 | 670 | }
|
662 | 671 | }
|
663 | 672 | }
|
664 | 673 | }
|
665 | 674 |
|
666 | 675 |
|
| 676 | + |
667 | 677 | static <T> void parsed(String name, T object, boolean isLocal, Event event) {
|
668 |
| - if (PROJECT_DEBUG && LOGGING_LEVEL > 2) info("PARSED -> (Variable) %s => &e%s", name, object); |
669 |
| - Variables.setVariable(name, object, event, isLocal); |
| 678 | + if (ParserUtil.isClassicType(object)) { |
| 679 | + primitive(name, object, isLocal, event); |
| 680 | + } else { |
| 681 | + if (PROJECT_DEBUG && LOGGING_LEVEL > 2) info("PARSED -> (%s) %s => &a%s", object.getClass().getName(), name, object); |
| 682 | + Variables.setVariable(name, object, event, isLocal); |
| 683 | + } |
670 | 684 | }
|
671 | 685 |
|
672 |
| - static void primitive(String name, JsonPrimitive input, boolean isLocal, Event event) { |
| 686 | + static void primitive(String name, Object input, boolean isLocal, Event event) { |
673 | 687 | if (name == null || input == null || event == null) return;
|
674 |
| - Object o = jsonToType(defaultConverter(input)); |
675 |
| - if (o != null) { |
676 |
| - if (PROJECT_DEBUG && LOGGING_LEVEL > 2) info("PRIMITIVE -> (Variable) %s => &e%s", name, input); |
677 |
| - } |
678 |
| - assert o != null; |
679 |
| - Variables.setVariable(name, o, event, isLocal); |
| 688 | + if (PROJECT_DEBUG && LOGGING_LEVEL > 2) info("&8PRIMITIVE&r -> (%s) %s => &e%s", input.getClass().getName(),name, input); |
| 689 | + Variables.setVariable(name, input, event, isLocal); |
680 | 690 | }
|
681 | 691 |
|
682 | 692 | @Override
|
683 | 693 | protected void execute(@NotNull Event e) {
|
684 | 694 | Object jsonInputSingle = jsonInput.getSingle(e);
|
685 | 695 | JsonElement json = ParserUtil.parse(jsonInputSingle);
|
| 696 | + |
686 | 697 | String vv = variableString.getSingle(e);
|
687 | 698 | String var = vv.substring(0, vv.length() - 3);
|
| 699 | + |
688 | 700 | if (json == null) return;
|
689 | 701 | if (async) {
|
690 | 702 | CompletableFuture.runAsync(() -> toList(var + SEPARATOR, json, isLocal, e));
|
|
0 commit comments