Package org.bukkit.plugin

Examples of org.bukkit.plugin.PluginDescriptionFile


    @SuppressWarnings("unchecked")
    private Plugin loadPlugin(File file, boolean ignoreSoftDependencies, PluginDataFile data) throws InvalidPluginException/*, InvalidDescriptionException, UnknownDependencyException*/ {
        System.out.println("[PythonLoader] Loading Plugin " + file.getName());
        PythonPlugin result = null;
        PluginDescriptionFile description = null;
        boolean hasyml = true;
        boolean hassolidmeta = false; // whether we have coder-set metadata. true for have set metadata, false for inferred metadata.
        try {
            InputStream stream = data.getStream("plugin.yml");
            if (stream == null)
                hasyml = false;

            if (hasyml) {
                description = new PluginDescriptionFile(stream);
                hassolidmeta = true;
            } else {
                String stripped = stripExtension(file.getName());
                if (stripped == null)
                    //throw new BukkitScrewedUpException("This would only occur if bukkit called the loader on a plugin which does not match the loader's regex.");
                    throw new InvalidPluginException(new Exception("This shouldn't be happening; go tell whoever altered the plugin loading api in bukkit that they're whores."));
                description = new PluginDescriptionFile(stripped, "dev", "plugin.py");
            }
            if (stream != null)
                stream.close();
        } catch (IOException ex) {
            throw new InvalidPluginException(ex);
        } catch (YAMLException ex) {
            throw new InvalidPluginException(ex);
        } catch (InvalidDescriptionException ex) {
            throw new InvalidPluginException(ex);
        }

        File dataFolder = new File(file.getParentFile(), description.getName());

        if (dataFolder.getAbsolutePath().equals(file.getAbsolutePath())) {
            throw new InvalidPluginException(new Exception(String.format("Projected datafolder: '%s' for %s is the same file as the plugin itself (%s)",
                    dataFolder,
                    description.getName(),
                    file)));
        }

        if (dataFolder.exists() && !dataFolder.isDirectory()) {
            throw new InvalidPluginException(new Exception(String.format("Projected datafolder: '%s' for %s (%s) exists and is not a directory",
                    dataFolder,
                    description.getName(),
                    file)));
        }

        ArrayList<String> depend;

        try {
            depend = (ArrayList<String>) description.getDepend();
            if (depend == null) {
                depend = new ArrayList<String>();
            }
        } catch (ClassCastException ex) {
            throw new InvalidPluginException(ex);
        }

        for (String pluginName : depend) {
            if (!isPluginLoaded(pluginName)) {
                throw new UnknownDependencyException(pluginName);
            }
        }

        PyList pythonpath = Py.getSystemState().path;
        PyString filepath = new PyString(file.getAbsolutePath());
        if (data.shouldAddPathEntry()) {
            if (pythonpath.__contains__(filepath)) {
                throw new InvalidPluginException(new Exception("path " + filepath
                        + " already on pythonpath!")); //can't imagine how this would happen, but better safe than sorry
            }
            pythonpath.append(filepath);
        }


        String mainfile = description.getMain();
        InputStream instream = null;
        try {
            instream = data.getStream(mainfile);

            if (instream == null) {
                mainfile = "plugin.py";
                instream = data.getStream(mainfile);
            }
            if (instream == null) {
                mainfile = "main.py";
                instream = data.getStream(mainfile);
            }
        } catch (IOException e) {
            throw new InvalidPluginException(e);
        }

        if (instream == null) {
            throw new InvalidPluginException(new FileNotFoundException("Data file does not contain "+mainfile));
        }
        try {
            PythonHooks hook = new PythonHooks(description);

            PythonInterpreter interp = new PythonInterpreter();

            interp.set("hook", hook);
            interp.set("info", description);
           
            // Decorator Enhancements
            interp.exec("import __builtin__");
            interp.exec("__builtin__.hook = hook");
            interp.exec("__builtin__.info = info");
           
            // Hardcoded for now, may be worth thinking about generalizing it as sort of "addons" for the PythonPluginLoader
            // Could be used to extend the capabilities of python plugins the same way the metaclass decorators do, without requiring any changes to the PythonPluginLoader itself
            String[] pre_plugin_scripts = {"imports.py", "meta_decorators.py"};
            String[] post_plugin_scripts = {"meta_loader.py"};
           
            // Run scripts designed to be run before plugin creation
            for (String script : pre_plugin_scripts) {
              InputStream metastream = this.getClass().getClassLoader().getResourceAsStream("scripts/"+script);
              interp.execfile(metastream);
              metastream.close();
            }

            interp.execfile(instream);

            instream.close();

            try {
                if (!hasyml) {
                    Object name = interp.get("__plugin_name__");
                    Object version = interp.get("__plugin_version__");
                    Object website = interp.get("__plugin_website__");
                    Object main = interp.get("__plugin_mainclass__");
                    hassolidmeta = name != null && version != null;
                    if (name != null)
                        ReflectionHelper.setPrivateValue(description, "name", name.toString());
                    if (version != null)
                        ReflectionHelper.setPrivateValue(description, "version", version.toString());
                    if (website != null)
                        ReflectionHelper.setPrivateValue(description, "website", website.toString());
                    if (main != null)
                        ReflectionHelper.setPrivateValue(description, "main", main.toString());
                }
            } catch (Throwable t) {
                Logger.getLogger("Minecraft").log(Level.SEVERE, "Error while setting python-set description values", t);
            }

            String mainclass = description.getMain();
            PyObject pyClass = interp.get(mainclass);
            if (pyClass == null)
                pyClass = interp.get("Plugin");
            if (pyClass == null)
                result = new PythonPlugin();
            else
                result = (PythonPlugin) pyClass.__call__().__tojava__(PythonPlugin.class);
           
            interp.set("pyplugin", result);
           
            result.hooks = hook;
            result.interp = interp;
           
            // Run scripts designed to be run after plugin creation
            for (String script : post_plugin_scripts) {
              InputStream metastream = this.getClass().getClassLoader().getResourceAsStream("scripts/"+script);
              interp.execfile(metastream);
              metastream.close();
            }
           
            result.initialize(this, server, description, dataFolder, file);
            result.setDataFile(data);
           
        } catch (Throwable t) {
            if (data.shouldAddPathEntry() && pythonpath.__contains__(filepath)) {
                pythonpath.remove(filepath);
            }
            throw new InvalidPluginException(t);
        }

        if (data.getNeedsSolidMeta() && !hassolidmeta) {
            throw new InvalidPluginException(new Exception("Released plugins require either a plugin.yml or both __plugin_name__ and __plugin_version__ set in the main python file!"));
        }

        if (!loadedplugins.contains(description.getName()))
            loadedplugins.add(description.getName());
        return result;
    }
View Full Code Here


            if(stream == null) {
                //TODO Does this cause serious problems with plugins which have no plugin.yml file?
                throw new InvalidDescriptionException(new InvalidPluginException(new FileNotFoundException("Jar does not contain plugin.yml")));
            }

            return new PluginDescriptionFile(stream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(stream != null) {
                try {
View Full Code Here

    /**
     * Generic method that posts a plugin to the metrics website
     */
    private void postPlugin(boolean isPing) throws IOException {
        // Server software specific section
        PluginDescriptionFile description = plugin.getDescription();
        String pluginName = description.getName();
        boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
        String pluginVersion = description.getVersion();
        String serverVersion = Bukkit.getVersion();
        int playersOnline = Bukkit.getServer().getOnlinePlayers().length;

        // END server software specific section -- all code below does not use any code outside of this class / Java

View Full Code Here

    }

    public void onDisable() {

        PluginDescriptionFile pdfFile = this.getDescription();

        if(lagMeasureTask != null) {
            lagMeasureTask.cancel();
            lagMeasureTask = null;
        }

        if(conf != null) {
            conf.cleanup();
            conf = null;
        }

        // Just to be sure nothing gets left out
        getServer().getScheduler().cancelTasks(this);

        commandHandler = null;

        System.out.println("[NoCheat] version [" + pdfFile.getVersion() + "] is disabled.");
    }
View Full Code Here

            // Let's let all MV files go to bin/test
            doReturn(pluginDirectory).when(core).getDataFolder();

            // Return a fake PDF file.
            PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Multiverse-Core", "2.2-Test",
                    "com.onarandombox.MultiverseCore.MultiverseCore"));
            when(pdf.getAuthors()).thenReturn(new ArrayList<String>());
            doReturn(pdf).when(core).getDescription();
            doReturn(true).when(core).isEnabled();
            doReturn(Util.logger).when(core).getLogger();
            core.setServerFolder(serverDirectory);
View Full Code Here

    /**
* Generic method that posts a plugin to the metrics website
*/
    private void postPlugin(final boolean isPing) throws IOException {
        // Server software specific section
        PluginDescriptionFile description = plugin.getDescription();
        String pluginName = description.getName();
        boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
        String pluginVersion = description.getVersion();
        String serverVersion = Bukkit.getVersion();
        int playersOnline = Bukkit.getServer().getOnlinePlayers().length;

        // END server software specific section -- all code below does not use any code outside of this class / Java

View Full Code Here

    /**
     * Generic method that posts a plugin to the metrics website
     */
    private void postPlugin(final boolean isPing) throws IOException {
        // The plugin's description file containg all of the plugin data such as name, version, author, etc
        final PluginDescriptionFile description = plugin.getDescription();

        // Construct the post data
        final StringBuilder data = new StringBuilder();
        data.append(encode("guid")).append('=').append(encode(guid));
        encodeDataPair(data, "version", description.getVersion());
        encodeDataPair(data, "server", Bukkit.getVersion());
        encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length));
        encodeDataPair(data, "revision", String.valueOf(REVISION));

        // If we're pinging, append it
View Full Code Here

  /**
   * Generic method that posts a plugin to the metrics website
   */
  private void postPlugin(final boolean isPing) throws IOException {
    // Server software specific section
    PluginDescriptionFile description = plugin.getDescription();
    String pluginName = description.getName();
    boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
    String pluginVersion = description.getVersion();
    String serverVersion = Bukkit.getVersion();
    int playersOnline = Bukkit.getServer().getOnlinePlayers().length;

    // END server software specific section -- all code below does not use any code outside of this class / Java

View Full Code Here

    /**
     * Generic method that posts a plugin to the metrics website
     */
    private void postPlugin(final boolean isPing) throws IOException {
        // Server software specific section
        PluginDescriptionFile description = plugin.getDescription();
        String pluginName = description.getName();
        boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
        String pluginVersion = description.getVersion();
        String serverVersion = Bukkit.getVersion();
        int playersOnline = helper.getOnlinePlayers().length;

        // END server software specific section -- all code below does not use any code outside of this class / Java

View Full Code Here

    public void onEnable() {
        if (helper == null) {
            Log.info("Dynmap is disabled (unsupported platform)");
            return;
        }
        PluginDescriptionFile pdfFile = this.getDescription();
        version = pdfFile.getVersion();

        /* Get MC version */
        String bukkitver = getServer().getVersion();
        String mcver = "1.0.0";
        int idx = bukkitver.indexOf("(MC: ");
View Full Code Here

TOP

Related Classes of org.bukkit.plugin.PluginDescriptionFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.