示例#1
0
  @UnsafeMethod
  public synchronized void enablePlugin(Plugin plugin) {
    if (!CommonPlugin.class.isAssignableFrom(plugin.getClass())) {
      throw new IllegalArgumentException(
          "Cannot enable plugin with this PluginLoader as it is of the wrong type!");
    }
    if (!plugin.isEnabled()) {
      CommonPlugin cp = (CommonPlugin) plugin;
      String name = cp.getDescription().getName();

      if (!loaders.containsKey(name)) {
        loaders.put(name, (CommonClassLoader) cp.getClassLoader());
      }

      try {
        cp.setEnabled(true);
        cp.onEnable();
      } catch (Throwable e) {
        engine
            .getLogger()
            .log(
                Level.SEVERE,
                "An error occured when enabling '"
                    + plugin.getDescription().getFullName()
                    + "': "
                    + e.getMessage(),
                e);
      }

      engine.getEventManager().callEvent(new PluginEnableEvent(cp));
    }
  }
示例#2
0
  /**
   * @param file Plugin file object
   * @return The current plugin's description element.
   * @throws InvalidPluginException
   * @throws InvalidDescriptionFileException
   */
  protected synchronized PluginDescriptionFile getDescription(File file)
      throws InvalidPluginException, InvalidDescriptionFileException {
    if (!file.exists()) {
      throw new InvalidPluginException(file.getName() + " does not exist!");
    }

    PluginDescriptionFile description = null;
    JarFile jar = null;
    InputStream in = null;
    try {
      // Spout plugin properties file
      jar = new JarFile(file);
      JarEntry entry = jar.getJarEntry(YAML_SPOUT);

      // Fallback plugin properties file
      if (entry == null) {
        entry = jar.getJarEntry(YAML_OTHER);
      }

      if (entry == null) {
        throw new InvalidPluginException("Jar has no properties.yml or plugin.yml!");
      }

      in = jar.getInputStream(entry);
      description = new PluginDescriptionFile(in);
    } catch (IOException e) {
      throw new InvalidPluginException(e);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {
          engine.getLogger().log(Level.WARNING, "Problem closing input stream", e);
        }
      }
      if (jar != null) {
        try {
          jar.close();
        } catch (IOException e) {
          engine.getLogger().log(Level.WARNING, "Problem closing jar input stream", e);
        }
      }
    }
    return description;
  }