jessefjxm

java

May 9th, 2021
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public static boolean simpleCheck(String path) {
  2. try {
  3. ScriptEngineManager sem = new ScriptEngineManager();
  4. ScriptEngine engine = sem.getEngineByName("nashorn");
  5. File js = new File(path);
  6. String script = FileUtils.readFileToString(js, StandardCharsets.UTF_8);
  7. engine.eval(script);
  8. Invocable iv = (Invocable) engine;
  9. ScriptEngine scriptengine = (ScriptEngine) iv;
  10. scriptengine.put("cm", new TestA());
  11. iv.invokeFunction("start");
  12. return false;
  13. } catch (Throwable ex) {
  14. ex.printStackTrace();
  15. return ex.getMessage().contains("is not a function");
  16. }
  17. }
  18.  
  19. public static class TestA {
  20. private final TestPlayer player = new TestPlayer();
  21.  
  22. public TestPlayer getPlayer() {
  23. return player;
  24. }
  25.  
  26. public void dispose() {
  27. }
  28.  
  29. public int getNumberFromQuestInfo(int i, String s) {
  30. return 0;
  31. }
  32. }
  33.  
  34. public static class TestPlayer {
  35. public String getInfoQuest(int i) {
  36. return "";
  37. }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment