feat: 添加 lettuce API
This commit is contained in:
@@ -1,27 +1,35 @@
|
||||
@file:Suppress("GradlePackageVersionRange", "GradlePackageUpdate")
|
||||
|
||||
evaluationDependsOn(":core-common")
|
||||
|
||||
dependencies {
|
||||
implementation(project(":core-common")) { isTransitive = false }
|
||||
implementation(project(":core-common")) {
|
||||
isTransitive = false
|
||||
}
|
||||
compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT")
|
||||
|
||||
implementation("de.tr7zw:item-nbt-api:+")
|
||||
compileOnly("net.milkbowl.vault:VaultAPI:+") { isTransitive = false }
|
||||
compileOnly("org.black_ixx:playerpoints:+") { isTransitive = false }
|
||||
implementation("de.tr7zw:item-nbt-api:2.12.3-SNAPSHOT")
|
||||
compileOnly("net.milkbowl.vault:VaultAPI:1.7") {
|
||||
isTransitive = false
|
||||
}
|
||||
compileOnly("org.black_ixx:playerpoints:3.2.6") {
|
||||
isTransitive = false
|
||||
}
|
||||
|
||||
implementation("net.kyori:adventure-platform-bukkit:4+") {
|
||||
implementation("net.kyori:adventure-platform-bukkit: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 {
|
||||
|
@@ -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.CoreBukkitUtils;
|
||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -25,14 +26,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class HamsterCorePlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private static HamsterCorePlugin instance;
|
||||
|
||||
@Getter
|
||||
private BukkitAudiences audienceProvider;
|
||||
|
||||
public static HamsterCorePlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在服务器主线程上执行一个任务
|
||||
*
|
||||
@@ -105,6 +103,8 @@ public class HamsterCorePlugin extends JavaPlugin {
|
||||
logger.info("仓鼠核心正在关闭");
|
||||
CoreBukkitAPI.getInstance().getDataSource().close();
|
||||
logger.info("已关闭数据库连接池");
|
||||
CoreAPI.getInstance().getRedisClient().close();
|
||||
logger.info("已关闭 Redis 连接池");
|
||||
CoreAPI.getInstance().getExecutorService().shutdownNow();
|
||||
logger.info("已关闭线程池");
|
||||
CoreAPI.getInstance().getScheduledService().shutdownNow();
|
||||
@@ -121,8 +121,4 @@ public class HamsterCorePlugin extends JavaPlugin {
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms");
|
||||
}
|
||||
|
||||
public BukkitAudiences getAudienceProvider() {
|
||||
return audienceProvider;
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import io.lettuce.core.RedisClient;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -21,14 +22,21 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class CoreBukkitAPI extends CoreAPI {
|
||||
@NotNull
|
||||
private final Gson gson;
|
||||
@NotNull
|
||||
private final Gson humanGson;
|
||||
@NotNull
|
||||
private final RedisClient redisClient;
|
||||
@NotNull
|
||||
private final HikariDataSource datasource;
|
||||
|
||||
private CoreBukkitAPI() {
|
||||
HamsterCorePlugin plugin = HamsterCorePlugin.getInstance();
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
|
||||
redisClient = RedisClient.create(config.getString("redis-url"));
|
||||
|
||||
ConfigurationSection datasourceConfig = config.getConfigurationSection("datasource");
|
||||
if (datasourceConfig == null) {
|
||||
throw new IllegalArgumentException("配置文件中未找到 datasource 节点");
|
||||
@@ -88,6 +96,11 @@ public final class CoreBukkitAPI extends CoreAPI {
|
||||
return datasource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull RedisClient getRedisClient() {
|
||||
return redisClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Gson getGson() {
|
||||
return gson;
|
||||
|
@@ -35,3 +35,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