Util Dependency Downloader

Discussion in 'Resources' started by Zombie_Striker, Aug 10, 2017.

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

    Zombie_Striker

    Description
    This util downloads files specified by the plugin. Now you no longer need to worry if server owners downloaded ProtocolLib, Vault, or any other plugin that you may need.

    Code:
    The class can be found at this Github page HERE.

    To download a plugin, simply use these two lines line:
    Code:
    if(!Bukkit.getPluginManager().isPluginEnabled(PLUGIN NAME))
          new DependencyDownloader(MAIN, ID );
    Where:
    • PLUGIN NAME is the name of the plugin. This is to prevent plugins from redownloading the dependency if the dependency is already on the server.
    • MAIN is the main class's instance. If this is in the main class, replace it with "this"
    • ID is the project id. You can either use the raw int ID for the project or, if the dependency is in the project list, use ProjectID.<PROJECT NAME>.
    Here is an example of this, where we are downloading ProtocolLib
    Code:
    if(!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib"))
          new DependencyDownloader(this,  ProjectID.PROTOCOLLIB);
    How this works:
    This utils was based off of @ArsenArsen 's auto updater. This works almost the same as the updater, but with half the code. Thanks for not getting any say in what I do with your code and now seeing me rip up most of it for this.

    Basically what happens is
    • Get a response from servermods
    • Get the last file in the response
    • Store files MD5, name and release type, as known as channel
    • Download it
    • If its MD5 is incorrect, check if line one says that it was moved
    • If it does repeat download for moved files URL
    • Otherwise download failed
    • If its not on the allowed channels list or has a skip tag, repeat the whole process for the next one

    Changelog:
    1.0:
    Initial post.
     
    Last edited: Aug 11, 2017
    AlvinB and timtower like this.
  2. @Zombie_Striker
    That's a very clever idea indeed. Are you sure this is compatible with licenses (I don't see why not, but just to make sure)?
     
  3. Online

    timtower Administrator Administrator Moderator

    @Zombie_Striker Could you check your if statement examples?
    Think that you need to invert them.
    And how about load order?
     
  4. Offline

    Zombie_Striker

    The GNU General license sections #2, #3, and #4 simply state that as long as the license is distributed as well, that I cannot charge money for the program, and that I am not circumventing any existing systems for retrieving it. For the GNU Lesser license, it says I can distribute the program without being bound to #3 for the GNU-GPL. The BSD License,MIT License, and the Open Software License all allow for distributing the program as long as the license is also distributed as well. For All Rights Reserved, although there is nothing stating anything about distribution, since this system takes the files from bukkitdev and puts it directly on the server, free of charge, I am going to assume this should be allowed.

    TL; DR; This should be compatible with all the licenses on bukkit.


    @timtower
    Thanks for pointing that out.

    For load order, since I do not know how to force bukkit to enable another plugin, this may require a reload in order for the dependency to be enabled. However, after that, the dependencies should load normally, before the plugin that depends on it.
     
  5. Online

    timtower Administrator Administrator Moderator

    @Zombie_Striker So adding a softdepend is needed for the correct load order?
     
  6. Offline

    Zombie_Striker

  7. @timtower
    Well, if it is a dependency to your plugin, you just use this to download it, wouldn't you have a softdepend/depend on the plugin anyway?

    @Zombie_Striker
    Good to see that most licenses seem to be compatible with this. I was more thinking that there'd be something with a license or perhaps devbukkit ToS or the like that would prevent you from downloading other people's plugins automatically. You're not actually distributing anything, so a license would probably need to be especially designed to prevent this.

    As for how to load the plugin: It is possible to make Bukkit load a plugin without reloading. If you get access to the (private) Map field 'fileAssociations' in Bukkit.getPluginManager(), and get its one entry (it should only be one, it's for various file patterns, but as of now only the '.jar' filter exists), it should be a PluginLoader, and you should be able to use its "loadPlugin(File)" method to load it. Note that this is only gets the plugin instance, it isn't actually registered or enabled or anything (only thing it does is it registers the created PluginClassLoader in JavaPluginLoader), you'll have to add it to the 'plugins' and 'lookupNames' fields in SimplePluginManager. This may be enough to use the existing methods to enable the plugin, but just maybe.

    There is however one problem to doing this; other plugins that use the dependency, and loadBefore's that that plugin may have won't work. You could maybe start reading plugin description files to find out loadBefores and other dependencies to manually just disable and re enable those plugins in the right order, but this might be too tricky. This is probably not worth the effort.

    TL DR: It's probably better to just use Bukkit.reload().
     
Thread Status:
Not open for further replies.

Share This Page