Skip to content

Commit

Permalink
Improve ReturnHandler#returnValues method (#6894)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderscoreTud authored Jul 15, 2024
1 parent ad3d5db commit db337a6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/main/java/ch/njol/skript/effects/EffReturn.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
Expand Down Expand Up @@ -110,7 +109,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
protected TriggerItem walk(Event event) {
debug(event, false);
//noinspection rawtypes,unchecked
((ReturnHandler) handler).returnValues(value.getArray(event));
((ReturnHandler) handler).returnValues(event, value);

TriggerSection parent = getParent();
while (parent != null && parent != handler) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/ch/njol/skript/lang/ReturnHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ default ReturnableTrigger<T> loadReturnableTrigger(SectionNode node, String name
}

/**
* @param values the values to return
* Called when {@link ch.njol.skript.effects.EffReturn} is executed
* @param event the event providing context
* @param value an expression representing the value(s) to return
*/
void returnValues(T @Nullable [] values);
void returnValues(Event event, Expression<? extends T> value);

/**
* @return whether this return handler may accept multiple return values
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ch/njol/skript/lang/ReturnableTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package ch.njol.skript.lang;

import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;
import org.skriptlang.skript.lang.script.Script;

Expand All @@ -36,8 +37,8 @@ public ReturnableTrigger(ReturnHandler<T> handler, @Nullable Script script, Stri
}

@Override
public void returnValues(T @Nullable [] values) {
handler.returnValues(values);
public void returnValues(Event event, Expression<? extends T> value) {
handler.returnValues(event, value);
}

@Override
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/ch/njol/skript/lang/function/ScriptFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
package ch.njol.skript.lang.function;

import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ReturnHandler;
import org.bukkit.event.Event;
import org.jetbrains.annotations.ApiStatus;
import org.skriptlang.skript.lang.script.Script;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.config.SectionNode;
import ch.njol.skript.effects.EffReturn;
import ch.njol.skript.lang.Trigger;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.variables.Variables;
Expand Down Expand Up @@ -80,13 +81,14 @@ public ScriptFunction(Signature<T> sign, SectionNode node) {
}

/**
* Should only be called by {@link EffReturn}.
* @deprecated Use {@link ScriptFunction#returnValues(Object[])}
* @deprecated Use {@link ScriptFunction#returnValues(Event, Expression)}
*/
@Deprecated
@ApiStatus.Internal
public final void setReturnValue(@Nullable T[] values) {
returnValues(values);
assert !returnValueSet;
returnValueSet = true;
this.returnValues = values;
}

@Override
Expand All @@ -97,10 +99,10 @@ public boolean resetReturnValue() {
}

@Override
public final void returnValues(T @Nullable [] values) {
public final void returnValues(Event event, Expression<? extends T> value) {
assert !returnValueSet;
returnValueSet = true;
this.returnValues = values;
this.returnValues = value.getArray(event);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ch/njol/skript/test/runner/SecReturnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is
}

@Override
public void returnValues(Object @Nullable [] values) {
returnedValues = values;
public void returnValues(Event event, Expression<?> value) {
returnedValues = value.getArray(event);
}

@Override
Expand Down Expand Up @@ -110,5 +110,5 @@ public String toString(@Nullable Event event, boolean debug) {
}

}

}

0 comments on commit db337a6

Please sign in to comment.