mirror of
https://github.com/carm-outsource/TimeReward.git
synced 2024-09-19 19:25:49 +00:00
[1.3.0] 添加更新检查机制
This commit is contained in:
parent
138a92799b
commit
9e35c457ae
32
README.md
32
README.md
@ -79,3 +79,35 @@
|
|||||||
### 消息配置文件 ([messages.yml](src/main/java/cc/carm/plugin/timereward/configuration/PluginMessages.java))
|
### 消息配置文件 ([messages.yml](src/main/java/cc/carm/plugin/timereward/configuration/PluginMessages.java))
|
||||||
|
|
||||||
详见代码源文件,将在首次启动时生成配置。
|
详见代码源文件,将在首次启动时生成配置。
|
||||||
|
|
||||||
|
## 支持与捐赠
|
||||||
|
|
||||||
|
若您觉得本插件做的不错,您可以捐赠支持我!
|
||||||
|
|
||||||
|
感谢您成为开源项目的支持者!
|
||||||
|
|
||||||
|
<img height=25% width=25% src="https://raw.githubusercontent.com/CarmJos/CarmJos/main/img/donate-code.jpg" alt=""/>
|
||||||
|
|
||||||
|
## 开源协议
|
||||||
|
本项目源码采用 [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 开源协议。
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>关于 GPL 协议</summary>
|
||||||
|
|
||||||
|
> GNU General Public Licence (GPL) 有可能是开源界最常用的许可模式。GPL 保证了所有开发者的权利,同时为使用者提供了足够的复制,分发,修改的权利:
|
||||||
|
>
|
||||||
|
> #### 可自由复制
|
||||||
|
> 你可以将软件复制到你的电脑,你客户的电脑,或者任何地方。复制份数没有任何限制。
|
||||||
|
> #### 可自由分发
|
||||||
|
> 在你的网站提供下载,拷贝到U盘送人,或者将源代码打印出来从窗户扔出去(环保起见,请别这样做)。
|
||||||
|
> #### 可以用来盈利
|
||||||
|
> 你可以在分发软件的时候收费,但你必须在收费前向你的客户提供该软件的 GNU GPL 许可协议,以便让他们知道,他们可以从别的渠道免费得到这份软件,以及你收费的理由。
|
||||||
|
> #### 可自由修改
|
||||||
|
> 如果你想添加或删除某个功能,没问题,如果你想在别的项目中使用部分代码,也没问题,唯一的要求是,使用了这段代码的项目也必须使用 GPL 协议。
|
||||||
|
>
|
||||||
|
> 需要注意的是,分发的时候,需要明确提供源代码和二进制文件,另外,用于某些程序的某些协议有一些问题和限制,你可以看一下 @PierreJoye 写的 Practical Guide to GPL Compliance 一文。使用 GPL 协议,你必须在源代码代码中包含相应信息,以及协议本身。
|
||||||
|
>
|
||||||
|
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
||||||
|
</details>
|
||||||
|
|
||||||
|
|
||||||
|
43
pom.xml
43
pom.xml
@ -14,13 +14,17 @@
|
|||||||
|
|
||||||
<groupId>cc.carm.plugin</groupId>
|
<groupId>cc.carm.plugin</groupId>
|
||||||
<artifactId>timereward</artifactId>
|
<artifactId>timereward</artifactId>
|
||||||
<version>1.2.1</version>
|
<version>1.3.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>TimeReward</name>
|
<name>TimeReward</name>
|
||||||
<description>区域保护插件,将不符合条件的玩家弹出区域,基于EasyPlugin实现。</description>
|
<description>区域保护插件,将不符合条件的玩家弹出区域,基于EasyPlugin实现。</description>
|
||||||
<url>https://github.com/CarmJos/TimeReward</url>
|
<url>https://github.com/CarmJos/TimeReward</url>
|
||||||
|
|
||||||
|
<issueManagement>
|
||||||
|
<system>GitHub Issues</system>
|
||||||
|
<url>https://github.com/CarmJos/TimeReward/issues</url>
|
||||||
|
</issueManagement>
|
||||||
|
|
||||||
<ciManagement>
|
<ciManagement>
|
||||||
<system>GitHub Actions</system>
|
<system>GitHub Actions</system>
|
||||||
@ -31,6 +35,14 @@
|
|||||||
<downloadUrl>https://github.com/CarmJos/TimeReward/releases</downloadUrl>
|
<downloadUrl>https://github.com/CarmJos/TimeReward/releases</downloadUrl>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>CarmJos</id>
|
||||||
|
<name>Carm Jos</name>
|
||||||
|
<email>carm@carm.cc</email>
|
||||||
|
<url>https://work.carm.cc</url>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
@ -81,10 +93,26 @@
|
|||||||
<artifactId>easyplugin-configuration</artifactId>
|
<artifactId>easyplugin-configuration</artifactId>
|
||||||
<version>${easyplugin.version}</version>
|
<version>${easyplugin.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
|
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>githubreleases4j</artifactId>
|
||||||
|
<version>1.3.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
@ -106,6 +134,7 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
@ -207,7 +236,15 @@
|
|||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>cc.carm.lib</pattern>
|
<pattern>cc.carm.lib</pattern>
|
||||||
<shadedPattern>cc.carm.plugin.timereward.lib</shadedPattern>
|
<shadedPattern>cc.carm.plugin.moeteleport.lib</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<shadedPattern>cc.carm.plugin.moeteleport.lib.bstats</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.json</pattern>
|
||||||
|
<shadedPattern>cc.carm.plugin.moeteleport.lib.json</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
<filters>
|
<filters>
|
||||||
|
@ -6,12 +6,14 @@ import cc.carm.lib.easyplugin.utils.MessageUtils;
|
|||||||
import cc.carm.plugin.timereward.command.TimeRewardCommand;
|
import cc.carm.plugin.timereward.command.TimeRewardCommand;
|
||||||
import cc.carm.plugin.timereward.configuration.PluginConfig;
|
import cc.carm.plugin.timereward.configuration.PluginConfig;
|
||||||
import cc.carm.plugin.timereward.database.DataManager;
|
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.hooker.PAPIExpansion;
|
||||||
import cc.carm.plugin.timereward.listener.UserListener;
|
import cc.carm.plugin.timereward.listener.UserListener;
|
||||||
import cc.carm.plugin.timereward.manager.ConfigManager;
|
import cc.carm.plugin.timereward.manager.ConfigManager;
|
||||||
import cc.carm.plugin.timereward.manager.RewardManager;
|
import cc.carm.plugin.timereward.manager.RewardManager;
|
||||||
import cc.carm.plugin.timereward.manager.UserManager;
|
import cc.carm.plugin.timereward.manager.UserManager;
|
||||||
import cc.carm.plugin.timereward.util.JarResourceUtils;
|
import cc.carm.plugin.timereward.util.JarResourceUtils;
|
||||||
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
public class Main extends EasyPlugin {
|
public class Main extends EasyPlugin {
|
||||||
@ -22,6 +24,8 @@ public class Main extends EasyPlugin {
|
|||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GHUpdateChecker checker;
|
||||||
|
|
||||||
protected DataManager dataManager;
|
protected DataManager dataManager;
|
||||||
protected ConfigManager configManager;
|
protected ConfigManager configManager;
|
||||||
protected UserManager userManager;
|
protected UserManager userManager;
|
||||||
@ -70,6 +74,19 @@ public class Main extends EasyPlugin {
|
|||||||
log("检测到未安装PlaceholderAPI,跳过变量注册。");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,14 @@ public class PluginConfig {
|
|||||||
"debug", Boolean.class, false
|
"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<>(
|
public static final ConfigSectionCast<HashMap<String, RewardContents>> REWARDS = new ConfigSectionCast<>(
|
||||||
"rewards", TimeRewardAPI.getRewardManager()::readRewards, new LinkedHashMap<>()
|
"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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -5,6 +5,16 @@ version: ${project.version}
|
|||||||
|
|
||||||
debug: false
|
debug: false
|
||||||
|
|
||||||
|
# 统计数据设定
|
||||||
|
# 该选项用于帮助开发者统计插件版本与使用情况,且绝不会影响性能与使用体验。
|
||||||
|
# 当然,您也可以选择在这里关闭,或在plugins/bStats下的配置文件中关闭。
|
||||||
|
metrics: true
|
||||||
|
|
||||||
|
# 检查更新设定
|
||||||
|
# 该选项用于插件判断是否要检查更新,若您不希望插件检查更新并提示您,可以选择关闭。
|
||||||
|
# 检查更新为异步操作,绝不会影响性能与使用体验。
|
||||||
|
check-update: true
|
||||||
|
|
||||||
|
|
||||||
database:
|
database:
|
||||||
# 数据库驱动路径,默认为 MySQL
|
# 数据库驱动路径,默认为 MySQL
|
||||||
|
Loading…
Reference in New Issue
Block a user