Resource [UPDATED] How to download your plugin dependencies!

Discussion in 'Spigot Plugin Development' started by Alex0589, Jan 14, 2019.

  1. This is the 2.0 version of my dependency downloader API. In version 1.0 I was using classes created by me, but that needed libs which made the jar size too big for Spigot, so there was no real usage! After some work, I was able to create an HTTP server to which you can make requests to download any spigot plugin you need!

    Usage:
    Code (Text):
     public void downloadDependency(String name, String id) throws IOException {
            File file = new File(plugin.getDataFolder().getParent(), name + ".jar");
            if(file.exists() || Bukkit.getPluginManager().getPlugin(name) != null){
                Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "The dependency " + ChatColor.AQUA + name + ChatColor.GREEN + " was not downloaded as it already was!");
                return;
            }
       
            URL url = new URL("http://144.217.136.224:8080/api/download/" + id");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0");

            InputStream in = connection.getInputStream();
            OutputStream out = new BufferedOutputStream(new FileOutputStream(file));

            byte[] buffer = new byte[1024];

            int numRead;
            while ((numRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, numRead);
            }

            in.close();
            out.close();
            Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "The dependency " + ChatColor.AQUA + name + ChatColor.GREEN + " was successfully downloaded!");
       
        }
    If you want to see this API not die, consider donating to support the cost of the VPS and domain(which I'm currently setting), even a dollar is something!
     
    #1 Alex0589, Jan 14, 2019
    Last edited: Jan 19, 2019 at 8:09 AM
    • Friendly Friendly x 1
    • Useful Useful x 1
  2. MiniDigger

    Supporter

    Mmh, why not download directly from spigot?
     
  3. Spigot is protected by cloudfare, so no resource downloads. In addition, the SpigetAPI only let's you download resources that are uploaded on spigot, so if the author uploaded it to an external link you can do nothing. This is why I had to create an http server to get the plugin
     
  4. Simple, but it does what it's designed for.
     
  5. I like this :D
    Might use it in my resources.
     
  6. how do you manage the conflict resolution? (if the target depending .jar file was already installed by the server owner, or if different version of the same plugin was required by other plugins, etc.)
     
  7. I'll add a version download.
    For the other problem, I just check if there's already a Jar with the same name or if there's a plugin which name is the provided one (the plugin.yml one)
     
  8. Is there any delay between updating and the VPS server to update?
     
  9. Yes. Something like 10 minutes
     
  10. you should make it so that one can specify the source of each depending library (some from spigot, some from your own server, some from other CI servers etc.)
     
  11. I can add a method that makes you download the dependency using a link and not spigot
     
  12. Why should I trust the web service set up by you, that isn't supported nor endorsed officially? How do I know you're not going to taint my downloads? How do I know the connection is trustworthy?
     
  13. LOL you can just ask for the sourcecode, I'll make open source on github in a few hours
     
  14. Also wtf can I do with your download? Inject a virus? You can decompile your plugin or get its sha256 and confront it with the sha256 of the original one
     
  15. Why would you do this as opposed to downloading dependencies from a repository or just shading them in? Dependency injection has very few useful cases in plugin development for the majority of developers.
     
  16. So that you reduce the size of your jar? Not to shade everything in?
     
  17. Who cares? Libraries you'll be using usually only add a few KB's to the size with worst case scenarios around single-digit MB's.
     
  18. LOL then you have never used a real library
     

Share This Page