From 1e9058a5cbef64ea9189b6ef216085049c54370c Mon Sep 17 00:00:00 2001 From: HaHaWTH Date: Sun, 15 Oct 2023 09:08:48 +0800 Subject: [PATCH] Clean up --- src/main/java/fr/xephi/authme/AuthMe.java | 85 ++++++++--------------- 1 file changed, 28 insertions(+), 57 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 1bbc35f5..86b7af4c 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -390,68 +390,39 @@ public class AuthMe extends JavaPlugin { infoLogMethod.accept("AuthMe " + this.getDescription().getVersion() + " is unloaded successfully!"); ConsoleLogger.closeFileWriter(); } + private static final String owner = "HaHaWTH"; private static final String owner_gitee = "Shixuehan114514"; private static final String repo = "AuthMeReReloaded"; -// private void checkForUpdates() { -// logger.info("Checking for updates..."); -// Bukkit.getScheduler().runTaskAsynchronously(this, () -> { -// try { -// // 从南通集线器获取最新版本号 -// -// URL url = new URL("https://api.github.com/repos/" + owner + "/" + repo + "/releases/latest"); -// HttpURLConnection conn = (HttpURLConnection) url.openConnection(); -// conn.setConnectTimeout(10000); // 设置连接超时为10秒 -// conn.setReadTimeout(10000); // 设置读取超时为10秒 -// Scanner scanner = new Scanner(conn.getInputStream()); -// String response = scanner.useDelimiter("\\Z").next(); -// scanner.close(); -// -// // 处理JSON响应 -// String latestVersion = response.substring(response.indexOf("tag_name") + 11); -// latestVersion = latestVersion.substring(0, latestVersion.indexOf("\"")); -// if ((pluginBuild + pluginBuildNumber).equals(latestVersion)) { -// getLogger().log(Level.INFO,"You are running the latest version."); -// } -// if (!(pluginBuild + pluginBuildNumber).equals(latestVersion)) { -// // Display update message -// String message = "New version available! Latest:" + latestVersion + " Current:" + pluginBuild + pluginBuildNumber; -// getLogger().log(Level.INFO, message); -// getLogger().log(Level.INFO,"Download from here:github.com/HaHaWTH/AuthMeReReloaded/releases/latest"); -// } -// }catch (IOException e) { -// getLogger().log(Level.WARNING,"Error occurred while checking updates from GitHub. Reason: " + e.getMessage()); -// } -// }); -// } -private void checkForUpdates() { - logger.info("Checking for updates..."); - Bukkit.getScheduler().runTaskAsynchronously(this, () -> { - try { - // 从南通集线器获取最新版本号 - URL url = new URL("https://api.github.com/repos/" + owner + "/" + repo + "/releases/latest"); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setConnectTimeout(10000); // 设置连接超时为10秒 - conn.setReadTimeout(10000); // 设置读取超时为10秒 - Scanner scanner = new Scanner(conn.getInputStream()); - String response = scanner.useDelimiter("\\Z").next(); - scanner.close(); - // 处理JSON响应 - String latestVersion = response.substring(response.indexOf("tag_name") + 11); - latestVersion = latestVersion.substring(0, latestVersion.indexOf("\"")); - if (isUpdateAvailable(latestVersion)) { - String message = "New version available! Latest:" + latestVersion + " Current:" + pluginBuild + pluginBuildNumber; - getLogger().log(Level.INFO, message); - getLogger().log(Level.INFO, "Download from here: github.com/HaHaWTH/AuthMeReReloaded/releases/latest"); - } else { - getLogger().log(Level.INFO, "You are running the latest version."); + private void checkForUpdates() { + logger.info("Checking for updates..."); + Bukkit.getScheduler().runTaskAsynchronously(this, () -> { + try { + // 从南通集线器获取最新版本号 + URL url = new URL("https://api.github.com/repos/" + owner + "/" + repo + "/releases/latest"); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setConnectTimeout(10000); // 设置连接超时为10秒 + conn.setReadTimeout(10000); // 设置读取超时为10秒 + Scanner scanner = new Scanner(conn.getInputStream()); + String response = scanner.useDelimiter("\\Z").next(); + scanner.close(); + + // 处理JSON响应 + String latestVersion = response.substring(response.indexOf("tag_name") + 11); + latestVersion = latestVersion.substring(0, latestVersion.indexOf("\"")); + if (isUpdateAvailable(latestVersion)) { + String message = "New version available! Latest:" + latestVersion + " Current:" + pluginBuild + pluginBuildNumber; + getLogger().log(Level.INFO, message); + getLogger().log(Level.INFO, "Download from here: github.com/HaHaWTH/AuthMeReReloaded/releases/latest"); + } else { + getLogger().log(Level.INFO, "You are running the latest version."); + } + } catch (IOException e) { + getLogger().log(Level.WARNING, "Error occurred while checking updates from GitHub. Reason: " + e.getMessage()); } - } catch (IOException e) { - getLogger().log(Level.WARNING, "Error occurred while checking updates from GitHub. Reason: " + e.getMessage()); - } - }); -} + }); + } private boolean isUpdateAvailable(String latestVersion) { // Extract the first character and the remaining digits from the version string char latestChar = latestVersion.charAt(0);