Skip to content

Commit

Permalink
Fix bits.
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky committed Nov 23, 2024
1 parent fb240c5 commit 36a9afd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions src/main/java/ch/njol/skript/expressions/ExprResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Name("Result (Experimental)")
@Description({
"Runs something (like a function) and returns its result.",
"If the thing is expected to return multiple values, specify 'results'."
"If the thing is expected to return multiple values, use 'results' instead of 'result'."
})
@Examples({
"set {_function} to the function named \"myFunction\"",
Expand All @@ -29,7 +29,6 @@
})
@Since("INSERT VERSION")
@Keywords({"run", "result", "execute", "function", "reflection"})
@SuppressWarnings("NotNullFieldNotInitialized")
public class ExprResult extends PropertyExpression<Executable<Event, Object>, Object> {

static {
Expand All @@ -53,8 +52,8 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is
if (hasArguments) {
this.arguments = LiteralUtils.defendExpression(expressions[1]);
Expression<?>[] arguments;
if (this.arguments instanceof ExpressionList<?>)
arguments = ((ExpressionList<?>) this.arguments).getExpressions();
if (this.arguments instanceof ExpressionList<?> list)
arguments = list.getExpressions();
else
arguments = new Expression[]{this.arguments};
this.input = new DynamicFunctionReference.Input(arguments);
Expand All @@ -69,9 +68,8 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is
protected Object[] get(Event event, Executable<Event, Object>[] source) {
for (Executable<Event, Object> task : source) {
Object[] arguments;
if (task instanceof DynamicFunctionReference) {
//noinspection rawtypes
DynamicFunctionReference<?> reference = (DynamicFunctionReference) task;
//noinspection rawtypes
if (task instanceof DynamicFunctionReference reference) {
Expression<?> validated = reference.validate(input);
if (validated == null)
return new Object[0];
Expand All @@ -81,8 +79,8 @@ protected Object[] get(Event event, Executable<Event, Object>[] source) {
else
arguments = new Object[0];
Object execute = task.execute(event, arguments);
if (execute instanceof Object[])
return (Object[]) execute;
if (execute instanceof Object[] results)
return results;
return new Object[]{execute};
}
return new Object[0];
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/skriptlang/skript/util/Executable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* This is an abstraction for general triggers (runnables, tasks, functions, etc.)
* without any Bukkit dependency.
*
* @param <Caller> The source type of this process.
* @param <Result> The result type of this process.
* @param <Caller> The source type of this process (e.g. Event, CommandSender, etc.)
* @param <Result> The return type of this process.
*/
public interface Executable<Caller, Result> {

Expand Down

0 comments on commit 36a9afd

Please sign in to comment.