Package dev.cwhead.GravesX.util
Class PluginDownloadUtil
java.lang.Object
dev.cwhead.GravesX.util.PluginDownloadUtil
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate static final OutputStreamSink to swallow streams when only status matters.private static final intprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddownloadAndReplacePlugin(long pluginId, String pluginName, String pluginsFolder, org.bukkit.command.CommandSender commandSender) Downloads a plugin from Spiget and saves it to the plugins folder, replacing it if it exists.static voiddownloadAndReplacePlugin(String pluginId, String pluginName, String pluginsFolder, org.bukkit.command.CommandSender commandSender) Downloads a plugin from Spiget and saves it to the plugins folder, replacing it if it exists.private static FiledownloadFile(String fileUrl, org.bukkit.command.CommandSender commandSender) Downloads a file from the given URL to a temporary file.private static booleanisRedirect(int code) private static HttpURLConnectionOpens an HTTP connection with headers, timeouts, and redirect handling.private static voidsendMessageToExecutor(org.bukkit.command.CommandSender commandSender, String message) private static voidsetup(HttpURLConnection conn)
-
Field Details
-
CONNECT_TIMEOUT_MS
private static final int CONNECT_TIMEOUT_MS- See Also:
-
READ_TIMEOUT_MS
private static final int READ_TIMEOUT_MS- See Also:
-
BUFFER_SIZE
private static final int BUFFER_SIZE- See Also:
-
USER_AGENT
- See Also:
-
DISCARD
Sink to swallow streams when only status matters.
-
-
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
Opens an HTTP connection with headers, timeouts, and redirect handling.- Throws:
IOException
-
setup
- Throws:
ProtocolException
-
isRedirect
private static boolean isRedirect(int code) -
sendMessageToExecutor
private static void sendMessageToExecutor(org.bukkit.command.CommandSender commandSender, String message)
-