-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [A] 添加版本更新检查。
- Loading branch information
Showing
6 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/cc/carm/plugin/ultradepository/hooker/UpdateChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cc.carm.plugin.ultradepository.hooker; | ||
|
||
import cc.carm.lib.githubreleases4j.GithubRelease; | ||
import cc.carm.lib.githubreleases4j.GithubReleases4J; | ||
import cc.carm.plugin.ultradepository.UltraDepository; | ||
|
||
import java.util.List; | ||
|
||
public class UpdateChecker { | ||
|
||
public static void checkUpdate(UltraDepository plugin) { | ||
plugin.getScheduler().runAsync(() -> { | ||
|
||
try { | ||
|
||
List<GithubRelease> releases = GithubReleases4J.listReleases("CarmJos", "UltraDepository"); | ||
if (releases.isEmpty()) throw new NullPointerException(); // 无法获取更新 | ||
|
||
String currentVersion = plugin.getDescription().getVersion(); | ||
int i = 0; | ||
|
||
for (GithubRelease release : releases) { | ||
if (release.getTagName().equalsIgnoreCase(currentVersion)) { | ||
break; | ||
} | ||
i++; | ||
} | ||
|
||
if (i > 0) { | ||
GithubRelease latestRelease = releases.get(0); | ||
plugin.log("检查更新完成,当前已落后 " + i + " 个版本,最新版本为 &6&l" + latestRelease.getTagName() + " &r。"); | ||
plugin.log("最新版本下载地址&e " + latestRelease.getHTMLUrl()); | ||
} else { | ||
plugin.log("检查更新完成,当前已是最新版本。"); | ||
} | ||
|
||
} catch (Exception exception) { | ||
plugin.error("检查更新失败,请您定期查看插件是否更新,避免安全问题。"); | ||
plugin.error("插件下载地址&e https://github.com/CarmJos/UltraDepository/releases"); | ||
} | ||
|
||
}); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import cc.carm.lib.githubreleases4j.GithubRelease; | ||
import cc.carm.lib.githubreleases4j.GithubReleases4J; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
public class ReleasesTest { | ||
|
||
@Test | ||
public void onTest() { | ||
|
||
List<GithubRelease> releases = GithubReleases4J.listReleases("CarmJos", "UltraDepository"); | ||
|
||
for (GithubRelease release : releases) { | ||
System.out.println("#" + release.getID() + " (:" + release.getTagName() + ")" + " " + release.getName()); | ||
System.out.println("- " + release.getHTMLUrl()); | ||
} | ||
|
||
} | ||
} |