Beispiel #1
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;
 }
Beispiel #2
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();
   }
 }
Beispiel #3
0
 private YamlConfiguration getDefaultConfig() {
   try {
     Map<String, Object> defmap =
         (Map<String, Object>) Utils.getOrExcept((ScriptEngine) sEngine, "DEFAULT_CONFIG");
     YamlConfiguration yamldef = new YamlConfiguration();
     Utils.callMethodHelper(yamldef, "deserializeValues", defmap, yamldef);
     return yamldef;
   } catch (IllegalArgumentException e) {
   } catch (Throwable t) {
     log(Level.SEVERE, "Failed to get default config!", t);
   }
   return null;
 }
Beispiel #4
0
 public ScriptPlugin(PluginLoader pluginLoader, Server instance, File plugin, ScriptEngine engine)
     throws InvalidDescriptionException {
   loader = pluginLoader;
   server = instance;
   file = plugin;
   rdescription = (Map<String, Object>) Utils.getOrExcept(engine, "SCRIPT_PDF");
   description = Utils.getPdfFromMap(rdescription);
   logger = Logger.getLogger("Minecraft.JxplPlugin." + description.getName());
   dataFolder = initialiseDataFolder();
   helper = new PluginHelper();
   engine.put(Utils.getOrDefault(rdescription, "jxpl.helpervarname", "helper"), helper);
   engine.put(Utils.getOrDefault(rdescription, "jxpl.pluginvarname", "plugin"), this);
   engine.put(Utils.getOrDefault(rdescription, "jxpl.servervarname", "server"), server);
   sEngine = (Invocable) engine;
   if (dataFolder != null && Utils.getOrDefault(rdescription, "jxpl.hasconfig", false)) {
     configFile = new File(dataFolder, "config.yml");
   } else {
     configFile = null;
   }
 }