perf: 简化代码

This commit is contained in:
2024-03-18 17:32:31 +08:00
parent 7462b99ce4
commit 6f4e40942c
7 changed files with 25 additions and 31 deletions

View File

@@ -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"
# 用户名

View File

@@ -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"

View File

@@ -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") {

View File

@@ -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 -

View File

@@ -7,7 +7,7 @@ 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 net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -32,15 +32,12 @@ public final class UpdateCheckUtils {
}
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 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 || downloadUrl == null) {
if (baseUrl == null || gitRepo == null) {
return;
}
String gitToken = updateConfig.getString("GIT_TOKEN");
@@ -65,8 +62,12 @@ public final class UpdateCheckUtils {
if (compareVersion(lastRelease, version) <= 0) {
return;
}
sender.sendMessage(Component.text(String.format("§a插件 §l%s§a 发布了新版本 %s", pluginName, lastRelease)));
sender.sendMessage(Component.text(String.format("§b下载链接: §n%s", downloadUrl)));
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));
}
}
public static int compareVersion(@NotNull String version1, String version2) {

View File

@@ -71,7 +71,7 @@ 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)
@@ -120,6 +120,6 @@ public class HamsterCorePlugin {
CoreAPI.getInstance().getScheduledService().shutdownNow();
slf4jLogger.info("已关闭 ScheduledExecutorService 线程池");
long time = System.currentTimeMillis() - start;
slf4jLogger.info("HamsterCore 关闭完成,总计耗时 " + time + " ms");
slf4jLogger.info("仓鼠核心关闭完成,总计耗时 " + time + " ms");
}
}

View File

@@ -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
# 保持连接池可用的间隔
# 除非你的服务器数据库连接经常断开,否则不建议启用该选项
# 单位:毫秒