Some java 17 code cleanup
This commit is contained in:
parent
82bd53d107
commit
eeb3fe0962
@ -175,7 +175,7 @@ public class EffExecuteStatement extends Effect {
|
|||||||
.map(arg -> SkriptValueWrapper.getBySkriptType(arg.getClass()).asSql(arg))
|
.map(arg -> SkriptValueWrapper.getBySkriptType(arg.getClass()).asSql(arg))
|
||||||
.toList();
|
.toList();
|
||||||
return new Pair<>(query.getSingle(e), argsList);
|
return new Pair<>(query.getSingle(e), argsList);
|
||||||
} else if (query instanceof VariableString && !((VariableString) query).isSimple()) {
|
} else if (query instanceof VariableString queryString && !queryString.isSimple()) {
|
||||||
return parseVariableQuery(e, (VariableString) query);
|
return parseVariableQuery(e, (VariableString) query);
|
||||||
}
|
}
|
||||||
return new Pair<>(query.getSingle(e), null);
|
return new Pair<>(query.getSingle(e), null);
|
||||||
@ -205,11 +205,11 @@ public class EffExecuteStatement extends Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Pair<String, Object> parseExpressionQuery(Expression<?> expr, Object expressionValue, boolean standaloneString) {
|
private Pair<String, Object> parseExpressionQuery(Expression<?> expr, Object expressionValue, boolean standaloneString) {
|
||||||
if (expr instanceof ExprUnsafe) {
|
if (expr instanceof ExprUnsafe unsafe) {
|
||||||
if (standaloneString && expressionValue instanceof String) {
|
if (standaloneString && expressionValue instanceof String) {
|
||||||
Skript.warning(
|
Skript.warning(
|
||||||
String.format("Unsafe may have been used unnecessarily. Try replacing 'unsafe %1$s' with %1$s",
|
String.format("Unsafe may have been used unnecessarily. Try replacing 'unsafe %1$s' with %1$s",
|
||||||
((ExprUnsafe) expr).getRawExpression()));
|
unsafe.getRawExpression()));
|
||||||
}
|
}
|
||||||
return new Pair<>((String) expressionValue, null);
|
return new Pair<>((String) expressionValue, null);
|
||||||
} else {
|
} else {
|
||||||
@ -308,8 +308,8 @@ public class EffExecuteStatement extends Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getString(Object[] objects, int index) {
|
private String getString(Object[] objects, int index) {
|
||||||
if (index >= 0 && index < objects.length && objects[index] instanceof String) {
|
if (index >= 0 && index < objects.length && objects[index] instanceof String str) {
|
||||||
return (String) objects[index];
|
return str;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -318,13 +318,13 @@ public class EffExecuteStatement extends Effect {
|
|||||||
|
|
||||||
//fix mediumblob and similar column types, so they return a String correctly
|
//fix mediumblob and similar column types, so they return a String correctly
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
if (obj instanceof byte[]) {
|
if (obj instanceof byte[] bytes) {
|
||||||
obj = new String((byte[]) obj);
|
obj = new String(bytes);
|
||||||
|
|
||||||
//in some servers instead of being byte array, it appears as SerialBlob (depends on mc version, 1.12.2 is bvte array, 1.16.5 SerialBlob)
|
//in some servers instead of being byte array, it appears as SerialBlob (depends on mc version, 1.12.2 is bvte array, 1.16.5 SerialBlob)
|
||||||
} else if (obj instanceof SerialBlob) {
|
} else if (obj instanceof SerialBlob blob) {
|
||||||
try {
|
try {
|
||||||
obj = new String(((SerialBlob) obj).getBinaryStream().readAllBytes());
|
obj = new String(blob.getBinaryStream().readAllBytes());
|
||||||
} catch (IOException | SerialException ex) {
|
} catch (IOException | SerialException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -360,7 +360,7 @@ public class EffExecuteStatement extends Effect {
|
|||||||
}
|
}
|
||||||
dataSource = (Expression<HikariDataSource>) exprs[1];
|
dataSource = (Expression<HikariDataSource>) exprs[1];
|
||||||
if (exprs[2] != null) {
|
if (exprs[2] != null) {
|
||||||
if (query instanceof VariableString && !((VariableString) query).isSimple()) {
|
if (query instanceof VariableString queryString && !queryString.isSimple()) {
|
||||||
Skript.warning("Your query string contains expresions, but you've also provided query arguments. Consider using `unsafe` keyword before your query.");
|
Skript.warning("Your query string contains expresions, but you've also provided query arguments. Consider using `unsafe` keyword before your query.");
|
||||||
}
|
}
|
||||||
queryArguments = (Expression<Object>) exprs[2];
|
queryArguments = (Expression<Object>) exprs[2];
|
||||||
|
@ -30,8 +30,8 @@ public class ExprSQLQuery extends SimpleExpression<String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] get(Event e) {
|
protected String[] get(Event e) {
|
||||||
if (e instanceof SQLQueryCompleteEvent) {
|
if (e instanceof SQLQueryCompleteEvent sqlEvent) {
|
||||||
return new String[]{((SQLQueryCompleteEvent) e).getQuery()};
|
return new String[]{ sqlEvent.getQuery() };
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user