Skip to content

Commit 28c879f

Browse files
committed
Fix JavaFunctions not returning keys in getReturnedKeys
1 parent 2e1d112 commit 28c879f

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/main/java/ch/njol/skript/lang/function/Function.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,12 @@ public Class<T> type() {
190190
}
191191

192192
@Override
193-
public @NotNull SequencedCollection<String> getReturnedKeys() {
194-
return Collections.emptyList();
193+
public final @NotNull SequencedCollection<String> getReturnedKeys() {
194+
String[] returnedKeys = returnedKeys();
195+
if (returnedKeys == null || returnedKeys.length == 0) {
196+
return Collections.emptyList();
197+
}
198+
return Arrays.asList(returnedKeys);
195199
}
196200

197201
/**

src/main/java/org/skriptlang/skript/common/function/DefaultFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ interface Builder<T> {
140140
* Completes this builder with the code to execute on call of this function.
141141
* Adds a function for setting the returned keys by this function.
142142
*
143-
* @param keys The function which sets the return keys.
143+
* @param keys The function which sets the return keys.
144144
* @param execute The code to execute and the key consumer.
145145
* @return The final function.
146146
*/
147147
DefaultFunction<T> buildKeyed(@NotNull java.util.function.Function<FunctionArguments, SequencedCollection<String>> keys,
148-
@NotNull java.util.function.Function<FunctionArguments, T> execute);
148+
@NotNull java.util.function.Function<FunctionArguments, T> execute);
149149

150150
}
151151

src/main/java/org/skriptlang/skript/common/function/DefaultFunctionImpl.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ public boolean resetReturnValue() {
153153
return returnedKeys.toArray(new String[0]);
154154
}
155155

156-
@Override
157-
public @NotNull SequencedCollection<String> getReturnedKeys() {
158-
return returnedKeys;
159-
}
160-
161156
@Override
162157
public @NotNull String name() {
163158
return getName();
@@ -290,7 +285,7 @@ public DefaultFunction<T> build(@NotNull Function<FunctionArguments, T> execute)
290285
Preconditions.checkNotNull(execute, "execute cannot be null");
291286

292287
return new DefaultFunctionImpl<>(source, name, parameters,
293-
returnType, !returnType.isArray(), contract, execute, (_) -> Collections.emptyList(),
288+
returnType, !returnType.isArray(), contract, execute, (args) -> Collections.emptyList(),
294289
description, since, examples, keywords, requires);
295290
}
296291

src/main/java/org/skriptlang/skript/common/function/Function.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.jetbrains.annotations.ApiStatus.Internal;
66
import org.jetbrains.annotations.ApiStatus.NonExtendable;
77
import org.jetbrains.annotations.NotNull;
8-
import org.jetbrains.annotations.Nullable;
98

109
import java.util.SequencedCollection;
1110

@@ -23,7 +22,7 @@ public interface Function<T> {
2322
/**
2423
* Executes this function with the given parameters.
2524
*
26-
* @param event The event that is associated with this function execution.
25+
* @param event The event that is associated with this function execution.
2726
* @param arguments The arguments to execute the function with.
2827
* @return The return value.
2928
*/
@@ -43,6 +42,7 @@ public interface Function<T> {
4342
/**
4443
* @return The returned keys.
4544
*/
45+
@Experimental
4646
@NotNull SequencedCollection<String> getReturnedKeys();
4747

4848
}

0 commit comments

Comments
 (0)