Update JeffChestSortUpdateChecker.java

comments
This commit is contained in:
JEFF 2019-04-29 02:11:10 +02:00 committed by GitHub
parent ae39c1f2a6
commit 1aa7ad45ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,13 +10,21 @@ import org.bukkit.entity.Player;
public class JeffChestSortUpdateChecker { public class JeffChestSortUpdateChecker {
// This checks for updates. A txt file is downloaded. If the txt file contains a string that is
// unequal to the currently used plugin's version, a message is printed in the console.
// The listener will also ensure that OPs will be notified on join.
// When the update checker could not complete the request, e.g. when the JEFF Media GbR API server is
// offline, or if you have no internet connection, a warning will be printed in the console.
private JeffChestSortPlugin plugin; private JeffChestSortPlugin plugin;
JeffChestSortUpdateChecker(JeffChestSortPlugin plugin) { JeffChestSortUpdateChecker(JeffChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
// This text file always contains a string with the latest version, e.g. 3.7.1
String latestVersionLink = "https://api.jeff-media.de/chestsort/chestsort-latest-version.txt"; String latestVersionLink = "https://api.jeff-media.de/chestsort/chestsort-latest-version.txt";
String downloadLink = "https://www.spigotmc.org/resources/1-13-chestsort.59773/"; String downloadLink = "https://www.spigotmc.org/resources/1-13-chestsort.59773/";
private String currentVersion = "undefined"; private String currentVersion = "undefined";
private String latestVersion = "undefined"; private String latestVersion = "undefined";
@ -32,22 +40,15 @@ public class JeffChestSortUpdateChecker {
} }
void checkForUpdate() { void checkForUpdate() {
plugin.getLogger().info("Checking for available updates..."); plugin.getLogger().info("Checking for available updates...");
try { try {
HttpURLConnection httpcon = (HttpURLConnection) new URL(latestVersionLink).openConnection(); HttpURLConnection httpcon = (HttpURLConnection) new URL(latestVersionLink).openConnection();
httpcon.addRequestProperty("User-Agent", "ChestSort/"+plugin.getDescription().getVersion()); httpcon.addRequestProperty("User-Agent", "ChestSort/"+plugin.getDescription().getVersion());
BufferedReader reader = new BufferedReader(new InputStreamReader(httpcon.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
String inputLine = reader.readLine().trim(); String inputLine = reader.readLine().trim();
latestVersion = inputLine; latestVersion = inputLine;
currentVersion = plugin.getDescription().getVersion().trim(); currentVersion = plugin.getDescription().getVersion().trim();
if (latestVersion.equals(currentVersion)) { if (latestVersion.equals(currentVersion)) {
plugin.getLogger().info("You are using the latest version of ChestSort."); plugin.getLogger().info("You are using the latest version of ChestSort.");
} else { } else {