Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default value, filter input, metadata, relational variable, ternary incorrectly converting #3930

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ExprDefaultValue<T> extends SimpleExpression<T> {
}

private final ExprDefaultValue<?> source;
private final Class<? extends T>[] types;
private final Class<T> superType;
@Nullable
private Expression<Object> first;
Expand All @@ -67,6 +68,7 @@ private ExprDefaultValue(ExprDefaultValue<?> source, Class<? extends T>... types
this.first = source.first;
this.second = source.second;
}
this.types = types;
this.superType = (Class<T>) Utils.getSuperType(types);
}

Expand All @@ -83,7 +85,7 @@ protected T[] get(Event e) {
Object[] first = this.first.getArray(e);
Object values[] = first.length != 0 ? first : second.getArray(e);
try {
return Converters.convertStrictly(values, superType);
return Converters.convertArray(values, types, superType);
} catch (ClassCastException e1) {
return (T[]) Array.newInstance(superType, 0);
}
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/ch/njol/skript/expressions/ExprFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import com.google.common.collect.Iterators;
import ch.njol.skript.Skript;
Expand Down Expand Up @@ -55,6 +56,7 @@
@SuppressWarnings({"null", "unchecked"})
public class ExprFilter extends SimpleExpression<Object> {

@Nullable
private static ExprFilter parsing;

static {
Expand All @@ -68,6 +70,7 @@ public class ExprFilter extends SimpleExpression<Object> {
private String rawCond;
private Expression<Object> objects;

@Nullable
public static ExprFilter getParsing() {
return parsing;
}
Expand Down Expand Up @@ -163,16 +166,20 @@ public static class ExprInput<T> extends SimpleExpression<T> {
);
}

private ExprInput<?> source;
private Class<T> superType;
@Nullable
private final ExprInput<?> source;
private final Class<? extends T>[] types;
private final Class<T> superType;
@SuppressWarnings("NotNullFieldNotInitialized")
private ExprFilter parent;
@Nullable
private ClassInfo<?> inputType;

public ExprInput() {
public ExprInput() {
this(null, (Class<? extends T>) Object.class);
}

public ExprInput(ExprInput<?> source, Class<? extends T>... types) {
public ExprInput(@Nullable ExprInput<?> source, Class<? extends T>... types) {
this.source = source;
if (source != null) {
this.parent = source.parent;
Expand All @@ -181,6 +188,7 @@ public ExprInput(ExprInput<?> source, Class<? extends T>... types) {
parent.addChild(this);
}

this.types = types;
this.superType = (Class<T>) Utils.getSuperType(types);
}

Expand All @@ -204,7 +212,7 @@ protected T[] get(Event e) {
}

try {
return Converters.convertStrictly(new Object[]{current}, superType);
return Converters.convertArray(new Object[]{current}, types, superType);
} catch (ClassCastException e1) {
return (T[]) Array.newInstance(superType, 0);
}
Expand All @@ -229,6 +237,7 @@ public Class<? extends T> getReturnType() {
return superType;
}

@Nullable
private ClassInfo<?> getClassInfo() {
return inputType;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/njol/skript/expressions/ExprMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class ExprMetadata<T> extends SimpleExpression<T> {
private Expression<String> values;
@Nullable
private Expression<Metadatable> holders;
private Class<? extends T>[] types;
private Class<T> superType;

public ExprMetadata() {
Expand All @@ -77,6 +78,7 @@ private ExprMetadata(ExprMetadata<?> source, Class<? extends T>... types) {
this.values = source.values;
this.holders = source.holders;
}
this.types = types;
this.superType = (Class<T>) Utils.getSuperType(types);
}

Expand All @@ -99,7 +101,7 @@ protected T[] get(Event e) {
}
}
try {
return Converters.convertStrictly(values.toArray(), superType);
return Converters.convertArray(values.toArray(), types, superType);
} catch (ClassCastException e1) {
return (T[]) Array.newInstance(superType, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class ExprRelationalVariable<T> extends SimpleExpression<T> {
private Expression<Object> holders;

private ExprRelationalVariable<?> source;
private Class<? extends T>[] types;
private Class<T> superType;

public ExprRelationalVariable() {
Expand All @@ -89,6 +90,7 @@ private ExprRelationalVariable(ExprRelationalVariable<?> source, Class<? extends
this.variables = source.variables;
this.holders = source.holders;
}
this.types = types;
this.superType = (Class<T>) Utils.getSuperType(types);
}

Expand Down Expand Up @@ -124,7 +126,7 @@ public T[] get(Event e) {
}
}
try {
return Converters.convertStrictly(values.toArray(), superType);
return Converters.convertArray(values.toArray(), types, superType);
} catch (ClassCastException ex) {
return (T[]) Array.newInstance(superType, 0);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/njol/skript/expressions/ExprTernary.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ExprTernary<T> extends SimpleExpression<T> {

private final ExprTernary<?> source;
private final Class<T> superType;
private final Class<? extends T>[] types;
@Nullable
private Expression<Object> ifTrue;
@Nullable
Expand All @@ -72,6 +73,7 @@ private ExprTernary(ExprTernary<?> source, Class<? extends T>... types) {
this.ifFalse = source.ifFalse;
this.condition = source.condition;
}
this.types = types;
this.superType = (Class<T>) Utils.getSuperType(types);
}

Expand All @@ -93,7 +95,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
protected T[] get(Event e) {
Object[] values = condition.check(e) ? ifTrue.getArray(e) : ifFalse.getArray(e);
try {
return Converters.convertStrictly(values, superType);
return Converters.convertArray(values, types, superType);
} catch (ClassCastException e1) {
return (T[]) Array.newInstance(superType, 0);
}
Expand Down