feat: 优化版本更新检测流程

This commit is contained in:
2024-03-19 16:31:38 +08:00
parent 7285f1b3e2
commit 98300804fe
9 changed files with 35 additions and 24 deletions

View File

@@ -6,6 +6,7 @@ plugins {
group = "cn.hamster3.mc.plugin" group = "cn.hamster3.mc.plugin"
version = "1.3.3-SNAPSHOT" version = "1.3.3-SNAPSHOT"
description = "叁只仓鼠的 Minecraft 插件开发通用工具包"
subprojects { subprojects {
apply { apply {
@@ -16,6 +17,7 @@ subprojects {
group = rootProject.group group = rootProject.group
version = rootProject.version version = rootProject.version
description = rootProject.description
repositories { repositories {
maven("https://maven.airgame.net/maven-public") maven("https://maven.airgame.net/maven-public")

View File

@@ -13,6 +13,7 @@ import cn.hamster3.mc.plugin.core.bukkit.page.handler.PageHandler;
import cn.hamster3.mc.plugin.core.bukkit.page.listener.PageListener; import cn.hamster3.mc.plugin.core.bukkit.page.listener.PageListener;
import cn.hamster3.mc.plugin.core.bukkit.util.MinecraftVersion; import cn.hamster3.mc.plugin.core.bukkit.util.MinecraftVersion;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI; import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
import cn.hamster3.mc.plugin.core.common.config.ConfigSection;
import cn.hamster3.mc.plugin.core.common.config.YamlConfig; import cn.hamster3.mc.plugin.core.common.config.YamlConfig;
import cn.hamster3.mc.plugin.core.common.util.UpdateCheckUtils; import cn.hamster3.mc.plugin.core.common.util.UpdateCheckUtils;
import lombok.Getter; import lombok.Getter;
@@ -118,13 +119,17 @@ public class HamsterCorePlugin extends JavaPlugin {
VaultAPI.reloadVaultHook(); VaultAPI.reloadVaultHook();
async(() -> { async(() -> {
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
try (InputStream stream = plugin.getResource("update.yml")) { try (InputStream stream = plugin.getResource("plugin.yml")) {
if (stream == null) { if (stream == null) {
continue; continue;
} }
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
YamlConfig config = YamlConfig.load(reader); YamlConfig config = YamlConfig.load(reader);
UpdateCheckUtils.checkUpdate(plugin.getName(), config); ConfigSection section = config.getSection("UPDATE_CHECKER");
if (section == null) {
continue;
}
UpdateCheckUtils.checkUpdate(plugin.getName(), section);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -4,8 +4,15 @@ version: ${version}
api-version: 1.13 api-version: 1.13
author: MiniDay author: MiniDay
description: ${description}
website: https://git.airgame.net/MiniDay/hamster-core website: https://git.airgame.net/MiniDay/hamster-core
description: 仓鼠核心:叁只仓鼠的 Minecraft 插件开发通用工具包
UPDATE_CHECKER:
VERSION: ${version}
CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-core
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/
load: STARTUP load: STARTUP

View File

@@ -1,6 +0,0 @@
version: ${version}
CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-core
GIT_TOKEN: a44a69a4d1b8601bf6091403247759cd28764d5e
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/

View File

@@ -2,6 +2,7 @@ package cn.hamster3.mc.plugin.core.bungee;
import cn.hamster3.mc.plugin.core.bungee.api.CoreBungeeAPI; import cn.hamster3.mc.plugin.core.bungee.api.CoreBungeeAPI;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI; import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
import cn.hamster3.mc.plugin.core.common.config.ConfigSection;
import cn.hamster3.mc.plugin.core.common.config.YamlConfig; import cn.hamster3.mc.plugin.core.common.config.YamlConfig;
import cn.hamster3.mc.plugin.core.common.util.UpdateCheckUtils; import cn.hamster3.mc.plugin.core.common.util.UpdateCheckUtils;
import lombok.Getter; import lombok.Getter;
@@ -66,13 +67,17 @@ public class HamsterCorePlugin extends Plugin {
CoreAPI.getInstance().getExecutorService().submit(() -> { CoreAPI.getInstance().getExecutorService().submit(() -> {
for (Plugin plugin : ProxyServer.getInstance().getPluginManager().getPlugins()) { for (Plugin plugin : ProxyServer.getInstance().getPluginManager().getPlugins()) {
try (InputStream stream = plugin.getResourceAsStream("update.yml")) { try (InputStream stream = plugin.getResourceAsStream("bungee.yml")) {
if (stream == null) { if (stream == null) {
continue; continue;
} }
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
YamlConfig config = YamlConfig.load(reader); YamlConfig config = YamlConfig.load(reader);
UpdateCheckUtils.checkUpdate(plugin.getDescription().getName(), config); ConfigSection section = config.getSection("UPDATE_CHECKER");
if (section == null) {
continue;
}
UpdateCheckUtils.checkUpdate(plugin.getDescription().getName(), section);
} }
} catch (IOException ignored) { } catch (IOException ignored) {
} }

View File

@@ -3,4 +3,12 @@ main: cn.hamster3.mc.plugin.core.bungee.HamsterCorePlugin
version: ${version} version: ${version}
author: MiniDay author: MiniDay
description: 仓鼠核心:叁只仓鼠的 Minecraft 插件开发通用工具包 description: ${description}
website: https://git.airgame.net/MiniDay/hamster-core
UPDATE_CHECKER:
VERSION: ${version}
CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-core
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/

View File

@@ -1,6 +0,0 @@
version: ${version}
CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-core
GIT_TOKEN: a44a69a4d1b8601bf6091403247759cd28764d5e
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/

View File

@@ -18,7 +18,6 @@ import lombok.Getter;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -97,10 +96,8 @@ public class HamsterCorePlugin {
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) { try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
YamlConfig config = YamlConfig.load(reader); YamlConfig config = YamlConfig.load(reader);
UpdateCheckUtils.checkUpdate(pluginName, config); UpdateCheckUtils.checkUpdate(pluginName, config);
} catch (IOException ignored) {
} }
} catch (IOException e) { } catch (Exception ignored) {
e.printStackTrace();
} }
} }
}); });

View File

@@ -1,6 +1,5 @@
version: ${version} VERSION: ${version}
CHECK_TYPE: GITEA_RELEASES CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-core GIT_REPO: MiniDay/hamster-core
GIT_TOKEN: a44a69a4d1b8601bf6091403247759cd28764d5e
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/ DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/