Skip to content

Commit

Permalink
Try to fix exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Pikachu920 committed Feb 15, 2024
1 parent a2ccb48 commit f3d7cda
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/main/java/com/btk5h/skriptmirror/skript/CondChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ch.njol.skript.util.Patterns;
import ch.njol.skript.util.Utils;
import ch.njol.util.Kleenean;
import ch.njol.util.NonNullPair;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

Expand All @@ -18,11 +19,17 @@ public class CondChange extends Condition {

private static final Patterns<ChangeMode> PATTERNS = new Patterns<>(new Object[][] {
{"%classinfo% can be added to %expressions%", ChangeMode.ADD},
{"%classinfo% (can't|cannot) be added to %expressions%", ChangeMode.ADD},
{"%expressions% can be set to %classinfo%", ChangeMode.SET},
{"%expressions% (can't|cannot) be set to %classinfo%", ChangeMode.SET},
{"%classinfo% can be removed from %expressions%", ChangeMode.REMOVE},
{"%classinfo% (can't|cannot) be removed from %expressions%", ChangeMode.REMOVE},
{"all %classinfo% can be removed from %expressions%", ChangeMode.REMOVE_ALL},
{"all %classinfo% (can't|cannot) be removed from %expressions%", ChangeMode.REMOVE_ALL},
{"%expressions% can be deleted", ChangeMode.DELETE},
{"%expressions% can be reset", ChangeMode.RESET}
{"%expressions% (can't|cannot) be deleted", ChangeMode.DELETE},
{"%expressions% can be reset", ChangeMode.RESET},
{"%expressions% (can't|cannot) be reset", ChangeMode.RESET}
});

static {
Expand All @@ -37,6 +44,7 @@ public class CondChange extends Condition {
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
setNegated((matchedPattern % 2) != 0);
desiredChangeMode = PATTERNS.getInfo(matchedPattern);
Expression<?> desiredType = null;
switch (desiredChangeMode) {
Expand All @@ -56,6 +64,9 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
}
if (desiredType instanceof UnparsedLiteral) {
UnparsedLiteral unparsedDesiredType = (UnparsedLiteral) desiredType;
desiredType = unparsedDesiredType.getConvertedExpression(ClassInfo.class);
if (desiredType == null)
return false;
typeIsPlural = Utils.getEnglishPlural(unparsedDesiredType.getData()).getSecond();
}
this.desiredType = (Expression<ClassInfo<?>>) desiredType;
Expand All @@ -64,10 +75,13 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye

@Override
public boolean check(Event event) {
if (desiredChangeMode == ChangeMode.DELETE || desiredChangeMode == ChangeMode.RESET)
//noinspection ConstantValue
return expressions.check(event, expressions -> expressions.acceptChange(desiredChangeMode) != null, isNegated());
ClassInfo<?> desiredType = this.desiredType.getSingle(event);
if (desiredType == null)
return false;
return expressions.check(event, expression -> acceptsChange(expression, desiredChangeMode, desiredType.getC(), typeIsPlural));
return expressions.check(event, expression -> acceptsChange(expression, desiredChangeMode, desiredType.getC(), typeIsPlural), isNegated());
}

@Override
Expand Down Expand Up @@ -103,9 +117,8 @@ private boolean acceptsChange(Expression<?> expression, ChangeMode desiredChange
} else if (!typeIsPlural && acceptableType.isAssignableFrom(desiredType))
return true;
}
return false;
}
return desiredChangeMode == ChangeMode.DELETE || desiredChangeMode == ChangeMode.RESET;
return false;
}

}

0 comments on commit f3d7cda

Please sign in to comment.