fix: 修复检测更新时获取版本号错误的问题
This commit is contained in:
@@ -35,7 +35,6 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@SuppressWarnings("CallToPrintStackTrace")
|
|
||||||
public class HamsterCorePlugin extends JavaPlugin {
|
public class HamsterCorePlugin extends JavaPlugin {
|
||||||
@Getter
|
@Getter
|
||||||
private static HamsterCorePlugin instance;
|
private static HamsterCorePlugin instance;
|
||||||
@@ -117,26 +116,7 @@ public class HamsterCorePlugin extends JavaPlugin {
|
|||||||
sync(() -> {
|
sync(() -> {
|
||||||
PointAPI.reloadPlayerPointAPIHook();
|
PointAPI.reloadPlayerPointAPIHook();
|
||||||
VaultAPI.reloadVaultHook();
|
VaultAPI.reloadVaultHook();
|
||||||
async(() -> {
|
async(this::checkUpdate);
|
||||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
|
||||||
try (InputStream stream = plugin.getResource("plugin.yml")) {
|
|
||||||
if (stream == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
|
||||||
YamlConfig config = YamlConfig.load(reader);
|
|
||||||
ConfigSection section = config.getSection("UPDATE_CHECKER");
|
|
||||||
if (section == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
UpdateCheckUtils.checkUpdate(plugin.getName(), section);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
||||||
}
|
}
|
||||||
@@ -165,4 +145,23 @@ public class HamsterCorePlugin extends JavaPlugin {
|
|||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms");
|
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkUpdate() {
|
||||||
|
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
|
try (InputStream stream = plugin.getResource("plugin.yml")) {
|
||||||
|
if (stream == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||||
|
YamlConfig config = YamlConfig.load(reader);
|
||||||
|
ConfigSection section = config.getSection("UPDATE_CHECKER");
|
||||||
|
if (section == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
UpdateCheckUtils.checkUpdate(plugin.getName(), section);
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -62,27 +62,9 @@ public class HamsterCorePlugin extends Plugin {
|
|||||||
logger.info("仓鼠核心正在启动");
|
logger.info("仓鼠核心正在启动");
|
||||||
audienceProvider = BungeeAudiences.create(this);
|
audienceProvider = BungeeAudiences.create(this);
|
||||||
logger.info("已创建 AudienceProvider");
|
logger.info("已创建 AudienceProvider");
|
||||||
|
CoreAPI.getInstance().getExecutorService().submit(this::checkUpdate);
|
||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
||||||
|
|
||||||
CoreAPI.getInstance().getExecutorService().submit(() -> {
|
|
||||||
for (Plugin plugin : ProxyServer.getInstance().getPluginManager().getPlugins()) {
|
|
||||||
try (InputStream stream = plugin.getResourceAsStream("bungee.yml")) {
|
|
||||||
if (stream == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
|
||||||
YamlConfig config = YamlConfig.load(reader);
|
|
||||||
ConfigSection section = config.getSection("UPDATE_CHECKER");
|
|
||||||
if (section == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
UpdateCheckUtils.checkUpdate(plugin.getDescription().getName(), section);
|
|
||||||
}
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -100,4 +82,23 @@ public class HamsterCorePlugin extends Plugin {
|
|||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms");
|
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkUpdate() {
|
||||||
|
for (Plugin plugin : ProxyServer.getInstance().getPluginManager().getPlugins()) {
|
||||||
|
try (InputStream stream = plugin.getResourceAsStream("bungee.yml")) {
|
||||||
|
if (stream == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||||
|
YamlConfig config = YamlConfig.load(reader);
|
||||||
|
ConfigSection section = config.getSection("UPDATE_CHECKER");
|
||||||
|
if (section == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
UpdateCheckUtils.checkUpdate(plugin.getDescription().getName(), section);
|
||||||
|
}
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,7 @@ public final class UpdateCheckUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void checkUpdate(@NotNull String pluginName, @NotNull ConfigSection updateConfig, @NotNull Audience sender) throws IOException {
|
public static void checkUpdate(@NotNull String pluginName, @NotNull ConfigSection updateConfig, @NotNull Audience sender) throws IOException {
|
||||||
String version = updateConfig.getString("version", "");
|
String version = updateConfig.getString("VERSION", "");
|
||||||
String checkType = updateConfig.getString("CHECK_TYPE", "");
|
String checkType = updateConfig.getString("CHECK_TYPE", "");
|
||||||
String baseUrl = updateConfig.getString("GIT_BASE_URL");
|
String baseUrl = updateConfig.getString("GIT_BASE_URL");
|
||||||
String gitRepo = updateConfig.getString("GIT_REPO");
|
String gitRepo = updateConfig.getString("GIT_REPO");
|
||||||
|
@@ -77,30 +77,9 @@ public class HamsterCorePlugin {
|
|||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
slf4jLogger.info("仓鼠核心正在启动");
|
slf4jLogger.info("仓鼠核心正在启动");
|
||||||
|
CoreAPI.getInstance().getExecutorService().submit(this::checkUpdate);
|
||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
slf4jLogger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
slf4jLogger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
||||||
CoreAPI.getInstance().getExecutorService().submit(() -> {
|
|
||||||
for (PluginContainer plugin : proxyServer.getPluginManager().getPlugins()) {
|
|
||||||
String pluginName = plugin.getDescription().getName().orElse(null);
|
|
||||||
if (pluginName == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Object pluginObject = plugin.getInstance().orElse(null);
|
|
||||||
if (pluginObject == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try (InputStream stream = pluginObject.getClass().getResourceAsStream("/update.yml")) {
|
|
||||||
if (stream == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
|
||||||
YamlConfig config = YamlConfig.load(reader);
|
|
||||||
UpdateCheckUtils.checkUpdate(pluginName, config);
|
|
||||||
}
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LAST)
|
@Subscribe(order = PostOrder.LAST)
|
||||||
@@ -119,4 +98,27 @@ public class HamsterCorePlugin {
|
|||||||
long time = System.currentTimeMillis() - start;
|
long time = System.currentTimeMillis() - start;
|
||||||
slf4jLogger.info("仓鼠核心关闭完成,总计耗时 " + time + " ms");
|
slf4jLogger.info("仓鼠核心关闭完成,总计耗时 " + time + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkUpdate() {
|
||||||
|
for (PluginContainer plugin : proxyServer.getPluginManager().getPlugins()) {
|
||||||
|
String pluginName = plugin.getDescription().getName().orElse(null);
|
||||||
|
if (pluginName == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Object pluginObject = plugin.getInstance().orElse(null);
|
||||||
|
if (pluginObject == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try (InputStream stream = pluginObject.getClass().getResourceAsStream("/update.yml")) {
|
||||||
|
if (stream == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||||
|
YamlConfig config = YamlConfig.load(reader);
|
||||||
|
UpdateCheckUtils.checkUpdate(pluginName, config);
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user