예제 #1
0
 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();
   }
 }
예제 #2
0
 private File initialiseDataFolder() {
   if (Utils.getOrDefault(rdescription, "jxpl.hasdatafolder", false)) {
     File tempFolder = new File(file.getParentFile(), description.getName());
     if (Utils.dirExistOrCreate(tempFolder)) return tempFolder;
   }
   return null;
 }
예제 #3
0
 /**
  * Includes a script.
  *
  * @param f The file describing the script file to be included
  * @return result Object of eval if successful, null otherwise
  */
 public Object includeScript(File f) {
   Object result = null;
   try {
     FileReader fr = new FileReader(f);
     try {
       result = ((ScriptEngine) ScriptPlugin.this.sEngine).eval(fr);
     } catch (Throwable t) {
       log(
           Level.SEVERE,
           "Failed to include script " + f.getPath() + " from " + file.getPath(),
           t);
     }
     fr.close();
   } catch (Throwable t) {
     log(Level.SEVERE, "Failed to read file " + f.getPath() + " from " + file.getPath(), t);
   }
   return result;
 }
예제 #4
0
 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;
 }
예제 #5
0
 @Override
 public void saveDefaultConfig() {
   if (configFile != null && !configFile.exists()) {
     YamlConfiguration def = getDefaultConfig();
     try {
       if (def != null) def.save(configFile);
     } catch (IOException e) {
       log(Level.SEVERE, "Failed to save default configuration file.", e);
     }
   }
 }