feat: 完成 gitea 更新检测功能
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package cn.hamster3.mc.plugin.core.velocity;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||
import cn.hamster3.mc.plugin.core.common.config.YamlConfig;
|
||||
import cn.hamster3.mc.plugin.core.common.util.UpdateCheckUtils;
|
||||
import cn.hamster3.mc.plugin.core.velocity.api.CoreVelocityAPI;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
@@ -8,17 +10,22 @@ import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Objects;
|
||||
|
||||
@Plugin(
|
||||
id = "hamster-core",
|
||||
@@ -53,11 +60,11 @@ public class HamsterCorePlugin {
|
||||
}
|
||||
File configFile = new File(dataFolder, "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
Files.copy(
|
||||
Objects.requireNonNull(HamsterCorePlugin.class.getResourceAsStream("/config.yml")),
|
||||
configFile.toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING
|
||||
);
|
||||
try (InputStream stream = HamsterCorePlugin.class.getResourceAsStream("/config.yml")) {
|
||||
if (stream != null) {
|
||||
Files.copy(stream, configFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
CoreVelocityAPI.init(configFile);
|
||||
slf4jLogger.info("已初始化 CoreAPI");
|
||||
@@ -74,6 +81,30 @@ public class HamsterCorePlugin {
|
||||
slf4jLogger.info("仓鼠核心正在启动");
|
||||
long time = System.currentTimeMillis() - start;
|
||||
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.showUpdate(pluginName, config, (s) -> proxyServer.sendMessage(Component.text(s)));
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
|
@@ -1,6 +0,0 @@
|
||||
BUILD_ID: ${BUILD_ID}
|
||||
BUILD_NUMBER: ${BUILD_NUMBER}
|
||||
BUILD_DISPLAY_NAME: ${BUILD_DISPLAY_NAME}
|
||||
JOB_URL: ${JOB_URL}
|
||||
BUILD_URL: ${BUILD_URL}
|
||||
GIT_COMMIT: ${GIT_COMMIT}
|
6
core-velocity/src/main/resources/update.yml
Normal file
6
core-velocity/src/main/resources/update.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
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/
|
Reference in New Issue
Block a user