3232import ch .njol .util .Kleenean ;
3333
3434import java .io .File ;
35+ import java .nio .file .Path ;
3536import java .util .ArrayList ;
37+ import java .util .Collections ;
3638import java .util .List ;
3739import java .util .regex .Pattern ;
40+ import java .util .stream .Collectors ;
3841
3942import org .bukkit .event .Event ;
4043
@@ -54,12 +57,12 @@ public class ExprScripts extends SimpleExpression<String> {
5457
5558 static {
5659 Skript .registerExpression (ExprScripts .class , String .class , ExpressionType .SIMPLE ,
57- "[all [of the]] scripts [( 1:without ([subdirectory] paths|parents) )]" ,
58- "[all [of the]] (enabled|loaded) scripts [( 1:without ([subdirectory] paths|parents) )]" ,
59- "[all [of the]] (disabled|unloaded) scripts [( 1:without ([subdirectory] paths|parents) )]" );
60+ "[all [of the]|the ] scripts [1:without ([subdirectory] paths|parents)]" ,
61+ "[all [of the]|the ] (enabled|loaded) scripts [1:without ([subdirectory] paths|parents)]" ,
62+ "[all [of the]|the ] (disabled|unloaded) scripts [1:without ([subdirectory] paths|parents)]" );
6063 }
6164
62- private static final String SCRIPTS_PATH = new File ( Skript .getInstance ().getDataFolder (), Skript . SCRIPTSFOLDER ). getPath () + File . separator ;
65+ private static final Path SCRIPTS_PATH = Skript .getInstance ().getScriptsFolder (). getAbsoluteFile (). toPath () ;
6366
6467 private boolean includeEnabled ;
6568 private boolean includeDisabled ;
@@ -75,20 +78,27 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
7578
7679 @ Override
7780 protected String [] get (Event event ) {
78- List <File > scripts = new ArrayList <>();
81+ List <Path > scripts = new ArrayList <>();
7982 if (includeEnabled ) {
8083 for (Script script : ScriptLoader .getLoadedScripts ())
81- scripts .add (script .getConfig ().getFile ());
84+ scripts .add (script .getConfig ().getPath ());
8285 }
8386 if (includeDisabled )
84- scripts .addAll (ScriptLoader .getDisabledScripts ());
85- return formatFiles (scripts );
87+ scripts .addAll (ScriptLoader .getDisabledScripts ()
88+ .stream ()
89+ .map (File ::toPath )
90+ .collect (Collectors .toList ()));
91+ return formatPaths (scripts );
8692 }
8793
8894 @ SuppressWarnings ("null" )
89- private String [] formatFiles (List <File > files ) {
90- return files .stream ()
91- .map (f -> noPaths ? f .getName () : f .getPath ().replaceFirst (Pattern .quote (SCRIPTS_PATH ), "" ))
95+ private String [] formatPaths (List <Path > paths ) {
96+ return paths .stream ()
97+ .map (path -> {
98+ if (noPaths )
99+ return path .getFileName ();
100+ return SCRIPTS_PATH .relativize (path .toAbsolutePath ()).toString ();
101+ })
92102 .toArray (String []::new );
93103 }
94104
0 commit comments