Cleanup
This commit is contained in:
parent
42e907580c
commit
2fe0da569b
@ -44,6 +44,7 @@ import fr.xephi.authme.settings.properties.EmailSettings;
|
|||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.task.CleanupTask;
|
import fr.xephi.authme.task.CleanupTask;
|
||||||
|
import fr.xephi.authme.task.Updater;
|
||||||
import fr.xephi.authme.task.purge.PurgeService;
|
import fr.xephi.authme.task.purge.PurgeService;
|
||||||
import fr.xephi.authme.util.ExceptionUtils;
|
import fr.xephi.authme.util.ExceptionUtils;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -55,15 +56,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE;
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE;
|
||||||
import static fr.xephi.authme.util.Utils.isClassLoaded;
|
import static fr.xephi.authme.util.Utils.isClassLoaded;
|
||||||
@ -224,8 +220,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
// Purge on start if enabled
|
// Purge on start if enabled
|
||||||
PurgeService purgeService = injector.getSingleton(PurgeService.class);
|
PurgeService purgeService = injector.getSingleton(PurgeService.class);
|
||||||
purgeService.runAutoPurge();
|
purgeService.runAutoPurge();
|
||||||
// 注册玩家加入事件监听
|
|
||||||
// register3rdPartyListeners();
|
|
||||||
logger.info("GitHub: https://github.com/HaHaWTH/AuthMeReReloaded/");
|
logger.info("GitHub: https://github.com/HaHaWTH/AuthMeReReloaded/");
|
||||||
if (settings.getProperty(SecuritySettings.CHECK_FOR_UPDATES)) {
|
if (settings.getProperty(SecuritySettings.CHECK_FOR_UPDATES)) {
|
||||||
checkForUpdates();
|
checkForUpdates();
|
||||||
@ -233,8 +227,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Migrated
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the version and build number of the plugin from the description file.
|
* Load the version and build number of the plugin from the description file.
|
||||||
*
|
*
|
||||||
@ -422,55 +414,19 @@ public class AuthMe extends JavaPlugin {
|
|||||||
ConsoleLogger.closeFileWriter();
|
ConsoleLogger.closeFileWriter();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String owner = "HaHaWTH";
|
|
||||||
// private static final String owner_gitee = "Shixuehan114514";
|
|
||||||
private static final String repo = "AuthMeReReloaded";
|
|
||||||
|
|
||||||
private void checkForUpdates() {
|
private void checkForUpdates() {
|
||||||
logger.info("Checking for updates...");
|
logger.info("Checking for updates...");
|
||||||
|
Updater updater = new Updater(pluginBuild + pluginBuildNumber);
|
||||||
bukkitService.runTaskAsynchronously(() -> {
|
bukkitService.runTaskAsynchronously(() -> {
|
||||||
try {
|
if (updater.isUpdateAvailable()) {
|
||||||
// 从南通集线器获取最新版本号
|
String message = "New version available! Latest:" + updater.getLatestVersion() + " Current:" + pluginBuild + pluginBuildNumber;
|
||||||
URL url = new URL("https://api.github.com/repos/" + owner + "/" + repo + "/releases/latest");
|
logger.warning(message);
|
||||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
logger.warning("Download from here: https://github.com/HaHaWTH/AuthMeReReloaded/releases/latest");
|
||||||
conn.setConnectTimeout(10000); // 设置连接超时为10秒
|
} else {
|
||||||
conn.setReadTimeout(10000); // 设置读取超时为10秒
|
logger.info("You are running the latest version.");
|
||||||
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.WARNING, message);
|
|
||||||
getLogger().log(Level.WARNING, "Download from here: https://github.com/HaHaWTH/AuthMeReReloaded/releases/latest");
|
|
||||||
} else {
|
|
||||||
getLogger().log(Level.INFO, "You are running the latest version.");
|
|
||||||
}
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private boolean isUpdateAvailable(String latestVersion) {
|
|
||||||
// Extract the first character and the remaining digits from the version string
|
|
||||||
char latestChar = latestVersion.charAt(0);
|
|
||||||
int latestNumber = Integer.parseInt(latestVersion.substring(1));
|
|
||||||
|
|
||||||
char currentChar = pluginBuild.charAt(0);
|
|
||||||
int currentNumber = Integer.parseInt(pluginBuildNumber);
|
|
||||||
|
|
||||||
// Compare the characters first
|
|
||||||
if (latestChar > currentChar) {
|
|
||||||
return true;
|
|
||||||
} else if (latestChar < currentChar) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
// If the characters are the same, compare the numbers
|
|
||||||
return latestNumber > currentNumber;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void checkServerType() {
|
private void checkServerType() {
|
||||||
|
|||||||
@ -21,9 +21,7 @@ public class SpawnCommand extends PlayerCommand {
|
|||||||
if (spawnLoader.getSpawn() == null) {
|
if (spawnLoader.getSpawn() == null) {
|
||||||
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
|
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
|
||||||
} else {
|
} else {
|
||||||
bukkitService.runTaskIfFolia(player, () -> {
|
bukkitService.runTaskIfFolia(player, () -> TeleportUtils.teleport(player, spawnLoader.getSpawn()));
|
||||||
TeleportUtils.teleport(player, spawnLoader.getSpawn());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
67
src/main/java/fr/xephi/authme/task/Updater.java
Normal file
67
src/main/java/fr/xephi/authme/task/Updater.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package fr.xephi.authme.task;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Updater {
|
||||||
|
private final String currentVersion;
|
||||||
|
private String latestVersion;
|
||||||
|
private static boolean isUpdateAvailable = false;
|
||||||
|
private static final String owner = "HaHaWTH";
|
||||||
|
private static final String repo = "AuthMeReReloaded";
|
||||||
|
private static final String UPDATE_URL = "https://api.github.com/repos/" + owner + "/" + repo + "/releases/latest";
|
||||||
|
|
||||||
|
public Updater(String currentVersion) {
|
||||||
|
this.currentVersion = currentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if there is an update available
|
||||||
|
* Note: This method will perform a network request!
|
||||||
|
*
|
||||||
|
* @return true if there is an update available, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean isUpdateAvailable() {
|
||||||
|
URI uri = URI.create(UPDATE_URL);
|
||||||
|
try {
|
||||||
|
URL url = uri.toURL();
|
||||||
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setConnectTimeout(10000);
|
||||||
|
conn.setReadTimeout(10000);
|
||||||
|
Scanner scanner = new Scanner(conn.getInputStream());
|
||||||
|
String response = scanner.useDelimiter("\\Z").next();
|
||||||
|
scanner.close();
|
||||||
|
String latestVersion = response.substring(response.indexOf("tag_name") + 11);
|
||||||
|
latestVersion = latestVersion.substring(0, latestVersion.indexOf("\""));
|
||||||
|
this.latestVersion = latestVersion;
|
||||||
|
isUpdateAvailable = !currentVersion.equals(latestVersion);
|
||||||
|
return isUpdateAvailable;
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
this.latestVersion = null;
|
||||||
|
isUpdateAvailable = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLatestVersion() {
|
||||||
|
return latestVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrentVersion() {
|
||||||
|
return currentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if there is an update available, false otherwise
|
||||||
|
* Must be called after {@link Updater#isUpdateAvailable()}
|
||||||
|
*
|
||||||
|
* @return A boolean indicating whether there is an update available
|
||||||
|
*/
|
||||||
|
public static boolean hasUpdate() {
|
||||||
|
return isUpdateAvailable;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user