package xyz.upperlevel.uppercore.update;

import org.bukkit.plugin.Plugin;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class SpigotUpdateChecker extends UpdateChecker {
    public static final String API_URL = "http://www.spigotmc.org/api/general.php";
    public static final String API_KEY = "98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4";

    private final int resId;

    public SpigotUpdateChecker(Plugin plugin, String spigotFullId) {
        super(plugin, spigotFullId);
        String[] parts = spigotFullId.split("\\.");
        try {
            resId = Integer.parseInt(parts[parts.length - 1]);
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid id: " + spigotFullId);
        }
    }


    @Override
    public String fetchVersion() throws IOException {
        HttpURLConnection connection = (HttpURLConnection) new URL(API_URL).openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.getOutputStream().write(("key=" + API_KEY + "&resource=" + resId).getBytes(StandardCharsets.UTF_8));
        return (new BufferedReader(new InputStreamReader(connection.getInputStream()))).readLine();
    }
}

@@ -368,14 +368,15 @@
 http
+s
 ://
-www
+api
 .spi
@@ -389,132 +389,35 @@
 org/
-api/general.php%22;%0A    public static final String API_KEY = %2298BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4
+legacy/update.php?resource=
 %22;%0A%0A
@@ -438,11 +438,12 @@
 nal 
-int
+long
  res
@@ -643,24 +643,22 @@
 d = 
-Integer
+Long
 .parse
-Int
+Long
 (par
@@ -807,17 +807,20 @@
 %7D%0A    %7D%0A
-%0A
+    
 %0A    @Ov
@@ -954,16 +954,24 @@
 (API_URL
+ + resId
 ).openCo
@@ -1061,133 +1061,12 @@
 od(%22
-POST%22);%0A        connection.getOutputStream().write((%22key=%22 + API_KEY + %22&resource=%22 + resId).getBytes(StandardCharsets.UTF_8)
+GET%22
 );%0A 

Fix update checker