public void reloadScript() { onDisable(); try { ScriptEngine engine = ((ScriptLoader) loader).getScriptEngine(file); engine.put(Utils.getStringOrDefault(engine, "HELPER_VARIABLE_NAME", "helper"), helper); engine.put(Utils.getStringOrDefault(engine, "PLUGIN_VARIABLE_NAME", "plugin"), this); engine.put(Utils.getStringOrDefault(engine, "SERVER_VARIABLE_NAME", "server"), server); sEngine = (Invocable) engine; } catch (FileNotFoundException fnfe) { log( Level.SEVERE, String.format( "Not reloading script \"%s\"; file not found. Was the script file moved or deleted?", file.getName()), fnfe); } catch (ScriptException sex) { log( Level.SEVERE, String.format("Not reloading script \"%s\"; error while parsing script.", file.getName()), sex); } catch (InvalidPluginException ipe) { log( Level.SEVERE, String.format( "Not reloading script \"%s\"; someone broke jxpl via reflection.", file.getName()), ipe); } finally { onEnable(); } }
private Object tryInvoke(String f, boolean stfu, Object... p) { try { return sEngine.invokeFunction(f, p); } catch (Throwable e) { if (!stfu) { log(Level.SEVERE, "Error while running " + f + " of script " + file.getName() + ".", e); } } return null; }