Search in sources :

Example 21 with JSONObject

use of com.loohp.interactivechat.libs.org.json.simple.JSONObject in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class Updater method checkUpdate.

public static UpdaterResponse checkUpdate() {
    try {
        String localPluginVersion = InteractiveChatDiscordSrvAddon.plugin.getDescription().getVersion();
        JSONObject response = (JSONObject) HTTPRequestUtils.getJSONResponse("https://api.loohpjames.com/spigot/data").get(PLUGIN_NAME);
        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);
        if (currentRelease.compareTo(spigotmc) < 0) {
            return new UpdaterResponse(spigotPluginVersion, spigotPluginId, currentDevBuild.compareTo(devBuild) >= 0);
        } else {
            return new UpdaterResponse("latest", spigotPluginId, currentDevBuild.compareTo(devBuild) >= 0);
        }
    } catch (Exception e) {
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[ICDiscordSrvAddon] Failed to check against \"api.loohpjames.com\" for the latest version.. It could be an internet issue or \"api.loohpjames.com\" is down. If you want disable the update checker, you can disable in config.yml, but we still highly-recommend you to keep your plugin up to date!");
    }
    return new UpdaterResponse("error", -1, false);
}
Also used : JSONObject(com.loohp.interactivechat.libs.org.json.simple.JSONObject)

Aggregations

JSONObject (com.loohp.interactivechat.libs.org.json.simple.JSONObject)21 JSONParser (com.loohp.interactivechat.libs.org.json.simple.parser.JSONParser)11 InputStreamReader (java.io.InputStreamReader)7 BufferedImage (java.awt.image.BufferedImage)6 HashMap (java.util.HashMap)6 BOMInputStream (com.loohp.interactivechat.libs.org.apache.commons.io.input.BOMInputStream)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 JSONArray (com.loohp.interactivechat.libs.org.json.simple.JSONArray)4 ResourceLoadingException (com.loohp.interactivechatdiscordsrvaddon.resources.ResourceLoadingException)4 ResourcePackFile (com.loohp.interactivechatdiscordsrvaddon.resources.ResourcePackFile)4 IOException (java.io.IOException)4 ICPlayer (com.loohp.interactivechat.objectholders.ICPlayer)3 OfflineICPlayer (com.loohp.interactivechat.objectholders.OfflineICPlayer)3 ModelOverrideType (com.loohp.interactivechatdiscordsrvaddon.resources.models.ModelOverride.ModelOverrideType)3 LinkedHashMap (java.util.LinkedHashMap)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 JsonParser (com.google.gson.JsonParser)2 XMaterial (com.loohp.interactivechat.libs.com.cryptomorin.xseries.XMaterial)2