From cca152532c7a7f4987ef9748f94c76a0b95366ad Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:13:36 +1000 Subject: [PATCH] Fix Edge Case Running Status of Sandbox (#205) * Fix Edge Case Running Status of Sandbox * Proper Fix --- .../com/cleanroommc/groovyscript/sandbox/GroovySandbox.java | 5 +++-- .../groovyscript/sandbox/GroovyScriptSandbox.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovySandbox.java b/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovySandbox.java index 7c4abe4aa..21f525bb5 100644 --- a/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovySandbox.java +++ b/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovySandbox.java @@ -168,7 +168,8 @@ protected void runScript(Script script){ } public T runClosure(Closure closure, Object... args) { - startRunning(); + boolean wasRunning = isRunning(); + if (!wasRunning) startRunning(); T result = null; try { result = closure.call(args); @@ -176,7 +177,7 @@ public T runClosure(Closure closure, Object... args) { GroovyScript.LOGGER.error("Caught an exception trying to run a closure:"); e.printStackTrace(); } finally { - stopRunning(); + if (!wasRunning) stopRunning(); } return result; } diff --git a/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyScriptSandbox.java b/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyScriptSandbox.java index ac97f4abb..279c0e6b9 100644 --- a/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyScriptSandbox.java +++ b/src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyScriptSandbox.java @@ -178,7 +178,8 @@ public void load() throws Exception { @ApiStatus.Internal @Override public T runClosure(Closure closure, Object... args) { - startRunning(); + boolean wasRunning = isRunning(); + if (!wasRunning) startRunning(); T result = null; try { result = runClosureInternal(closure, args); @@ -189,7 +190,7 @@ public T runClosure(Closure closure, Object... args) { return new AtomicInteger(); }).addAndGet(1); } finally { - stopRunning(); + if (!wasRunning) stopRunning(); } return result; }