1212import mx .kenzie .jupiter .stream .Stream ;
1313import org .byteskript .skript .api .Library ;
1414import org .byteskript .skript .api .SyntaxElement ;
15+ import org .byteskript .skript .api .resource .ClassResource ;
16+ import org .byteskript .skript .api .resource .Resource ;
1517import org .byteskript .skript .api .syntax .InnerModifyExpression ;
1618import org .byteskript .skript .api .syntax .Section ;
1719import org .byteskript .skript .compiler .structure .ErrorDetails ;
@@ -44,18 +46,38 @@ protected static synchronized int getAnonymous() {
4446 return ++anonymous ;
4547 }
4648
47- @ Override
48- public PostCompileClass compileClass (InputStream source ) {
49- return this .compile (source )[0 ];
49+ public Resource compileClassWithResources (InputStream source ) {
50+ return this .compileWithResources (source )[0 ];
5051 }
5152
52- @ Override
53- public PostCompileClass [] compile (InputStream source ) {
53+ public Resource [] compileWithResources (InputStream source ) {
5454 final int index = getAnonymous ();
5555 final String path = "skript/unknown_" + index ;
5656 return this .compile (source , path );
5757 }
58-
58+
59+ @ Override
60+ public PostCompileClass compileClass (InputStream inputStream ) {
61+ final Resource compiled = compileClassWithResources (inputStream );
62+ if (!(compiled instanceof final ClassResource compiledClass ))
63+ throw new ScriptCompileError (-1 , "The script included resources when only one class was expected." );
64+
65+ return compiledClass .source ();
66+ }
67+
68+ @ Override
69+ public PostCompileClass [] compile (InputStream inputStream ) {
70+ final Resource [] compiled = compileWithResources (inputStream );
71+ final List <PostCompileClass > classes = new ArrayList <>();
72+ for (final Resource resource : compiled ) {
73+ if (!(resource instanceof final ClassResource compiledClass ))
74+ throw new ScriptCompileError (-1 , "The script included resources when only classes were expected." );
75+ classes .add (compiledClass .source ());
76+ }
77+
78+ return classes .toArray (new PostCompileClass [0 ]);
79+ }
80+
5981 @ Override
6082 public void compileAndLoad (InputStream inputStream ) {
6183 throw new ScriptCompileError (-1 , "This compiler does not support this feature." );
@@ -304,7 +326,7 @@ public boolean removeLibrary(Library library) {
304326 }
305327
306328 @ Override
307- public PostCompileClass [] compile (InputStream stream , Type path ) {
329+ public Resource [] compile (InputStream stream , Type path ) {
308330 final FileContext context = this .createContext (path );
309331 context .libraries .addAll (libraries );
310332 for (final Library library : libraries ) {
@@ -323,13 +345,13 @@ public PostCompileClass[] compile(InputStream stream, Type path) {
323345 }
324346
325347 @ Override
326- public PostCompileClass [] compile (InputStream source , String path ) {
327- if (path == null ) return this .compile (source );
348+ public Resource [] compile (InputStream source , String path ) {
349+ if (path == null ) return this .compileWithResources (source );
328350 return compile (source , new Type (path ));
329351 }
330352
331353 @ Override
332- public PostCompileClass [] compile (String source , Type path ) {
354+ public Resource [] compile (String source , Type path ) {
333355 final FileContext context = this .createContext (path );
334356 context .libraries .addAll (libraries );
335357 for (final Library library : libraries ) {
0 commit comments