blob: 1e85cf78c093c5593b6e0255e543c5c170c924e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
package net.brysonsteck.Resurrection.startup;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.bukkit.plugin.java.JavaPlugin;
import net.brysonsteck.Resurrection.Resurrection;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Logger;
public class CheckForUpdate {
boolean success;
String version;
String versionURL;
String message;
Logger log = JavaPlugin.getProvidingPlugin(Resurrection.class).getLogger();
public CheckForUpdate() {
try {
String json = urlReader();
JsonElement root = new JsonParser().parse(json);
JsonObject rootobj = root.getAsJsonObject();
JsonElement softwareElement = rootobj.getAsJsonObject("resurrection");
JsonObject softwareObj = softwareElement.getAsJsonObject();
version = softwareObj.get("current-release").toString();
version = version.replace("\"", "");
versionURL = softwareObj.get("github-release").toString();
message = softwareObj.get("message").toString();
success = true;
} catch (IOException e) {
log.warning("An error has occurred while attempting to check for updates.");
e.printStackTrace();
}
}
public String urlReader() throws IOException {
URL website = new URL("https://brysonsteck.net/updates.json");
URLConnection connection = website.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
connection.getInputStream()));
StringBuilder response = new StringBuilder();
String inputLine;
while ((inputLine = in.readLine()) != null)
response.append(inputLine);
in.close();
return response.toString();
}
public boolean isSuccess() { return success; }
public String getVersionURL() {
return versionURL;
}
public String getVersion() {
return version;
}
public String getMessage() {
return message;
}
}
|