|
2 | 2 |
|
3 | 3 | import ch.njol.skript.Skript; |
4 | 4 | import ch.njol.skript.effects.EffReturn; |
5 | | -import ch.njol.skript.lang.ExpressionInfo; |
6 | | -import ch.njol.skript.lang.SyntaxElement; |
7 | | -import ch.njol.skript.lang.SyntaxElementInfo; |
| 5 | +import ch.njol.skript.lang.*; |
| 6 | +import ch.njol.util.Checker; |
8 | 7 | import com.btk5h.skriptmirror.skript.EffExpressionStatement; |
9 | 8 | import com.btk5h.skriptmirror.skript.custom.ExprMatchedPattern; |
10 | 9 | import com.btk5h.skriptmirror.skript.custom.condition.CustomCondition; |
@@ -40,39 +39,23 @@ public class ParseOrderWorkarounds { |
40 | 39 | }; |
41 | 40 |
|
42 | 41 | public static void reorderSyntax() { |
43 | | - Arrays.stream(PARSE_ORDER) |
44 | | - .forEach(c -> { |
45 | | - ensureLast(Skript.getStatements(), c); |
46 | | - ensureLast(Skript.getConditions(), c); |
47 | | - ensureLast(Skript.getEffects(), c); |
48 | | - ensureLastExpression(c); |
49 | | - }); |
| 42 | + for (String c : PARSE_ORDER) { |
| 43 | + ensureLast(Skript.getStatements(), o -> o.c.getName().equals(c)); |
| 44 | + ensureLast(Skript.getConditions(), o -> o.c.getName().equals(c)); |
| 45 | + ensureLast(Skript.getEffects(), o -> o.c.toString().equals(c)); |
| 46 | + ensureLast(SkriptReflection.getExpressions(), o -> o.c.getName().equals(c)); |
| 47 | + ensureLast(Skript.getEvents(), o -> o.c.getName().equals(c)); |
| 48 | + } |
50 | 49 | } |
51 | 50 |
|
52 | | - private static <E extends SyntaxElement> void ensureLast(Collection<SyntaxElementInfo<? extends E>> elements, |
53 | | - String element) { |
54 | | - Optional<SyntaxElementInfo<? extends E>> optionalElementInfo = elements.stream() |
55 | | - .filter(info -> info.c.getName().equals(element)) |
| 51 | + private static <E> void ensureLast(Collection<E> elements, Checker<E> checker) { |
| 52 | + Optional<E> optionalE = elements.stream() |
| 53 | + .filter(checker::check) |
56 | 54 | .findFirst(); |
57 | 55 |
|
58 | | - optionalElementInfo.ifPresent(elementInfo -> { |
59 | | - elements.remove(elementInfo); |
60 | | - elements.add(elementInfo); |
61 | | - }); |
62 | | - } |
63 | | - |
64 | | - private static void ensureLastExpression(String element) { |
65 | | - List<ExpressionInfo<?, ?>> elements = SkriptReflection.getExpressions(); |
66 | | - if (elements == null) |
67 | | - return; |
68 | | - |
69 | | - Optional<ExpressionInfo<?, ?>> optionalExpressionInfo = elements.stream() |
70 | | - .filter(info -> info.c.getName().equals(element)) |
71 | | - .findFirst(); |
72 | | - |
73 | | - optionalExpressionInfo.ifPresent(elementInfo -> { |
74 | | - elements.remove(elementInfo); |
75 | | - elements.add(elementInfo); |
| 56 | + optionalE.ifPresent(value -> { |
| 57 | + elements.remove(value); |
| 58 | + elements.add(value); |
76 | 59 | }); |
77 | 60 | } |
78 | 61 |
|
|
0 commit comments