Skip to content

Commit

Permalink
Fix script is loaded condition in effect commands (SkriptLang#4480)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyhamAl-Ali authored Jan 18, 2022
1 parent bc8458f commit e43c37e
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/main/java/ch/njol/skript/conditions/CondScriptLoaded.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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")
Expand All @@ -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<String>) 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<String> 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,
Expand All @@ -76,9 +83,8 @@ public boolean check(Event e) {

@Override
public String toString(@Nullable Event e, boolean debug) {
Expression<String> scripts = this.scripts;

String scriptName;

if (scripts == null)
scriptName = "script";
else
Expand Down

0 comments on commit e43c37e

Please sign in to comment.