mirror of
https://github.com/carm-outsource/TimeReward.git
synced 2026-06-05 01:08:10 +08:00
[1.3.0] 添加更新检查机制
This commit is contained in:
@@ -6,12 +6,14 @@ import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||
import cc.carm.plugin.timereward.command.TimeRewardCommand;
|
||||
import cc.carm.plugin.timereward.configuration.PluginConfig;
|
||||
import cc.carm.plugin.timereward.database.DataManager;
|
||||
import cc.carm.plugin.timereward.hooker.GHUpdateChecker;
|
||||
import cc.carm.plugin.timereward.hooker.PAPIExpansion;
|
||||
import cc.carm.plugin.timereward.listener.UserListener;
|
||||
import cc.carm.plugin.timereward.manager.ConfigManager;
|
||||
import cc.carm.plugin.timereward.manager.RewardManager;
|
||||
import cc.carm.plugin.timereward.manager.UserManager;
|
||||
import cc.carm.plugin.timereward.util.JarResourceUtils;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Main extends EasyPlugin {
|
||||
@@ -22,6 +24,8 @@ public class Main extends EasyPlugin {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private GHUpdateChecker checker;
|
||||
|
||||
protected DataManager dataManager;
|
||||
protected ConfigManager configManager;
|
||||
protected UserManager userManager;
|
||||
@@ -70,6 +74,19 @@ public class Main extends EasyPlugin {
|
||||
log("检测到未安装PlaceholderAPI,跳过变量注册。");
|
||||
}
|
||||
|
||||
if (PluginConfig.METRICS.get()) {
|
||||
info("启用统计数据...");
|
||||
Metrics metrics = new Metrics(this, 14505);
|
||||
}
|
||||
|
||||
if (PluginConfig.CHECK_UPDATE.get()) {
|
||||
info("开始检查更新...");
|
||||
this.checker = new GHUpdateChecker("CarmJos", "TimeReward");
|
||||
getScheduler().runAsync(() -> this.checker.checkUpdate(Main.this.getDescription().getVersion()));
|
||||
} else {
|
||||
info("已禁用检查更新,跳过。");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,14 @@ public class PluginConfig {
|
||||
"debug", Boolean.class, false
|
||||
);
|
||||
|
||||
public static final ConfigValue<Boolean> METRICS = new ConfigValue<>(
|
||||
"metrics", Boolean.class, true
|
||||
);
|
||||
|
||||
public static final ConfigValue<Boolean> CHECK_UPDATE = new ConfigValue<>(
|
||||
"check-update", Boolean.class, true
|
||||
);
|
||||
|
||||
public static final ConfigSectionCast<HashMap<String, RewardContents>> REWARDS = new ConfigSectionCast<>(
|
||||
"rewards", TimeRewardAPI.getRewardManager()::readRewards, new LinkedHashMap<>()
|
||||
);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package cc.carm.plugin.timereward.hooker;
|
||||
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import cc.carm.plugin.timereward.Main;
|
||||
|
||||
public class GHUpdateChecker {
|
||||
|
||||
private final String owner;
|
||||
private final String repo;
|
||||
|
||||
public GHUpdateChecker(String owner, String repo) {
|
||||
this.owner = owner;
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
public void checkUpdate(String currentVersion) {
|
||||
Integer behindVersions = GithubReleases4J.getVersionBehind(owner, repo, currentVersion);
|
||||
String downloadURL = GithubReleases4J.getReleasesURL(owner, repo);
|
||||
if (behindVersions == null) {
|
||||
Main.severe("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
|
||||
Main.severe("下载地址 " + downloadURL);
|
||||
} else if (behindVersions == 0) {
|
||||
Main.info("检查完成,当前已是最新版本。");
|
||||
} else if (behindVersions > 0) {
|
||||
Main.info("发现新版本! 目前已落后 " + behindVersions + " 个版本。");
|
||||
Main.info("最新版下载地址 " + downloadURL);
|
||||
} else {
|
||||
Main.severe("检查更新失败! 当前版本未知,请您使用原生版本以避免安全问题。");
|
||||
Main.severe("最新版下载地址 " + downloadURL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user