|
14 | 14 | import ch.njol.skript.lang.SkriptParser.ParseResult; |
15 | 15 | import ch.njol.skript.lang.Variable; |
16 | 16 | import ch.njol.skript.lang.parser.ParserInstance; |
| 17 | +import ch.njol.skript.variables.HintManager; |
17 | 18 | import ch.njol.skript.variables.Variables; |
18 | 19 | import ch.njol.util.Kleenean; |
19 | 20 | import ch.njol.util.Pair; |
@@ -69,19 +70,27 @@ public class EffTransform extends Effect implements InputSource { |
69 | 70 |
|
70 | 71 | @Override |
71 | 72 | public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { |
72 | | - if (expressions[0].isSingle() || !(expressions[0] instanceof Variable)) { |
| 73 | + if (parseResult.regexes.isEmpty()) { |
| 74 | + return false; |
| 75 | + } |
| 76 | + |
| 77 | + if (expressions[0].isSingle() || !(expressions[0] instanceof Variable<?> variable)) { |
73 | 78 | Skript.error("You can only transform list variables!"); |
74 | 79 | return false; |
75 | 80 | } |
76 | | - unmappedObjects = (Variable<?>) expressions[0]; |
77 | | - |
78 | | - //noinspection DuplicatedCode |
79 | | - if (!parseResult.regexes.isEmpty()) { |
80 | | - @Nullable String unparsedExpression = parseResult.regexes.get(0).group(); |
81 | | - assert unparsedExpression != null; |
82 | | - mappingExpr = parseExpression(unparsedExpression, getParser(), SkriptParser.ALL_FLAGS); |
83 | | - return mappingExpr != null; |
| 81 | + unmappedObjects = variable; |
| 82 | + |
| 83 | + String unparsedExpression = parseResult.regexes.get(0).group(); |
| 84 | + mappingExpr = parseExpression(unparsedExpression, getParser(), SkriptParser.ALL_FLAGS); |
| 85 | + if (mappingExpr == null) { |
| 86 | + return false; |
| 87 | + } |
| 88 | + |
| 89 | + // type hints |
| 90 | + if (HintManager.canUseHints(variable)) { |
| 91 | + getParser().getHintManager().set(variable, mappingExpr.possibleReturnTypes()); |
84 | 92 | } |
| 93 | + |
85 | 94 | return true; |
86 | 95 | } |
87 | 96 |
|
|
0 commit comments