33import java .io .File ;
44import java .io .FileFilter ;
55import java .io .FileReader ;
6- import java .nio .file .Files ;
76import java .nio .file .Paths ;
87
98import com .google .gson .JsonObject ;
1413
1514import org .graalvm .polyglot .Context ;
1615import org .graalvm .polyglot .Value ;
16+ import org .graalvm .polyglot .Source ;
1717
1818/**
1919 * Hello world!
@@ -80,29 +80,21 @@ public boolean accept(File f) {
8080 if (!pkgJson .has ("main" )) continue ;
8181
8282 pkgJsonMain = pkgJson .get ("main" ).getAsString ();
83-
83+
8484 jsPluginFile = new File (pluginSubDir .getAbsoluteFile () + "/" + pkgJsonMain );
8585 if (!jsPluginFile .exists ()) {
8686 System .err .println ("Couldn't import 'main' : " + jsPluginFile .toPath () + ", ignoring!" );
8787 continue ;
8888 }
89-
9089 try {
91- this .ctx .eval ("js" , new String (Files .readAllBytes (jsPluginFile .toPath ())));
90+ Source src = Source .newBuilder ("js" , jsPluginFile ).build ();
91+ this .ctx .eval (src );
9292 } catch (Exception e ) {
93- //Technically we already handled this, just skip this script
93+ //Just skip this script
9494 e .printStackTrace ();
9595 continue ;
9696 }
9797 }
98-
99- try {
100- this .ctx .eval ("js" , "print('[js] Hello World');" );
101- } catch (Exception ex ) {
102- System .err .println (ex );
103- return ;
104- }
105-
10698 jsc = new JSCommand (this );
10799
108100 this .getCommand ("js" ).setExecutor (this .jsc );
@@ -118,6 +110,5 @@ public void put(String key, Object value) {
118110
119111 @ Override
120112 public void onDisable () {
121-
122113 }
123114}
0 commit comments