mirror of
https://github.com/TotalFreedomMC/TF-LibsDisguises.git
synced 2025-02-05 14:22:53 +00:00
They don't like spigot on bukkit. Dunno why
This commit is contained in:
parent
705362c708
commit
e0495e8001
1 changed files with 25 additions and 19 deletions
|
@ -2,9 +2,12 @@ package me.libraryaddict.disguise.utilities;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.regex.Pattern;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
|
||||
public class UpdateChecker {
|
||||
private String latestVersion;
|
||||
|
@ -16,7 +19,7 @@ public class UpdateChecker {
|
|||
}
|
||||
|
||||
public void checkUpdate(String currentVersion) {
|
||||
String version = getSpigotVersion();
|
||||
String version = getBukkitVersion();
|
||||
if (version != null) {
|
||||
if (checkHigher(currentVersion, version)) {
|
||||
latestVersion = version;
|
||||
|
@ -24,30 +27,33 @@ public class UpdateChecker {
|
|||
}
|
||||
}
|
||||
|
||||
public String getLatestVersion() {
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks spigot for the version
|
||||
* Asks bukkit for the version
|
||||
*/
|
||||
private String getSpigotVersion() {
|
||||
private String getBukkitVersion() {
|
||||
try {
|
||||
HttpURLConnection con = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection();
|
||||
con.setDoOutput(true);
|
||||
con.setRequestMethod("POST");
|
||||
con.getOutputStream().write(
|
||||
("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=81").getBytes("UTF-8"));
|
||||
String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
|
||||
if (version.length() <= 7) {
|
||||
return version;
|
||||
URLConnection conn = new URL("https://api.curseforge.com/servermods/files?projectIds=72490").openConnection();
|
||||
conn.addRequestProperty("User-Agent", "Lib's Disguises Update Checker");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
JSONArray array = (JSONArray) JSONValue.parse(reader.readLine());
|
||||
if (!array.isEmpty()) {
|
||||
JSONObject latest = (JSONObject) array.get(array.size() - 1);
|
||||
String version = (String) latest.get("name");
|
||||
version = version.substring(version.lastIndexOf(" ") + 1);
|
||||
if (version.length() <= 7) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.print("[LibsDisguises] Failed to check for a update on spigot. Now checking bukkit..");
|
||||
} catch (Exception e) {
|
||||
System.out.print("[LibsDisguises] Failed to check for a update on bukkit. " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getLatestVersion() {
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
private String toReadable(String version) {
|
||||
String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", ""));
|
||||
version = "";
|
||||
|
@ -55,4 +61,4 @@ public class UpdateChecker {
|
|||
version += String.format("%4s", s);
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue