Compare commits
13 Commits
1.3.2
...
865812c524
Author | SHA1 | Date | |
---|---|---|---|
865812c524 | |||
f3e4becf35 | |||
02836c9086 | |||
e2a8cc236e | |||
86bd28e134 | |||
03b0d62b19 | |||
98300804fe | |||
7285f1b3e2 | |||
6f4e40942c | |||
7462b99ce4 | |||
9bcf8a28dd | |||
e6cb7efe77 | |||
fb75b4d95f |
@@ -26,9 +26,9 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
// 对于 Bukkit 插件
|
||||
compileOnly("cn.hamster3.mc.plugin:core-bukkit:1.3.2")
|
||||
compileOnly("cn.hamster3.mc.plugin:core-bukkit:1.3.3")
|
||||
// 对于 BungeeCord 插件
|
||||
compileOnly("cn.hamster3.mc.plugin:core-bungee:1.3.2")
|
||||
compileOnly("cn.hamster3.mc.plugin:core-bungee:1.3.3")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -54,13 +54,13 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>cn.hamster3.mc.plugin</groupId>
|
||||
<artifactId>core-bukkit</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.3</version>
|
||||
</dependency>
|
||||
<!--对于 BungeeCord 插件-->
|
||||
<dependency>
|
||||
<groupId>cn.hamster3.mc.plugin</groupId>
|
||||
<artifactId>core-bungee</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@@ -5,7 +5,8 @@ plugins {
|
||||
}
|
||||
|
||||
group = "cn.hamster3.mc.plugin"
|
||||
version = "1.3.2"
|
||||
version = "1.3.3"
|
||||
description = "叁只仓鼠的 Minecraft 插件开发通用工具包"
|
||||
|
||||
subprojects {
|
||||
apply {
|
||||
@@ -16,6 +17,7 @@ subprojects {
|
||||
|
||||
group = rootProject.group
|
||||
version = rootProject.version
|
||||
description = rootProject.description
|
||||
|
||||
repositories {
|
||||
maven("https://maven.airgame.net/maven-public")
|
||||
|
@@ -1,12 +1,7 @@
|
||||
@file:Suppress("VulnerableLibrariesLocal")
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
evaluationDependsOn(":core-common")
|
||||
|
||||
val shade = configurations.create("shade")
|
||||
val shadeJava8 = configurations.create("shadeJava8")
|
||||
|
||||
dependencies {
|
||||
api(project(":core-common")) { isTransitive = false }
|
||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||
@@ -30,16 +25,15 @@ dependencies {
|
||||
}
|
||||
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
|
||||
api("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
||||
// https://mvnrepository.com/artifact/com.sun.mail/jakarta.mail
|
||||
api("com.sun.mail:jakarta.mail:2.0.1")
|
||||
|
||||
// https://www.spigotmc.org/resources/nbt-api.7939/
|
||||
implementation("de.tr7zw:item-nbt-api:2.12.2")
|
||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||
implementation("com.zaxxer:HikariCP:4.0.3") { exclude(group = "org.slf4j") }
|
||||
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
|
||||
shade("org.jetbrains.kotlin:kotlin-stdlib:1.9.23") { exclude(group = "org.jetbrains") }
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8
|
||||
shadeJava8("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23") { exclude(group = "org.jetbrains") }
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23") { exclude(group = "org.jetbrains") }
|
||||
}
|
||||
|
||||
tasks {
|
||||
@@ -52,23 +46,8 @@ tasks {
|
||||
archiveBaseName = "HamsterCore-Bukkit"
|
||||
}
|
||||
shadowJar {
|
||||
from(shade.map { if (it.isDirectory) it else zipTree(it) })
|
||||
destinationDirectory = rootProject.layout.buildDirectory
|
||||
relocate("de.tr7zw.changeme.nbtapi", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi")
|
||||
relocate("de.tr7zw.annotations", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi.annotations")
|
||||
}
|
||||
val shadowJava8 = register<ShadowJar>("shadowJava8") {
|
||||
dependsOn(":core-common:build")
|
||||
archiveClassifier = "Java8"
|
||||
from(project.configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
|
||||
from(processResources.get().outputs)
|
||||
from(jar.get().outputs)
|
||||
from(shadeJava8.map { if (it.isDirectory) it else zipTree(it) })
|
||||
destinationDirectory = rootProject.layout.buildDirectory
|
||||
relocate("de.tr7zw.changeme.nbtapi", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi")
|
||||
relocate("de.tr7zw.annotations", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi.annotations")
|
||||
}
|
||||
build {
|
||||
dependsOn(shadowJava8)
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import cn.hamster3.mc.plugin.core.bukkit.page.handler.PageHandler;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.page.listener.PageListener;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.util.MinecraftVersion;
|
||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||
import cn.hamster3.mc.plugin.core.common.config.ConfigSection;
|
||||
import cn.hamster3.mc.plugin.core.common.config.YamlConfig;
|
||||
import cn.hamster3.mc.plugin.core.common.util.UpdateCheckUtils;
|
||||
import lombok.Getter;
|
||||
@@ -27,7 +28,6 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -35,7 +35,6 @@ import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public class HamsterCorePlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private static HamsterCorePlugin instance;
|
||||
@@ -117,21 +116,7 @@ public class HamsterCorePlugin extends JavaPlugin {
|
||||
sync(() -> {
|
||||
PointAPI.reloadPlayerPointAPIHook();
|
||||
VaultAPI.reloadVaultHook();
|
||||
async(() -> {
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
try (InputStream stream = plugin.getResource("update.yml")) {
|
||||
if (stream == null) {
|
||||
continue;
|
||||
}
|
||||
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||
YamlConfig config = YamlConfig.load(reader);
|
||||
UpdateCheckUtils.showUpdate(plugin.getName(), config, Bukkit.getConsoleSender()::sendMessage);
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async(this::checkUpdate);
|
||||
});
|
||||
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
||||
}
|
||||
@@ -160,4 +145,23 @@ public class HamsterCorePlugin extends JavaPlugin {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms");
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
try (InputStream stream = plugin.getResource("plugin.yml")) {
|
||||
if (stream == null) {
|
||||
continue;
|
||||
}
|
||||
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||
YamlConfig config = YamlConfig.load(reader);
|
||||
ConfigSection section = config.getSection("UPDATE_CHECKER");
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
UpdateCheckUtils.checkUpdate(plugin.getName(), section);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,15 +9,12 @@
|
||||
redis-url: "redis://localhost:6379/0?clientName=HamsterCore&timeout=5s"
|
||||
|
||||
datasource:
|
||||
# 数据库链接驱动地址
|
||||
# 除非你知道自己在做什么,否则不建议更改该项
|
||||
# 旧版服务端(低于1.13)请使用:com.mysql.jdbc.Driver
|
||||
# 数据库链接驱动地址,旧版服务端(低于1.13)请使用:com.mysql.jdbc.Driver
|
||||
driver: "com.mysql.cj.jdbc.Driver"
|
||||
# 数据库链接填写格式:
|
||||
# MySQL数据库链接填写格式:
|
||||
# jdbc:mysql://{数据库地址}:{数据库端口}/{使用的库名}?参数
|
||||
# 除非你知道自己在做什么,否则不建议随意更改参数
|
||||
url: "jdbc:mysql://localhost:3306/Test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true"
|
||||
# 如果你不需要做多端跨服,那么请使用 sqlite 作本地数据库
|
||||
# 如果你不需要做多端跨服,那么请使用 sqlite 作本地数据库 ↓
|
||||
# driver: "org.sqlite.JDBC"
|
||||
# url: "jdbc:sqlite:./plugins/HamsterCore/database.db"
|
||||
# 用户名
|
||||
|
@@ -4,8 +4,15 @@ version: ${version}
|
||||
api-version: 1.13
|
||||
|
||||
author: MiniDay
|
||||
description: ${description}
|
||||
website: https://git.airgame.net/MiniDay/hamster-core
|
||||
description: 仓鼠核心:叁只仓鼠的 Minecraft 插件开发通用工具包
|
||||
|
||||
UPDATE_CHECKER:
|
||||
VERSION: ${version}
|
||||
CHECK_TYPE: GITEA_RELEASES
|
||||
GIT_BASE_URL: https://git.airgame.net
|
||||
GIT_REPO: MiniDay/hamster-core
|
||||
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/
|
||||
|
||||
load: STARTUP
|
||||
|
||||
|
@@ -1,6 +0,0 @@
|
||||
version: ${version}
|
||||
CHECK_TYPE: GITEA_RELEASES
|
||||
GIT_BASE_URL: https://git.airgame.net
|
||||
GIT_REPO: MiniDay/hamster-core
|
||||
GIT_TOKEN: a44a69a4d1b8601bf6091403247759cd28764d5e
|
||||
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/
|
@@ -1,12 +1,7 @@
|
||||
@file:Suppress("VulnerableLibrariesLocal")
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
evaluationDependsOn(":core-common")
|
||||
|
||||
val shade = configurations.create("shade")
|
||||
val shadeJava8 = configurations.create("shadeJava8")
|
||||
|
||||
dependencies {
|
||||
api(project(":core-common")) { isTransitive = false }
|
||||
compileOnly("net.md-5:bungeecord-api:1.20-R0.1")
|
||||
@@ -26,13 +21,12 @@ dependencies {
|
||||
}
|
||||
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
|
||||
api("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
||||
// https://mvnrepository.com/artifact/com.sun.mail/jakarta.mail
|
||||
api("com.sun.mail:jakarta.mail:2.0.1")
|
||||
|
||||
implementation("com.zaxxer:HikariCP:4.0.3") { exclude(group = "org.slf4j") }
|
||||
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
|
||||
shade("org.jetbrains.kotlin:kotlin-stdlib:1.9.23") { exclude(group = "org.jetbrains") }
|
||||
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8
|
||||
shadeJava8("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23") { exclude(group = "org.jetbrains") }
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23") { exclude(group = "org.jetbrains") }
|
||||
}
|
||||
|
||||
tasks {
|
||||
@@ -45,23 +39,6 @@ tasks {
|
||||
archiveBaseName = "HamsterCore-BungeeCord"
|
||||
}
|
||||
shadowJar {
|
||||
from(shade.map { if (it.isDirectory) it else zipTree(it) })
|
||||
destinationDirectory = rootProject.layout.buildDirectory
|
||||
}
|
||||
shadowJar {
|
||||
from(shade.map { if (it.isDirectory) it else zipTree(it) })
|
||||
destinationDirectory = rootProject.layout.buildDirectory
|
||||
}
|
||||
val shadowJava8 = register<ShadowJar>("shadowJava8") {
|
||||
dependsOn(":core-common:build")
|
||||
archiveClassifier = "Java8"
|
||||
from(project.configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
|
||||
from(processResources.get().outputs)
|
||||
from(jar.get().outputs)
|
||||
from(shadeJava8.map { if (it.isDirectory) it else zipTree(it) })
|
||||
destinationDirectory = rootProject.layout.buildDirectory
|
||||
}
|
||||
build {
|
||||
dependsOn(shadowJava8)
|
||||
}
|
||||
}
|
||||
|
@@ -2,12 +2,12 @@ package cn.hamster3.mc.plugin.core.bungee;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bungee.api.CoreBungeeAPI;
|
||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||
import cn.hamster3.mc.plugin.core.common.config.ConfigSection;
|
||||
import cn.hamster3.mc.plugin.core.common.config.YamlConfig;
|
||||
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;
|
||||
@@ -62,26 +62,9 @@ public class HamsterCorePlugin extends Plugin {
|
||||
logger.info("仓鼠核心正在启动");
|
||||
audienceProvider = BungeeAudiences.create(this);
|
||||
logger.info("已创建 AudienceProvider");
|
||||
CoreAPI.getInstance().getExecutorService().submit(this::checkUpdate);
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
||||
|
||||
CoreAPI.getInstance().getExecutorService().submit(() -> {
|
||||
for (Plugin plugin : ProxyServer.getInstance().getPluginManager().getPlugins()) {
|
||||
try (InputStream stream = plugin.getResourceAsStream("update.yml")) {
|
||||
if (stream == null) {
|
||||
continue;
|
||||
}
|
||||
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))
|
||||
);
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,4 +82,23 @@ public class HamsterCorePlugin extends Plugin {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms");
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
for (Plugin plugin : ProxyServer.getInstance().getPluginManager().getPlugins()) {
|
||||
try (InputStream stream = plugin.getResourceAsStream("bungee.yml")) {
|
||||
if (stream == null) {
|
||||
continue;
|
||||
}
|
||||
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||
YamlConfig config = YamlConfig.load(reader);
|
||||
ConfigSection section = config.getSection("UPDATE_CHECKER");
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
UpdateCheckUtils.checkUpdate(plugin.getDescription().getName(), section);
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,4 +3,12 @@ main: cn.hamster3.mc.plugin.core.bungee.HamsterCorePlugin
|
||||
version: ${version}
|
||||
|
||||
author: MiniDay
|
||||
description: 仓鼠核心:叁只仓鼠的 Minecraft 插件开发通用工具包
|
||||
description: ${description}
|
||||
website: https://git.airgame.net/MiniDay/hamster-core
|
||||
|
||||
UPDATE_CHECKER:
|
||||
VERSION: ${version}
|
||||
CHECK_TYPE: GITEA_RELEASES
|
||||
GIT_BASE_URL: https://git.airgame.net
|
||||
GIT_REPO: MiniDay/hamster-core
|
||||
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/
|
||||
|
@@ -10,11 +10,9 @@ redis-url: "redis://localhost:6379/0?clientName=HamsterCore&timeout=5s"
|
||||
|
||||
datasource:
|
||||
# 数据库链接驱动地址
|
||||
# 除非你知道自己在做什么,否则不建议更改该项
|
||||
driver: "com.mysql.cj.jdbc.Driver"
|
||||
# 数据库链接填写格式:
|
||||
# MySQL数据库链接填写格式:
|
||||
# jdbc:mysql://{数据库地址}:{数据库端口}/{使用的库名}?参数
|
||||
# 除非你知道自己在做什么,否则不建议随意更改参数
|
||||
url: "jdbc:mysql://localhost:3306/Test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true"
|
||||
# 用户名
|
||||
username: "root"
|
||||
|
@@ -1,6 +0,0 @@
|
||||
version: ${version}
|
||||
CHECK_TYPE: GITEA_RELEASES
|
||||
GIT_BASE_URL: https://git.airgame.net
|
||||
GIT_REPO: MiniDay/hamster-core
|
||||
GIT_TOKEN: a44a69a4d1b8601bf6091403247759cd28764d5e
|
||||
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/
|
@@ -12,6 +12,10 @@ dependencies {
|
||||
exclude(group = "org.jetbrains")
|
||||
exclude(group = "com.google.code.gson")
|
||||
}
|
||||
compileOnlyApi("net.kyori:adventure-text-serializer-legacy:4.13.1") {
|
||||
exclude(group = "org.jetbrains")
|
||||
exclude(group = "com.google.code.gson")
|
||||
}
|
||||
|
||||
// https://mvnrepository.com/artifact/redis.clients/jedis
|
||||
compileOnlyApi("redis.clients:jedis:5.1.2") {
|
||||
@@ -19,6 +23,8 @@ dependencies {
|
||||
exclude(group = "org.slf4j")
|
||||
}
|
||||
compileOnlyApi("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
||||
// https://mvnrepository.com/artifact/com.sun.mail/jakarta.mail
|
||||
compileOnlyApi("com.sun.mail:jakarta.mail:2.0.1")
|
||||
|
||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||
compileOnly("com.zaxxer:HikariCP:4.0.3") { isTransitive = false }
|
||||
|
@@ -29,7 +29,7 @@ public abstract class CoreAPI {
|
||||
@NotNull
|
||||
private final JedisPool jedisPool;
|
||||
/**
|
||||
* HamsterCore 公用数据库连接池
|
||||
* 公用数据库连接池
|
||||
*/
|
||||
@Getter
|
||||
@NotNull
|
||||
@@ -63,7 +63,7 @@ public abstract class CoreAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 HamsterCore 公用数据库连接池
|
||||
* 获取公用数据库连接池
|
||||
*
|
||||
* @return 公用数据库连接池
|
||||
*/
|
||||
@@ -73,7 +73,7 @@ public abstract class CoreAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 HamsterCore 公用数据库连接
|
||||
* 获取公用数据库连接
|
||||
*
|
||||
* @return 公用数据库连接
|
||||
* @throws SQLException -
|
||||
|
@@ -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.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -14,6 +17,9 @@ import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class UpdateCheckUtils {
|
||||
private static final JsonParser JSON_PARSER = new JsonParser();
|
||||
@@ -21,59 +27,66 @@ public final class UpdateCheckUtils {
|
||||
private UpdateCheckUtils() {
|
||||
}
|
||||
|
||||
public static void showUpdate(@NotNull String pluginName, @NotNull ConfigSection config, @NotNull UpdateReceiver sender) {
|
||||
String version = config.getString("version");
|
||||
if (version == null) {
|
||||
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", "");
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
String checkType = config.getString("CHECK_TYPE", "");
|
||||
try {
|
||||
String gitToken = updateConfig.getString("GIT_TOKEN");
|
||||
String lastRelease = null;
|
||||
switch (checkType) {
|
||||
case "GITEA_RELEASES": {
|
||||
String baseUrl = config.getString("GIT_BASE_URL");
|
||||
String gitRepo = config.getString("GIT_REPO");
|
||||
String downloadUrl = config.getString("DOWNLOAD_URL");
|
||||
if (baseUrl == null || gitRepo == null || downloadUrl == null) {
|
||||
return;
|
||||
}
|
||||
String gitToken = config.getString("GIT_TOKEN");
|
||||
String lastRelease = getGiteaLastRelease(baseUrl, gitRepo, gitToken);
|
||||
if (lastRelease == null) {
|
||||
break;
|
||||
}
|
||||
if (lastRelease.compareToIgnoreCase(version) <= 0) {
|
||||
break;
|
||||
}
|
||||
sender.sendMessage(String.format("§a插件 §l%s§a 发布了新版本 %s", pluginName, lastRelease));
|
||||
sender.sendMessage(String.format("§b下载链接: §n%s", downloadUrl));
|
||||
lastRelease = getGiteaLastRelease(baseUrl, gitRepo, gitToken);
|
||||
break;
|
||||
}
|
||||
case "GITLAB_RELEASES": {
|
||||
String baseUrl = config.getString("GIT_BASE_URL");
|
||||
String gitRepo = config.getString("GIT_REPO");
|
||||
String downloadUrl = config.getString("DOWNLOAD_URL");
|
||||
if (baseUrl == null || gitRepo == null || downloadUrl == null) {
|
||||
return;
|
||||
}
|
||||
String gitToken = config.getString("GIT_TOKEN");
|
||||
int projectID = getGitlabProjectID(baseUrl, gitRepo, gitToken);
|
||||
if (projectID < 0) {
|
||||
break;
|
||||
}
|
||||
String lastRelease = getGitlabLastRelease(baseUrl, projectID, gitToken);
|
||||
lastRelease = getGitlabLastRelease(baseUrl, projectID, gitToken);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastRelease == null) {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
if (lastRelease.compareToIgnoreCase(version) <= 0) {
|
||||
break;
|
||||
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));
|
||||
break;
|
||||
sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize(
|
||||
String.format("§a插件 §l%s§a 发布了新版本 %s", pluginName, lastRelease)
|
||||
));
|
||||
if (downloadUrl != null) {
|
||||
sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize("§b下载链接: §n" + downloadUrl));
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
|
||||
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());
|
||||
int max = Math.max(collect1.size(), collect2.size());
|
||||
for (int i = 0; i < max; i++) {
|
||||
int v1 = i < collect1.size() ? collect1.get(i) : 0;
|
||||
int v2 = i < collect2.size() ? collect2.get(i) : 0;
|
||||
if (v1 > v2) {
|
||||
return 1;
|
||||
}
|
||||
if (v1 < v2) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -103,12 +116,12 @@ public final class UpdateCheckUtils {
|
||||
}
|
||||
|
||||
public static int getGitlabProjectID(@NotNull String baseUrl, @NotNull String repo, @Nullable String token) throws IOException {
|
||||
URL url = new URL("https://" + baseUrl + "/api/v4/projects?search=" + repo);
|
||||
URL url = new URL(baseUrl + "/api/v4/projects?search=" + repo);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.setRequestMethod("GET");
|
||||
if (token != null) {
|
||||
connection.setRequestProperty("PRIVATE-TOKEN", "token " + token);
|
||||
connection.setRequestProperty("PRIVATE-TOKEN", token);
|
||||
}
|
||||
connection.connect();
|
||||
try (InputStream stream = connection.getInputStream()) {
|
||||
@@ -130,7 +143,7 @@ public final class UpdateCheckUtils {
|
||||
connection.setDoInput(true);
|
||||
connection.setRequestMethod("GET");
|
||||
if (token != null) {
|
||||
connection.setRequestProperty("Authorization", "token " + token);
|
||||
connection.setRequestProperty("PRIVATE-TOKEN", token);
|
||||
}
|
||||
connection.connect();
|
||||
try (InputStream stream = connection.getInputStream()) {
|
||||
@@ -140,8 +153,4 @@ public final class UpdateCheckUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface UpdateReceiver {
|
||||
void sendMessage(@NotNull String message);
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,8 @@ dependencies {
|
||||
}
|
||||
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
|
||||
api("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
||||
// https://mvnrepository.com/artifact/com.sun.mail/jakarta.mail
|
||||
api("com.sun.mail:jakarta.mail:2.0.1")
|
||||
|
||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||
implementation("com.zaxxer:HikariCP:5.1.0") { isTransitive = false }
|
||||
|
@@ -15,11 +15,9 @@ 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;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -72,39 +70,16 @@ public class HamsterCorePlugin {
|
||||
slf4jLogger.error("初始化 CoreAPI 出错", e);
|
||||
}
|
||||
long time = System.currentTimeMillis() - start;
|
||||
slf4jLogger.info("HamsterCore 初始化完成,总计耗时 " + time + " ms");
|
||||
slf4jLogger.info("仓鼠核心初始化完成,总计耗时 " + time + " ms");
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
long start = System.currentTimeMillis();
|
||||
slf4jLogger.info("仓鼠核心正在启动");
|
||||
CoreAPI.getInstance().getExecutorService().submit(this::checkUpdate);
|
||||
long time = System.currentTimeMillis() - start;
|
||||
slf4jLogger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
||||
CoreAPI.getInstance().getExecutorService().submit(() -> {
|
||||
for (PluginContainer plugin : proxyServer.getPluginManager().getPlugins()) {
|
||||
String pluginName = plugin.getDescription().getName().orElse(null);
|
||||
if (pluginName == null) {
|
||||
continue;
|
||||
}
|
||||
Object pluginObject = plugin.getInstance().orElse(null);
|
||||
if (pluginObject == null) {
|
||||
continue;
|
||||
}
|
||||
try (InputStream stream = pluginObject.getClass().getResourceAsStream("/update.yml")) {
|
||||
if (stream == null) {
|
||||
continue;
|
||||
}
|
||||
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||
YamlConfig config = YamlConfig.load(reader);
|
||||
UpdateCheckUtils.showUpdate(pluginName, config, (s) -> proxyServer.sendMessage(Component.text(s)));
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
@@ -121,6 +96,29 @@ public class HamsterCorePlugin {
|
||||
CoreAPI.getInstance().getScheduledService().shutdownNow();
|
||||
slf4jLogger.info("已关闭 ScheduledExecutorService 线程池");
|
||||
long time = System.currentTimeMillis() - start;
|
||||
slf4jLogger.info("HamsterCore 关闭完成,总计耗时 " + time + " ms");
|
||||
slf4jLogger.info("仓鼠核心关闭完成,总计耗时 " + time + " ms");
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
for (PluginContainer plugin : proxyServer.getPluginManager().getPlugins()) {
|
||||
String pluginName = plugin.getDescription().getName().orElse(null);
|
||||
if (pluginName == null) {
|
||||
continue;
|
||||
}
|
||||
Object pluginObject = plugin.getInstance().orElse(null);
|
||||
if (pluginObject == null) {
|
||||
continue;
|
||||
}
|
||||
try (InputStream stream = pluginObject.getClass().getResourceAsStream("/update.yml")) {
|
||||
if (stream == null) {
|
||||
continue;
|
||||
}
|
||||
try (InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
|
||||
YamlConfig config = YamlConfig.load(reader);
|
||||
UpdateCheckUtils.checkUpdate(pluginName, config);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,9 +7,9 @@ import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||
import cn.hamster3.mc.plugin.core.common.impl.ComponentTypeAdapter;
|
||||
import cn.hamster3.mc.plugin.core.common.impl.MessageTypeAdapter;
|
||||
import cn.hamster3.mc.plugin.core.velocity.HamsterCorePlugin;
|
||||
import cn.hamster3.mc.plugin.core.velocity.impl.AudienceProviderImpl;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import cn.hamster3.mc.plugin.core.velocity.impl.AudienceProviderImpl;
|
||||
import net.kyori.adventure.platform.AudienceProvider;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@@ -10,16 +10,10 @@ redis-url: "redis://localhost:6379/0?clientName=HamsterCore&timeout=5s"
|
||||
|
||||
datasource:
|
||||
# 数据库链接驱动地址
|
||||
# 除非你知道自己在做什么,否则不建议更改该项
|
||||
# 旧版服务端(低于1.13)请使用:com.mysql.jdbc.Driver
|
||||
driver: "com.mysql.cj.jdbc.Driver"
|
||||
# 数据库链接填写格式:
|
||||
# MySQL数据库链接填写格式:
|
||||
# jdbc:mysql://{数据库地址}:{数据库端口}/{使用的库名}?参数
|
||||
# 除非你知道自己在做什么,否则不建议随意更改参数
|
||||
url: "jdbc:mysql://localhost:3306/Test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true"
|
||||
# 如果你不需要做多端跨服,那么请使用 sqlite 作本地数据库
|
||||
# driver: "org.sqlite.JDBC"
|
||||
# url: "jdbc:sqlite:./plugins/HamsterCore/database.db"
|
||||
# 用户名
|
||||
username: "root"
|
||||
# 密码
|
||||
@@ -28,8 +22,8 @@ datasource:
|
||||
# 推荐值:1~3
|
||||
minimum-idle: 0
|
||||
# 最大链接数
|
||||
# 推荐值:不低于3
|
||||
maximum-pool-size: 3
|
||||
# 推荐值:不低于5
|
||||
maximum-pool-size: 5
|
||||
# 保持连接池可用的间隔
|
||||
# 除非你的服务器数据库连接经常断开,否则不建议启用该选项
|
||||
# 单位:毫秒
|
||||
|
@@ -1,6 +1,5 @@
|
||||
version: ${version}
|
||||
VERSION: ${version}
|
||||
CHECK_TYPE: GITEA_RELEASES
|
||||
GIT_BASE_URL: https://git.airgame.net
|
||||
GIT_REPO: MiniDay/hamster-core
|
||||
GIT_TOKEN: a44a69a4d1b8601bf6091403247759cd28764d5e
|
||||
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-core/
|
||||
|
Reference in New Issue
Block a user