Skip to content

Commit

Permalink
Merge branch 'dev/patch' into fix/gradle-encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky authored Oct 9, 2023
2 parents f0ca59e + da97d3e commit 5e0f3c6
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/main/java/ch/njol/skript/effects/EffScriptFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Set;

@Name("Enable/Disable/Reload Script File")
@Description("Enables, disables, or reloads a script file.")
Expand Down Expand Up @@ -102,10 +103,8 @@ protected void execute(Event e) {
case RELOAD: {
if (ScriptLoader.getDisabledScriptsFilter().accept(scriptFile))
return;

Script script = ScriptLoader.getScript(scriptFile);
if (script != null)
ScriptLoader.unloadScript(script);

this.unloadScripts(scriptFile);

ScriptLoader.loadScripts(scriptFile, OpenCloseable.EMPTY);
break;
Expand All @@ -114,9 +113,7 @@ protected void execute(Event e) {
if (ScriptLoader.getDisabledScriptsFilter().accept(scriptFile))
return;

Script script = ScriptLoader.getScript(scriptFile);
if (script != null)
ScriptLoader.unloadScript(script);
this.unloadScripts(scriptFile);

try {
FileUtils.move(
Expand All @@ -135,6 +132,19 @@ protected void execute(Event e) {
assert false;
}
}

private void unloadScripts(File file) {
if (file.isDirectory()) {
Set<Script> scripts = ScriptLoader.getScripts(file);
if (scripts.isEmpty())
return;
ScriptLoader.unloadScripts(scripts);
} else {
Script script = ScriptLoader.getScript(file);
if (script != null)
ScriptLoader.unloadScript(script);
}
}

@Override
public String toString(@Nullable Event e, boolean debug) {
Expand Down

0 comments on commit 5e0f3c6

Please sign in to comment.