Skip to content

Commit 4521121

Browse files
committed
fix: updates Updater to new Spigot API
1 parent d0b3988 commit 4521121

File tree

1 file changed

+6
-9
lines changed
  • src/main/java/de/dustplanet/silkspawnersshopaddon/util

1 file changed

+6
-9
lines changed

src/main/java/de/dustplanet/silkspawnersshopaddon/util/Updater.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.InputStreamReader;
66
import java.net.HttpURLConnection;
77
import java.net.URL;
8+
import java.net.URLEncoder;
89
import java.nio.charset.StandardCharsets;
910

1011
import org.bukkit.plugin.java.JavaPlugin;
@@ -20,12 +21,10 @@
2021

2122
public class Updater {
2223
private JavaPlugin plugin;
23-
private static final String API_KEY = "98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4";
24-
private static final String REQUEST_METHOD = "POST";
24+
private static final String REQUEST_METHOD = "GET";
2525
private final String RESOURCE_ID;
26-
private static final String HOST = "https://www.spigotmc.org";
27-
private static final String QUERY = "/api/general.php";
28-
private String WRITE_STRING;
26+
private static final String HOST = "https://api.spigotmc.org";
27+
private static final String PATH = "/legacy/update.php";
2928

3029
@Getter
3130
private String version;
@@ -56,23 +55,21 @@ public Updater(JavaPlugin plugin, Integer resourceId, boolean disabled) {
5655
}
5756

5857
try {
59-
connection = (HttpURLConnection) new URL(HOST + QUERY).openConnection();
58+
final String query = String.format("?resource=%s", URLEncoder.encode(RESOURCE_ID, StandardCharsets.UTF_8.toString()));
59+
connection = (HttpURLConnection) new URL(HOST + PATH + query).openConnection();
6060
} catch (IOException e) {
6161
result = UpdateResult.FAIL_SPIGOT;
6262
plugin.getLogger().severe("Failed to open the connection to SpigotMC.");
6363
e.printStackTrace();
6464
return;
6565
}
66-
67-
WRITE_STRING = "key=" + API_KEY + "&resource=" + RESOURCE_ID;
6866
run();
6967
}
7068

7169
private void run() {
7270
connection.setDoOutput(true);
7371
try {
7472
connection.setRequestMethod(REQUEST_METHOD);
75-
connection.getOutputStream().write(WRITE_STRING.getBytes(StandardCharsets.UTF_8));
7673
} catch (IOException e) {
7774
plugin.getLogger().severe("Failed to open the connection to SpigotMC.");
7875
e.printStackTrace();

0 commit comments

Comments
 (0)