Skip to content

Commit

Permalink
[1.4.2]更改检测更新实现方式
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Nov 12, 2023
1 parent 617b5ef commit 18685e9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@
Craftorithm是一个基于BukkitAPI编写的配方管理插件,可以添加原版的各类配方,并可以进行合成限制,删除配方等管理操作

## 使用方式
#### [Craftorithm Wiki](https://yufiriamazenta.gitbook.io/craftorithm-wiki/)

## ParettiaLib
#### [下载链接](https://github.com/YufiriaMazenta/ParettiaLib/actions)
#### [Craftorithm Wiki](https://yufiriamazenta.gitbook.io/craftorithm-wiki/)
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
}

group = "com.github.yufiriamazenta"
version = "1.4.2-dev2"
version = "1.4.2"
var pluginVersion: String = version.toString() + "-" + SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis())
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.github.yufiriamazenta.craftorithm.util;

import com.github.yufiriamazenta.craftorithm.Craftorithm;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import crypticlib.CrypticLib;
import crypticlib.util.JsonUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

Expand All @@ -20,22 +23,25 @@ public static void checkUpdate(CommandSender sender) {
try {
URL url = new URL("https://api.github.com/repos/YufiriaMazenta/Craftorithm/releases/latest");
URLConnection conn = url.openConnection();
String newVersion;
String releaseInfo;
conn.setConnectTimeout(15000);
conn.setReadTimeout(60000);
InputStream is = conn.getInputStream();
newVersion = new BufferedReader(new InputStreamReader(is)).readLine();
releaseInfo = new BufferedReader(new InputStreamReader(is)).readLine();
is.close();

int index = newVersion.indexOf("\"tag_name\"");
int index2 = newVersion.indexOf("\"target_commitish\"");
newVersion = newVersion.substring(index + 13, index2 - 2);
String ver = Craftorithm.getInstance().getDescription().getVersion();
ver = ver.substring(0, ver.indexOf("-"));
if (checkVersion(newVersion, ver)) {
String finalNewVersion = newVersion;
JsonObject jsonObject = JsonUtil.str2JsonObject(releaseInfo);
String latestVersion = jsonObject.get("tag_name").getAsString();
if (latestVersion.startsWith("v"))
latestVersion = latestVersion.substring(1);
if (latestVersion.contains("-"))
latestVersion = latestVersion.substring(0, latestVersion.indexOf("-"));
String pluginVersion = Craftorithm.getInstance().getDescription().getVersion();
pluginVersion = pluginVersion.substring(0, pluginVersion.indexOf("-"));
if (checkVersion(latestVersion, pluginVersion)) {
String finalLatestVersion = latestVersion;
Bukkit.getScheduler().callSyncMethod(Craftorithm.getInstance(), () -> {
LangUtil.sendMsg(sender, "new_version", ContainerUtil.newHashMap("<new_version>", finalNewVersion));
LangUtil.sendMsg(sender, "new_version", ContainerUtil.newHashMap("<new_version>", finalLatestVersion));
return null;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Craftorithm
version: ${version}
version: '${version}'
main: com.github.yufiriamazenta.craftorithm.Craftorithm
api-version: 1.13
load: POSTWORLD
Expand Down

0 comments on commit 18685e9

Please sign in to comment.