20
20
21
21
import java .io .File ;
22
22
23
+ import ch .njol .skript .config .Config ;
23
24
import org .bukkit .event .Event ;
24
25
import org .eclipse .jdt .annotation .Nullable ;
25
26
32
33
import ch .njol .skript .doc .Since ;
33
34
import ch .njol .skript .lang .Condition ;
34
35
import ch .njol .skript .lang .Expression ;
35
- import ch .njol .skript .lang .SkriptParser ;
36
+ import ch .njol .skript .lang .SkriptParser . ParseResult ;
36
37
import ch .njol .util .Kleenean ;
37
38
38
39
@ Name ("Is Script Loaded" )
@@ -52,21 +53,27 @@ public class CondScriptLoaded extends Condition {
52
53
@ Nullable
53
54
private File currentScriptFile ;
54
55
55
- @ SuppressWarnings ({"unchecked" })
56
56
@ 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 ) {
58
59
scripts = (Expression <String >) exprs [0 ];
59
60
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
+ }
62
68
return true ;
63
69
}
64
-
70
+
65
71
@ Override
66
72
public boolean check (Event e ) {
67
- Expression <String > scripts = this .scripts ;
68
73
if (scripts == null ) {
69
- return ScriptLoader .getLoadedFiles ().contains (currentScriptFile );
74
+ if (currentScriptFile == null )
75
+ return isNegated ();
76
+ return ScriptLoader .getLoadedFiles ().contains (currentScriptFile ) ^ isNegated ();
70
77
}
71
78
72
79
return scripts .check (e ,
@@ -76,9 +83,8 @@ public boolean check(Event e) {
76
83
77
84
@ Override
78
85
public String toString (@ Nullable Event e , boolean debug ) {
79
- Expression <String > scripts = this .scripts ;
80
-
81
86
String scriptName ;
87
+
82
88
if (scripts == null )
83
89
scriptName = "script" ;
84
90
else
0 commit comments