Class PluginDownloadUtil

java.lang.Object
dev.cwhead.GravesX.util.PluginDownloadUtil

public final class PluginDownloadUtil extends Object
Utility methods to download plugin jars from Spiget and place them in the server's plugins folder.

Note: This class uses simple HTTP requests with sensible timeouts and follows redirects.

  • Field Details

  • Constructor Details

    • PluginDownloadUtil

      private PluginDownloadUtil()
  • Method Details

    • downloadAndReplacePlugin

      public static void downloadAndReplacePlugin(long pluginId, String pluginName, String pluginsFolder, org.bukkit.command.CommandSender commandSender) throws IOException
      Downloads a plugin from Spiget and saves it to the plugins folder, replacing it if it exists.
      Parameters:
      pluginId - The Spigot resource ID of the plugin.
      pluginName - The name of the plugin file (without the ".jar" extension).
      pluginsFolder - The path to the plugins' folder.
      Throws:
      IOException - If the download or file operations fail.
    • downloadAndReplacePlugin

      public static void downloadAndReplacePlugin(String pluginId, String pluginName, String pluginsFolder, org.bukkit.command.CommandSender commandSender) throws IOException
      Downloads a plugin from Spiget and saves it to the plugins folder, replacing it if it exists.
      Parameters:
      pluginId - The Spigot resource ID of the plugin.
      pluginName - The name of the plugin file (without the ".jar" extension).
      pluginsFolder - The path to the plugins' folder.
      Throws:
      IOException - If the download or file operations fail.
    • downloadFile

      private static File downloadFile(String fileUrl, org.bukkit.command.CommandSender commandSender) throws IOException
      Downloads a file from the given URL to a temporary file.
      Parameters:
      fileUrl - The URL to download the file from.
      Returns:
      A temporary file containing the downloaded data.
      Throws:
      IOException - If the download fails.
    • open

      private static HttpURLConnection open(String urlStr) throws IOException
      Opens an HTTP connection with headers, timeouts, and redirect handling.
      Throws:
      IOException
    • setup

      private static void setup(HttpURLConnection conn) throws ProtocolException
      Throws:
      ProtocolException
    • isRedirect

      private static boolean isRedirect(int code)
    • sendMessageToExecutor

      private static void sendMessageToExecutor(org.bukkit.command.CommandSender commandSender, String message)