File tree Expand file tree Collapse file tree
src/main/java/ch/njol/skript/expressions/arithmetic Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -353,8 +353,35 @@ public String toString(@Nullable Event event, boolean debug) {
353353 @ Override
354354 public Expression <T > simplify () {
355355 // simplify this expression IFF it's the top-level arithmetic expression
356- if ( isTopLevel && first instanceof Literal && second instanceof Literal )
356+ if (isTopLevel )
357+ return simplifyInternal ();
358+ return this ;
359+ }
360+
361+ /**
362+ * Simplifies an arithmetic expression regardless of whether it is the top-level expression.
363+ * @return the simplified expression
364+ */
365+ private Expression <T > simplifyInternal () {
366+ if (first instanceof ExprArithmetic <?,?,?> firstArith ) {
367+ //noinspection unchecked
368+ first = (Expression <L >) firstArith .simplifyInternal ();
369+ } else {
370+ //noinspection unchecked
371+ first = (Expression <L >) first .simplify ();
372+ }
373+
374+ if (second instanceof ExprArithmetic <?,?,?> secondArith ) {
375+ //noinspection unchecked
376+ second = (Expression <R >) secondArith .simplifyInternal ();
377+ } else {
378+ //noinspection unchecked
379+ second = (Expression <R >) second .simplify ();
380+ }
381+
382+ if (first instanceof Literal && second instanceof Literal )
357383 return getAsSimplifiedLiteral ();
384+
358385 return this ;
359386 }
360387
You can’t perform that action at this time.
0 commit comments