From e43c37e02a8508137bf4e114f0f79880cc9cc283 Mon Sep 17 00:00:00 2001 From: Ayham Al Ali Date: Tue, 18 Jan 2022 18:12:14 +0200 Subject: [PATCH] Fix script is loaded condition in effect commands (#4480) --- .../skript/conditions/CondScriptLoaded.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondScriptLoaded.java b/src/main/java/ch/njol/skript/conditions/CondScriptLoaded.java index a27ddda42ea..027850b3195 100644 --- a/src/main/java/ch/njol/skript/conditions/CondScriptLoaded.java +++ b/src/main/java/ch/njol/skript/conditions/CondScriptLoaded.java @@ -20,6 +20,7 @@ import java.io.File; +import ch.njol.skript.config.Config; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; @@ -32,7 +33,7 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; @Name("Is Script Loaded") @@ -52,21 +53,27 @@ public class CondScriptLoaded extends Condition { @Nullable private File currentScriptFile; - @SuppressWarnings({"unchecked"}) @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + @SuppressWarnings({"unchecked"}) + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { scripts = (Expression) exprs[0]; setNegated(matchedPattern == 1); - assert getParser().getCurrentScript() != null; - currentScriptFile = getParser().getCurrentScript().getFile(); + Config cs = getParser().getCurrentScript(); + if (cs == null && scripts == null) { + Skript.error("The condition 'script loaded' requires a script name argument when used outside of script files"); + return false; + } else if (cs != null) { + currentScriptFile = cs.getFile(); + } return true; } - + @Override public boolean check(Event e) { - Expression scripts = this.scripts; if (scripts == null) { - return ScriptLoader.getLoadedFiles().contains(currentScriptFile); + if (currentScriptFile == null) + return isNegated(); + return ScriptLoader.getLoadedFiles().contains(currentScriptFile) ^ isNegated(); } return scripts.check(e, @@ -76,9 +83,8 @@ public boolean check(Event e) { @Override public String toString(@Nullable Event e, boolean debug) { - Expression scripts = this.scripts; - String scriptName; + if (scripts == null) scriptName = "script"; else