Use Gson api for update checking to fix build with 1.14

This commit is contained in:
Sn0wStorm 2019-06-28 16:12:52 +02:00
parent f4af4c3f00
commit 8fdfa41cc2
3 changed files with 17 additions and 17 deletions

View File

@ -117,10 +117,6 @@
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>

View File

@ -176,7 +176,11 @@ public class P extends JavaPlugin {
p.getServer().getScheduler().runTaskTimer(p, new DrunkRunnable(), 120, 120);
if (updateCheck) {
p.getServer().getScheduler().runTaskLaterAsynchronously(p, new UpdateChecker(), 135);
try {
p.getServer().getScheduler().runTaskLaterAsynchronously(p, new UpdateChecker(), 135);
} catch (Exception e) {
e.printStackTrace();
}
}
this.log(this.getDescription().getName() + " enabled!");

View File

@ -1,5 +1,11 @@
package com.dre.brewery.filedata;
import com.dre.brewery.P;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.bukkit.entity.Player;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@ -7,13 +13,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import org.bukkit.entity.Player;
import com.dre.brewery.P;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
/**
* Update Checker modified from the Gravity Update Checker Example:
@ -80,19 +79,20 @@ public class UpdateChecker implements Runnable {
conn.addRequestProperty("User-Agent", "Brewery UpdateChecker (by Gravity)");
// Read the response of the query
// The response will be in a JSON format, so only reading one line is necessary.
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = reader.readLine();
JsonParser parser = new JsonParser();
// Parse the array of files from the query's response
JSONArray array = (JSONArray) JSONValue.parse(response);
JsonArray array = parser.parse(reader).getAsJsonArray();
if (array.size() > 0) {
// Get the newest file's details
JSONObject latest = (JSONObject) array.get(array.size() - 1);
JsonObject latest = array.get(array.size() - 1).getAsJsonObject();
// Get the version's title
String versionName = (String) latest.get(API_NAME_VALUE);
String versionName = latest.get(API_NAME_VALUE).getAsString();
/*// Get the version's link
String versionLink = (String) latest.get(API_LINK_VALUE);