Skip to content

Commit e43c37e

Browse files
authored
Fix script is loaded condition in effect commands (SkriptLang#4480)
1 parent bc8458f commit e43c37e

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/main/java/ch/njol/skript/conditions/CondScriptLoaded.java

+16-10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.File;
2222

23+
import ch.njol.skript.config.Config;
2324
import org.bukkit.event.Event;
2425
import org.eclipse.jdt.annotation.Nullable;
2526

@@ -32,7 +33,7 @@
3233
import ch.njol.skript.doc.Since;
3334
import ch.njol.skript.lang.Condition;
3435
import ch.njol.skript.lang.Expression;
35-
import ch.njol.skript.lang.SkriptParser;
36+
import ch.njol.skript.lang.SkriptParser.ParseResult;
3637
import ch.njol.util.Kleenean;
3738

3839
@Name("Is Script Loaded")
@@ -52,21 +53,27 @@ public class CondScriptLoaded extends Condition {
5253
@Nullable
5354
private File currentScriptFile;
5455

55-
@SuppressWarnings({"unchecked"})
5656
@Override
57-
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
57+
@SuppressWarnings({"unchecked"})
58+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
5859
scripts = (Expression<String>) exprs[0];
5960
setNegated(matchedPattern == 1);
60-
assert getParser().getCurrentScript() != null;
61-
currentScriptFile = getParser().getCurrentScript().getFile();
61+
Config cs = getParser().getCurrentScript();
62+
if (cs == null && scripts == null) {
63+
Skript.error("The condition 'script loaded' requires a script name argument when used outside of script files");
64+
return false;
65+
} else if (cs != null) {
66+
currentScriptFile = cs.getFile();
67+
}
6268
return true;
6369
}
64-
70+
6571
@Override
6672
public boolean check(Event e) {
67-
Expression<String> scripts = this.scripts;
6873
if (scripts == null) {
69-
return ScriptLoader.getLoadedFiles().contains(currentScriptFile);
74+
if (currentScriptFile == null)
75+
return isNegated();
76+
return ScriptLoader.getLoadedFiles().contains(currentScriptFile) ^ isNegated();
7077
}
7178

7279
return scripts.check(e,
@@ -76,9 +83,8 @@ public boolean check(Event e) {
7683

7784
@Override
7885
public String toString(@Nullable Event e, boolean debug) {
79-
Expression<String> scripts = this.scripts;
80-
8186
String scriptName;
87+
8288
if (scripts == null)
8389
scriptName = "script";
8490
else

0 commit comments

Comments
 (0)