feat: 添加 lettuce API
This commit is contained in:
@@ -1,23 +1,30 @@
|
||||
@file:Suppress("GradlePackageVersionRange", "GradlePackageUpdate")
|
||||
@file:Suppress("VulnerableLibrariesLocal")
|
||||
|
||||
evaluationDependsOn(":core-common")
|
||||
|
||||
dependencies {
|
||||
implementation(project(":core-common")) { isTransitive = false }
|
||||
compileOnly("net.md-5:bungeecord-api:+")
|
||||
implementation(project(":core-common")) {
|
||||
isTransitive = false
|
||||
}
|
||||
compileOnly("net.md-5:bungeecord-api:1.20-R0.1")
|
||||
|
||||
implementation("net.kyori:adventure-platform-bungeecord:4+") {
|
||||
implementation("net.kyori:adventure-platform-bungeecord:4.3.2") {
|
||||
exclude(group = "org.jetbrains")
|
||||
exclude(group = "com.google.code.gson")
|
||||
}
|
||||
implementation("net.kyori:adventure-text-minimessage:4+") {
|
||||
implementation("net.kyori:adventure-text-minimessage:4.15.0") {
|
||||
exclude(module = "adventure-api")
|
||||
exclude(group = "org.jetbrains")
|
||||
}
|
||||
|
||||
implementation("com.zaxxer:HikariCP:4.0.3") {
|
||||
exclude(group = "org.slf4j")
|
||||
}
|
||||
implementation("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
||||
// https://mvnrepository.com/artifact/io.lettuce/lettuce-core
|
||||
implementation("io.lettuce:lettuce-core:6.3.1.RELEASE")
|
||||
implementation("org.quartz-scheduler:quartz:2.3.2") {
|
||||
isTransitive = false
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
@@ -2,19 +2,18 @@ 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 lombok.Getter;
|
||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class HamsterCorePlugin extends Plugin {
|
||||
@Getter
|
||||
private static HamsterCorePlugin instance;
|
||||
@Getter
|
||||
private BungeeAudiences audienceProvider;
|
||||
|
||||
public static HamsterCorePlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
long start = System.currentTimeMillis();
|
||||
@@ -45,6 +44,8 @@ public class HamsterCorePlugin extends Plugin {
|
||||
logger.info("仓鼠核心正在关闭");
|
||||
CoreBungeeAPI.getInstance().getDataSource().close();
|
||||
logger.info("已关闭数据库连接池");
|
||||
CoreAPI.getInstance().getRedisClient().close();
|
||||
logger.info("已关闭 Redis 连接池");
|
||||
CoreAPI.getInstance().getExecutorService().shutdownNow();
|
||||
logger.info("已关闭线程池");
|
||||
CoreAPI.getInstance().getScheduledService().shutdownNow();
|
||||
@@ -53,7 +54,4 @@ public class HamsterCorePlugin extends Plugin {
|
||||
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms");
|
||||
}
|
||||
|
||||
public BungeeAudiences getAudienceProvider() {
|
||||
return audienceProvider;
|
||||
}
|
||||
}
|
||||
|
@@ -10,21 +10,29 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import net.kyori.adventure.platform.AudienceProvider;
|
||||
import io.lettuce.core.RedisClient;
|
||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class CoreBungeeAPI extends CoreAPI {
|
||||
@NotNull
|
||||
private final Gson gson;
|
||||
@NotNull
|
||||
private final Gson humanGson;
|
||||
@NotNull
|
||||
private final RedisClient redisClient;
|
||||
@NotNull
|
||||
private final HikariDataSource datasource;
|
||||
|
||||
private CoreBungeeAPI() {
|
||||
HamsterCorePlugin plugin = HamsterCorePlugin.getInstance();
|
||||
|
||||
Configuration config = CoreBungeeCordUtils.getPluginConfig(plugin);
|
||||
|
||||
redisClient = RedisClient.create(config.getString("redis-url"));
|
||||
|
||||
Configuration datasourceConfig = config.getSection("datasource");
|
||||
if (datasourceConfig == null) {
|
||||
throw new IllegalArgumentException("配置文件中未找到 datasource 节点");
|
||||
@@ -71,7 +79,7 @@ public final class CoreBungeeAPI extends CoreAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull AudienceProvider getAudienceProvider() {
|
||||
public @NotNull BungeeAudiences getAudienceProvider() {
|
||||
return HamsterCorePlugin.getInstance().getAudienceProvider();
|
||||
}
|
||||
|
||||
@@ -80,6 +88,11 @@ public final class CoreBungeeAPI extends CoreAPI {
|
||||
return datasource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull RedisClient getRedisClient() {
|
||||
return redisClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Gson getGson() {
|
||||
return gson;
|
||||
|
@@ -31,3 +31,13 @@ datasource:
|
||||
# 验证连接存活的超时时间
|
||||
# 单位:毫秒
|
||||
validation-timeout: 5000
|
||||
|
||||
# redis 连接配置,连接格式如下:
|
||||
# redis://用户名:密码@主机名:端口/数据库索引?参数名=参数值&参数名=参数值
|
||||
# 若没有设置 redis 用户名,则可以省略:
|
||||
# redis://密码@localhost:6379?clientName=HamsterBall
|
||||
# 若没有设置 redis 用户名和密码,则可以省略:
|
||||
# redis://localhost:6379?clientName=HamsterBall
|
||||
# 若不设置数据库,则默认使用 0
|
||||
# 详细信息:https://github.com/lettuce-io/lettuce-core/wiki/Redis-URI-and-connection-details
|
||||
redis-url: "redis://localhost:6379?clientName=HamsterCore"
|
||||
|
Reference in New Issue
Block a user