Plugin dependency override JavaPluginLoader

Discussion in 'Plugin Development' started by brord, Jul 9, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    brord

    Hello!

    Im working on a plugin which loads plugins from a global folder.
    This could be used for 1 server group with multiple servers, which all use the same plugin(s)
    This will mean less time to update :)

    Features i have now:
    - Global plugins
    - Global Configs

    But the problem is, when bukkit loads, it checks for the description files -> depends: [] part, and then iterates over the plugins in the /plugins/ directory.
    Now, my plugins are in a different directory, so i keep getting UnknownDependency Error.
    I have a fix fir it, and everything works, btut i would love to know if there is a way to "add" a folder of which bukkit reads from.

    You can find my source code here: https://github.com/kwek20/GlobalPlugins
    If you have any polite comments, or informative suggestions, please leave them in the comments!

    Thanks in advance
     
  2. Offline

    LinearLogic


    The loadPlugins(File directory) method in SimplePluginManager (CB's default implementation of PluginManager) performs every operation involved in loading plugins, including handling of dependencies. The plugin directory is provided to the plugin manager in this method in CraftServer.

    See if you can point the method to your "global" plugin directory, but it looks like trying to change the plugin directory requires modifying MinecraftServer's OptionSet object, which buries you in NMS... My guess is you won't be able to achieve it with anything less than a CB fork.
     
  3. Offline

    rmh4209

    If you can modify the command line when the server starts, adding a "-P foldername" at the end of the command (without the quotation marks, obviously) will change from which folder Bukkit reads plugins.
     
  4. Offline

    LinearLogic

    I was under the impression that he was trying to achieve that effect through code, but if not, he has his answer!
     
  5. Offline

    brord

    Thanks for your comments! I allready have everything working, like plugin loading etc.
    But the real problem is that the plugins from the /plugins directory do not know about the existance from the /globalplugins/ directory. And it is possible for lpugins to load before the plugins from globalplugins.
    And incase the plugins from /plugins/ have a "depend" on a plugin from /globalplugins/ =, it will throw an UnknownDependencyException because it doesnt know about the other plugins.
    I have fixed it by, after the server is loaded, try to load those plugins again, which works fine unless there is a depend on a depend plugin.

    But the rela question is if there is a way to fix this. Like a plugin.yml: "loadbefore: [allplugins]"
    Aka, how to force my plugin to load before ANY OTHER plugin? Because i cant just add the names of every plugin :)

    Thanks in advance
     
  6. Offline

    LinearLogic

    Only plugins that are dependencies need the loadbefore node, and only the plugins that depend on them need to be entered in loadbefore. This would mean a number of plugin dependency/depending pairs, but most plugins wouldn't need to be altered.
     
  7. Offline

    brord

    ill lookinto "load: startup" now, maybe that fixes some things.
    Ill otherwise add the major plugins to depend, yea :)
     
  8. Offline

    brord

    Allright, i have thought of a solution ,jsut dont know how to do it yet.
    My plan is to override the JavaPluginLoader class and modify it, so that it reads from the defined folder too.
    This will require a reboot of the server to succeed.
    1. override .class file
    2. stop
    3. load overriden file -> load plugins

    Does anyone here have any clue on how to do this?
     
  9. Offline

    brord

    Bump
     
  10. Offline

    brord

    Allright. this is what ive got now:
    Code:
    String path = Bukkit.class.getProtectionDomain().getCodeSource().getLocation().getPath().replaceAll("%20", " ");
            String name = new File(Bukkit.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName();
            JarOutputStream tempJar = null;
            try {
                JarFile file = new JarFile(path);
                tempJar = new JarOutputStream(new FileOutputStream(path.replace(".jar", "_1.jar")));
             
                for (Enumeration<JarEntry> entryList = file.entries(); entryList.hasMoreElements();){
                    JarEntry entry = entryList.nextElement();
                 
                    InputStream filereader = file.getInputStream(entry);
                    tempJar.putNextEntry(new JarEntry(entry.getName()));
                 
                    System.out.println(entry.getName());
                 
                    for(int data = filereader.read(new byte[4096]); data != -1; data = filereader.read(new byte[4096])){
                        System.out.println("Wrote: " + data + " to " + entry.getName());
                        tempJar.write(data);
                    }
                    System.out.println(entry.getCompressedSize());
                }
             
                tempJar.putNextEntry(new JarEntry("org\\bukkit\\plugin\\java\\JavaPluginLoader.class"));
                InputStream stream = GlobalPlugins.class.getClassLoader().getResourceAsStream("net\\castegaming\\plugins\\globalplugins\\JavaPluginLoader.class");
             
                     
                     
                tempJar.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
         
            try {
                JarInputStream jar = new JarInputStream(new FileInputStream(path));
            } catch (IOException e) {
                e.printStackTrace();
                log("Could not acces " + name);
            }
    But for some reason, it doesnt copy the files their content :/
    I see the name, and valid paths, but their size is always something around 5.
    Anyone here good with Streams?
     
Thread Status:
Not open for further replies.

Share This Page