Skip to content

Commit

Permalink
Truncate functionArgs if task function accepts less args than number …
Browse files Browse the repository at this point in the history
…of args passed
  • Loading branch information
magicmq committed Apr 1, 2024
1 parent 2e94374 commit f7c9d54
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/dev/magicmq/pyspigot/manager/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import dev.magicmq.pyspigot.manager.script.Script;
import dev.magicmq.pyspigot.manager.script.ScriptManager;
import org.bukkit.scheduler.BukkitRunnable;
import org.python.core.Py;
import org.python.core.PyException;
import org.python.core.PyFunction;
import org.python.core.PyObject;
import org.python.core.*;

import java.util.Arrays;

/**
* Represents a task defined by a script.
Expand All @@ -42,7 +41,14 @@ public class Task extends BukkitRunnable {
public Task(Script script, PyFunction function, Object[] functionArgs) {
this.script = script;
this.function = function;
this.functionArgs = functionArgs;

if (functionArgs != null) {
int numOfFunctionArgs = ((PyBaseCode) function.__code__).co_argcount;
if (numOfFunctionArgs < functionArgs.length)
functionArgs = Arrays.copyOf(functionArgs, numOfFunctionArgs);
this.functionArgs = functionArgs;
} else
this.functionArgs = null;
}

/**
Expand Down

0 comments on commit f7c9d54

Please sign in to comment.