Search in sources :

Example 1 with Version

use of com.loohp.interactivechat.updater.Version in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class CMLMain method downloadAssets.

protected static void downloadAssets() throws IOException {
    File defaultAssetsFolder = new File("InteractiveChatDiscordSrvAddon/built-in", "Default");
    defaultAssetsFolder.mkdirs();
    System.out.println("Available Minecraft Versions:");
    for (String version : ResourceDownloadManager.getMinecraftVersions()) {
        System.out.println(version);
    }
    System.out.println();
    System.out.println("Select Minecraft Version: (Type the version string)");
    String input;
    while (true) {
        input = IN.readLine();
        if (ResourceDownloadManager.getMinecraftVersions().contains(input)) {
            break;
        }
        System.out.println("That is not a valid Minecraft version!");
        System.out.println();
    }
    ResourceDownloadManager downloadManager = new ResourceDownloadManager(input, defaultAssetsFolder);
    CompletableFuture<Void> future = new CompletableFuture<>();
    new Thread(() -> {
        downloadManager.downloadResources((type, fileName, percentage) -> {
            switch(type) {
                case CLIENT_DOWNLOAD:
                    System.out.println("Downloading client jar");
                    break;
                case EXTRACT:
                    System.out.println("Extracting " + fileName);
                    break;
                case DOWNLOAD:
                    System.out.println("Downloading " + fileName);
                    break;
                case DONE:
                    System.out.println("Done!");
                    break;
            }
        });
        future.complete(null);
    }).start();
    future.join();
    System.out.println("Assets saved at: " + defaultAssetsFolder.getAbsolutePath());
}
Also used : YamlConfiguration(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration) Version(com.loohp.interactivechat.updater.Version) Enumeration(java.util.Enumeration) URL(java.net.URL) Registry(com.loohp.interactivechat.registry.Registry) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) File(java.io.File) FileUtils(com.loohp.interactivechat.utils.FileUtils) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ResourceDownloadManager(com.loohp.interactivechatdiscordsrvaddon.resources.ResourceDownloadManager) HTTPRequestUtils(com.loohp.interactivechat.utils.HTTPRequestUtils) Map(java.util.Map) InteractiveChatRegistry(com.loohp.interactivechatdiscordsrvaddon.registry.InteractiveChatRegistry) Entry(java.util.Map.Entry) ConfigurationSection(com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.ConfigurationSection) BufferedReader(java.io.BufferedReader) LinkedList(java.util.LinkedList) JSONObject(com.loohp.interactivechat.libs.org.json.simple.JSONObject) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceDownloadManager(com.loohp.interactivechatdiscordsrvaddon.resources.ResourceDownloadManager) File(java.io.File)

Example 2 with Version

use of com.loohp.interactivechat.updater.Version in project InteractiveChat by LOOHP.

the class ConfigDataFixer method update.

public static void update(Config config) {
    String versionString = config.getConfiguration().getString("ConfigVersion");
    if (versionString == null) {
        versionString = BASE_PLUGIN_VERSION;
        config.getConfiguration().set("ConfigVersion", versionString);
    }
    Version configVersion = new Version(versionString);
    boolean backup = false;
    if (configVersion.compareTo(new Version("4.1.1.9")) < 0) {
        if (!backup) {
            config.save(new File(config.getFile().getParent(), config.getFile().getName() + "." + versionString + ".bak"));
        }
        backup = true;
        // Regex placeholder
        boolean itemCase = config.getConfiguration().getBoolean("ItemDisplay.Item.CaseSensitive", false);
        config.getConfiguration().set("ItemDisplay.Item.CaseSensitive", null);
        config.getConfiguration().set("ItemDisplay.Item.Aliases", null);
        config.getConfiguration().set("ItemDisplay.Item.Name", config.getConfiguration().getString("ItemDisplay.Item.Keyword"));
        config.getConfiguration().set("ItemDisplay.Item.Keyword", (itemCase ? "" : "(?i)") + CustomStringUtils.escapeMetaCharacters(config.getConfiguration().getString("ItemDisplay.Item.Keyword")));
        boolean invCase = config.getConfiguration().getBoolean("ItemDisplay.Inventory.CaseSensitive", false);
        config.getConfiguration().set("ItemDisplay.Inventory.CaseSensitive", null);
        config.getConfiguration().set("ItemDisplay.Inventory.Aliases", null);
        config.getConfiguration().set("ItemDisplay.Inventory.Name", config.getConfiguration().getString("ItemDisplay.Inventory.Keyword"));
        config.getConfiguration().set("ItemDisplay.Inventory.Keyword", (invCase ? "" : "(?i)") + CustomStringUtils.escapeMetaCharacters(config.getConfiguration().getString("ItemDisplay.Inventory.Keyword")));
        boolean enderCase = config.getConfiguration().getBoolean("ItemDisplay.EnderChest.CaseSensitive", false);
        config.getConfiguration().set("ItemDisplay.EnderChest.CaseSensitive", null);
        config.getConfiguration().set("ItemDisplay.EnderChest.Aliases", null);
        config.getConfiguration().set("ItemDisplay.EnderChest.Name", config.getConfiguration().getString("ItemDisplay.EnderChest.Keyword"));
        config.getConfiguration().set("ItemDisplay.EnderChest.Keyword", (enderCase ? "" : "(?i)") + CustomStringUtils.escapeMetaCharacters(config.getConfiguration().getString("ItemDisplay.EnderChest.Keyword")));
        for (int customNo = 1; config.getConfiguration().contains("CustomPlaceholders." + customNo); customNo++) {
            ConfigurationSection s = config.getConfiguration().getConfigurationSection("CustomPlaceholders." + customNo);
            String text = s.getString("Text");
            s.set("Text", null);
            boolean caseSensitive = s.getBoolean("CaseSensitive", false);
            s.set("CaseSensitive", null);
            s.set("Keyword", (caseSensitive ? "" : "(?i)") + CustomStringUtils.escapeMetaCharacters(text));
            s.set("Name", text);
            s.set("Aliases", null);
        }
    }
    if (configVersion.compareTo(new Version("4.1.1.13")) < 0) {
        if (!backup) {
            config.save(new File(config.getFile().getParent(), config.getFile().getName() + "." + versionString + ".bak"));
        }
        backup = true;
        config.getConfiguration().set("Settings.FormattingTags.AdditionalRGBFormats", Collections.singletonList("#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])"));
    }
    if (configVersion.compareTo(new Version("4.1.2.14")) < 0) {
        if (!backup) {
            config.save(new File(config.getFile().getParent(), config.getFile().getName() + "." + versionString + ".bak"));
        }
        backup = true;
        config.getConfiguration().set("Settings.ChatListeningPlugins", null);
    }
    config.getConfiguration().set("ConfigVersion", InteractiveChat.plugin.getDescription().getVersion());
    config.save();
}
Also used : Version(com.loohp.interactivechat.updater.Version) File(java.io.File) ConfigurationSection(com.loohp.yamlconfiguration.ConfigurationSection)

Example 3 with Version

use of com.loohp.interactivechat.updater.Version in project InteractiveChat by LOOHP.

the class CMLMain method checkForUpdates.

protected static void checkForUpdates(String localPluginVersion) throws URISyntaxException, IOException {
    JSONObject response = (JSONObject) HTTPRequestUtils.getJSONResponse("https://api.loohpjames.com/spigot/data").get("InteractiveChat");
    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
        System.out.println("There is a new version available! (" + currentDevBuild + ")\nLocal version: " + localPluginVersion + "");
        System.out.println("You can download a new build at: https://ci.loohpjames.com/job/InteractiveChat/");
    } else if (currentDevBuild.compareTo(devBuild) < 0) {
        // dev build update
        System.out.println("There is a new DEV build available! (" + currentDevBuild + ")\nLocal version: " + localPluginVersion);
        System.out.println("You can download a new build at: https://ci.loohpjames.com/job/InteractiveChat/");
    } else {
        // latest
        System.out.println("You are already running the latest version! (" + localPluginVersion + ")");
    }
}
Also used : JSONObject(org.json.simple.JSONObject) Version(com.loohp.interactivechat.updater.Version)

Example 4 with Version

use of com.loohp.interactivechat.updater.Version in project InteractiveChat 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");
    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/"));
        }
    }
}
Also used : JSONObject(org.json.simple.JSONObject) Desktop(java.awt.Desktop) Version(com.loohp.interactivechat.updater.Version) JSONObject(org.json.simple.JSONObject) URI(java.net.URI)

Example 5 with Version

use of com.loohp.interactivechat.updater.Version in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class CMLMain method checkForUpdates.

protected static void checkForUpdates(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
        System.out.println("There is a new version available! (" + currentDevBuild + ")\nLocal version: " + localPluginVersion + "");
        System.out.println("You can download a new build at: https://ci.loohpjames.com/job/InteractiveChat-DiscordSRV-Addon/");
    } else if (currentDevBuild.compareTo(devBuild) < 0) {
        // dev build update
        System.out.println("There is a new DEV build available! (" + currentDevBuild + ")\nLocal version: " + localPluginVersion);
        System.out.println("You can download a new build at: https://ci.loohpjames.com/job/InteractiveChat-DiscordSRV-Addon/");
    } else {
        // latest
        System.out.println("You are already running the latest version! (" + localPluginVersion + ")");
    }
}
Also used : JSONObject(com.loohp.interactivechat.libs.org.json.simple.JSONObject) Version(com.loohp.interactivechat.updater.Version)

Aggregations

Version (com.loohp.interactivechat.updater.Version)7 JSONObject (com.loohp.interactivechat.libs.org.json.simple.JSONObject)4 Desktop (java.awt.Desktop)3 File (java.io.File)3 URI (java.net.URI)3 ConfigurationSection (com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.ConfigurationSection)2 YamlConfiguration (com.loohp.interactivechat.libs.com.loohp.yamlconfiguration.YamlConfiguration)2 Registry (com.loohp.interactivechat.registry.Registry)2 FileUtils (com.loohp.interactivechat.utils.FileUtils)2 HTTPRequestUtils (com.loohp.interactivechat.utils.HTTPRequestUtils)2 InteractiveChatRegistry (com.loohp.interactivechatdiscordsrvaddon.registry.InteractiveChatRegistry)2 ResourceDownloadManager (com.loohp.interactivechatdiscordsrvaddon.resources.ResourceDownloadManager)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 Enumeration (java.util.Enumeration)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2