1.3.3 稳定版 #3

Merged
MiniDay merged 10 commits from dev into master 2024-03-24 13:36:55 +08:00
4 changed files with 23 additions and 23 deletions
Showing only changes of commit 9bcf8a28dd - Show all commits

View File

@@ -124,7 +124,7 @@ public class HamsterCorePlugin extends JavaPlugin {
}
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
YamlConfig config = YamlConfig.load(reader);
UpdateCheckUtils.showUpdate(plugin.getName(), config, Bukkit.getConsoleSender()::sendMessage);
UpdateCheckUtils.checkUpdate(plugin.getName(), config);
}
} catch (Exception e) {
e.printStackTrace();

View File

@@ -7,7 +7,6 @@ import cn.hamster3.mc.plugin.core.common.util.UpdateCheckUtils;
import lombok.Getter;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Plugin;
import java.io.File;
@@ -73,10 +72,7 @@ public class HamsterCorePlugin extends Plugin {
}
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
YamlConfig config = YamlConfig.load(reader);
UpdateCheckUtils.showUpdate(
plugin.getDescription().getName(), config,
(s) -> ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(s))
);
UpdateCheckUtils.checkUpdate(plugin.getDescription().getName(), config);
}
} catch (IOException ignored) {
}

View File

@@ -1,10 +1,13 @@
package cn.hamster3.mc.plugin.core.common.util;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
import cn.hamster3.mc.plugin.core.common.config.ConfigSection;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -24,19 +27,23 @@ public final class UpdateCheckUtils {
private UpdateCheckUtils() {
}
public static void showUpdate(@NotNull String pluginName, @NotNull ConfigSection config, @NotNull UpdateReceiver sender) throws IOException {
String version = config.getString("version");
public static void checkUpdate(@NotNull String pluginName, @NotNull ConfigSection updateConfig) throws IOException {
checkUpdate(pluginName, updateConfig, CoreAPI.getInstance().getAudienceProvider().console());
}
public static void checkUpdate(@NotNull String pluginName, @NotNull ConfigSection updateConfig, @NotNull Audience sender) throws IOException {
String version = updateConfig.getString("version");
if (version == null) {
return;
}
String checkType = config.getString("CHECK_TYPE", "");
String baseUrl = config.getString("GIT_BASE_URL");
String gitRepo = config.getString("GIT_REPO");
String downloadUrl = config.getString("DOWNLOAD_URL");
String checkType = updateConfig.getString("CHECK_TYPE", "");
String baseUrl = updateConfig.getString("GIT_BASE_URL");
String gitRepo = updateConfig.getString("GIT_REPO");
String downloadUrl = updateConfig.getString("DOWNLOAD_URL");
if (baseUrl == null || gitRepo == null || downloadUrl == null) {
return;
}
String gitToken = config.getString("GIT_TOKEN");
String gitToken = updateConfig.getString("GIT_TOKEN");
String lastRelease = null;
switch (checkType) {
case "GITEA_RELEASES": {
@@ -58,13 +65,15 @@ public final class UpdateCheckUtils {
if (compareVersion(lastRelease, version) <= 0) {
return;
}
sender.sendMessage(String.format("§a插件 §l%s§a 发布了新版本 %s", pluginName, lastRelease));
sender.sendMessage(String.format("§b下载链接: §n%s", downloadUrl));
sender.sendMessage(Component.text(String.format("§a插件 §l%s§a 发布了新版本 %s", pluginName, lastRelease)));
sender.sendMessage(Component.text(String.format("§b下载链接: §n%s", downloadUrl)));
}
public static int compareVersion(@NotNull String version1, String version2) {
List<Integer> collect1 = Arrays.stream(version1.split("[+-]")[0].split("\\.")).map(Integer::parseInt).collect(Collectors.toList());
List<Integer> collect2 = Arrays.stream(version2.split("[+-]")[0].split("\\.")).map(Integer::parseInt).collect(Collectors.toList());
List<Integer> collect1 = Arrays.stream(version1.split("[+-]")[0].split("\\."))
.map(Integer::parseInt).collect(Collectors.toList());
List<Integer> collect2 = Arrays.stream(version2.split("[+-]")[0].split("\\."))
.map(Integer::parseInt).collect(Collectors.toList());
int max = Math.max(collect1.size(), collect2.size());
for (int i = 0; i < max; i++) {
int v1 = i < collect1.size() ? collect1.get(i) : 0;
@@ -143,8 +152,4 @@ public final class UpdateCheckUtils {
}
}
}
public interface UpdateReceiver {
void sendMessage(@NotNull String message);
}
}

View File

@@ -15,7 +15,6 @@ 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;
@@ -97,7 +96,7 @@ public class HamsterCorePlugin {
}
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
YamlConfig config = YamlConfig.load(reader);
UpdateCheckUtils.showUpdate(pluginName, config, (s) -> proxyServer.sendMessage(Component.text(s)));
UpdateCheckUtils.checkUpdate(pluginName, config);
} catch (IOException ignored) {
}
} catch (IOException e) {