use of com.loohp.interactivechat.updater.Version in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class GUIMain method checkForUpdates.
protected static void checkForUpdates(String title, Icon icon, String localPluginVersion) throws URISyntaxException, IOException {
JSONObject response = (JSONObject) HTTPRequestUtils.getJSONResponse("https://api.loohpjames.com/spigot/data").get("InteractiveChat-DiscordSRV-Addon");
String spigotPluginVersion = (String) ((JSONObject) response.get("latestversion")).get("release");
String devBuildVersion = (String) ((JSONObject) response.get("latestversion")).get("devbuild");
int spigotPluginId = (int) (long) ((JSONObject) response.get("spigotmc")).get("pluginid");
int posOfThirdDot = localPluginVersion.indexOf(".", localPluginVersion.indexOf(".", localPluginVersion.indexOf(".") + 1) + 1);
Version currentDevBuild = new Version(localPluginVersion);
Version currentRelease = new Version(localPluginVersion.substring(0, posOfThirdDot >= 0 ? posOfThirdDot : localPluginVersion.length()));
Version spigotmc = new Version(spigotPluginVersion);
Version devBuild = new Version(devBuildVersion);
int input;
if (currentRelease.compareTo(spigotmc) < 0) {
// update
input = JOptionPane.showOptionDialog(null, createLabel("There is a new version available! (" + currentDevBuild + ")\nLocal version: " + localPluginVersion, 15), title, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, icon, new Object[] { "OK", "Download Link" }, null);
} else if (currentDevBuild.compareTo(devBuild) < 0) {
// dev build update
input = JOptionPane.showOptionDialog(null, createLabel("There is a new DEV build available! (" + currentDevBuild + ")\nLocal version: " + localPluginVersion, 15), title, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, icon, new Object[] { "OK", "Download Link" }, null);
} else {
// latest
JOptionPane.showMessageDialog(null, createLabel("You are already running the latest version! (" + localPluginVersion + ")", 15), title, JOptionPane.INFORMATION_MESSAGE, icon);
input = 0;
}
if (input == 1) {
if (Desktop.isDesktopSupported()) {
Desktop dt = Desktop.getDesktop();
dt.browse(new URI("https://ci.loohpjames.com/job/InteractiveChat-DiscordSRV-Addon/"));
}
}
}
use of com.loohp.interactivechat.updater.Version in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class GUIMain method downloadAssets.
protected static void downloadAssets(String title, BufferedImage image, Icon icon) {
File defaultAssetsFolder = new File("InteractiveChatDiscordSrvAddon/built-in", "Default");
defaultAssetsFolder.mkdirs();
File libsFolder = new File("InteractiveChatDiscordSrvAddon", "libs");
libsFolder.mkdirs();
JPanel panel = new JPanel();
panel.add(GUIMain.createLabel("Select Minecraft Version: ", 13));
JComboBox<String> options = new JComboBox<>();
for (String version : ResourceDownloadManager.getMinecraftVersions()) {
options.addItem(version);
}
panel.add(options);
int result = JOptionPane.showOptionDialog(null, panel, title, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, icon, null, null);
if (result < 0) {
return;
}
ResourceDownloadManager resourceDownloadManager = new ResourceDownloadManager((String) options.getSelectedItem(), defaultAssetsFolder);
LibraryDownloadManager libraryDownloadManager = new LibraryDownloadManager(libsFolder);
JFrame frame = new JFrame(title);
frame.setIconImage(image);
frame.setSize(800, 175);
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.setLocationRelativeTo(null);
panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));
panel.setLayout(new GridLayout(0, 1));
JLabel label = GUIMain.createLabel("<html>Downloading Assets:<html/>", 13);
label.setSize(800, 125);
panel.add(label);
JProgressBar progressBar = new JProgressBar(0, 10000);
panel.add(progressBar);
frame.add(panel, BorderLayout.CENTER);
frame.setResizable(false);
frame.setVisible(true);
CompletableFuture<Void> future = new CompletableFuture<>();
new Thread(() -> {
resourceDownloadManager.downloadResources((type, fileName, percentage) -> {
switch(type) {
case CLIENT_DOWNLOAD:
label.setText("<html>Downloading Assets:<br>Downloading client jar<html/>");
break;
case EXTRACT:
label.setText("<html>Downloading Assets:<br>Extracting " + fileName + "<html/>");
break;
case DOWNLOAD:
label.setText("<html>Downloading Assets:<br>Downloading " + fileName + "<html/>");
progressBar.setValue(Math.min(9999, (int) (percentage * 100)));
break;
case DONE:
label.setText("<html>Done!<html/>");
break;
}
});
libraryDownloadManager.downloadLibraries((downloadResult, jarName) -> {
if (downloadResult) {
label.setText("<html>Downloaded library \"" + jarName + "\"<html/>");
}
});
future.complete(null);
}).start();
future.join();
progressBar.setValue(9999);
JOptionPane.showMessageDialog(null, createLabel("Assets saved at: " + defaultAssetsFolder.getAbsolutePath(), 15), title, JOptionPane.INFORMATION_MESSAGE, icon);
frame.setVisible(false);
frame.dispose();
}
Aggregations