feat: 添加redission
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
//file:noinspection GrDeprecatedAPIUsage
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
@@ -36,7 +34,7 @@ subprojects {
|
|||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
withJavadocJar()
|
// withJavadocJar()
|
||||||
withSourcesJar()
|
withSourcesJar()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,5 +96,4 @@ subprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -34,8 +34,14 @@ dependencies {
|
|||||||
exclude(group = "org.jetbrains")
|
exclude(group = "org.jetbrains")
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GradlePackageUpdate
|
val hikariVersion = property("HikariCP_version")
|
||||||
implementation("com.zaxxer:HikariCP:${property("HikariCP_version")}") {
|
implementation("com.zaxxer:HikariCP:${hikariVersion}") {
|
||||||
|
exclude(group = "org.slf4j")
|
||||||
|
}
|
||||||
|
val redissionVersion = property("redission_version")
|
||||||
|
implementation("org.redisson:redisson:${redissionVersion}") {
|
||||||
|
exclude(group = "io.netty")
|
||||||
|
exclude(group = "org.yaml")
|
||||||
exclude(group = "org.slf4j")
|
exclude(group = "org.slf4j")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,13 +8,24 @@ import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.redisson.Redisson;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import org.redisson.config.Config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class CoreBukkitAPI extends CoreAPI {
|
public final class CoreBukkitAPI extends CoreAPI {
|
||||||
private final HikariDataSource datasource;
|
private final HikariDataSource datasource;
|
||||||
|
private final RedissonClient redissonClient;
|
||||||
|
|
||||||
private CoreBukkitAPI() {
|
private CoreBukkitAPI() {
|
||||||
FileConfiguration config = HamsterCorePlugin.getInstance().getConfig();
|
HamsterCorePlugin plugin = HamsterCorePlugin.getInstance();
|
||||||
|
FileConfiguration config = plugin.getConfig();
|
||||||
|
|
||||||
ConfigurationSection datasourceConfig = config.getConfigurationSection("datasource");
|
ConfigurationSection datasourceConfig = config.getConfigurationSection("datasource");
|
||||||
if (datasourceConfig == null) {
|
if (datasourceConfig == null) {
|
||||||
@@ -36,8 +47,20 @@ public final class CoreBukkitAPI extends CoreAPI {
|
|||||||
hikariConfig.setMaxLifetime(datasourceConfig.getLong("max-lifetime", 30 * 60 * 1000));
|
hikariConfig.setMaxLifetime(datasourceConfig.getLong("max-lifetime", 30 * 60 * 1000));
|
||||||
hikariConfig.setValidationTimeout(datasourceConfig.getLong("validation-timeout", 5000));
|
hikariConfig.setValidationTimeout(datasourceConfig.getLong("validation-timeout", 5000));
|
||||||
hikariConfig.setPoolName("HamsterCore-Pool");
|
hikariConfig.setPoolName("HamsterCore-Pool");
|
||||||
|
|
||||||
datasource = new HikariDataSource(hikariConfig);
|
datasource = new HikariDataSource(hikariConfig);
|
||||||
|
|
||||||
|
File file = new File(plugin.getDataFolder(), "redission.yml");
|
||||||
|
try {
|
||||||
|
if (!file.exists()) {
|
||||||
|
Files.copy(
|
||||||
|
Objects.requireNonNull(plugin.getResource("redission.yml")),
|
||||||
|
file.toPath(), StandardCopyOption.REPLACE_EXISTING
|
||||||
|
);
|
||||||
|
}
|
||||||
|
redissonClient = Redisson.create(Config.fromYAML(file));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("redis 连接加载失败!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CoreBukkitAPI getInstance() {
|
public static CoreBukkitAPI getInstance() {
|
||||||
@@ -61,9 +84,8 @@ public final class CoreBukkitAPI extends CoreAPI {
|
|||||||
return datasource;
|
return datasource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportError(@NotNull String projectID, @NotNull Throwable exception) {
|
@Override
|
||||||
}
|
public @NotNull RedissonClient getRedissonClient() {
|
||||||
|
return redissonClient;
|
||||||
public void reportFile(@NotNull String projectID, @NotNull String filename, byte @NotNull [] bytes) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,8 +27,14 @@ dependencies {
|
|||||||
exclude(group = "org.jetbrains")
|
exclude(group = "org.jetbrains")
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GradlePackageUpdate
|
val hikariVersion = property("HikariCP_version")
|
||||||
implementation("com.zaxxer:HikariCP:${property("HikariCP_version")}") {
|
implementation("com.zaxxer:HikariCP:${hikariVersion}") {
|
||||||
|
exclude(group = "org.slf4j")
|
||||||
|
}
|
||||||
|
val redissionVersion = property("redission_version")
|
||||||
|
implementation("org.redisson:redisson:${redissionVersion}") {
|
||||||
|
exclude(group = "io.netty")
|
||||||
|
exclude(group = "org.yaml")
|
||||||
exclude(group = "org.slf4j")
|
exclude(group = "org.slf4j")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,10 +8,19 @@ import com.zaxxer.hikari.HikariDataSource;
|
|||||||
import net.kyori.adventure.platform.AudienceProvider;
|
import net.kyori.adventure.platform.AudienceProvider;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.redisson.Redisson;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import org.redisson.config.Config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class CoreBungeeAPI extends CoreAPI {
|
public final class CoreBungeeAPI extends CoreAPI {
|
||||||
private final HikariDataSource datasource;
|
private final HikariDataSource datasource;
|
||||||
|
private final RedissonClient redissonClient;
|
||||||
|
|
||||||
private CoreBungeeAPI() {
|
private CoreBungeeAPI() {
|
||||||
HamsterCorePlugin plugin = HamsterCorePlugin.getInstance();
|
HamsterCorePlugin plugin = HamsterCorePlugin.getInstance();
|
||||||
@@ -37,8 +46,21 @@ public final class CoreBungeeAPI extends CoreAPI {
|
|||||||
hikariConfig.setMaxLifetime(datasourceConfig.getLong("max-lifetime", 30 * 60 * 1000));
|
hikariConfig.setMaxLifetime(datasourceConfig.getLong("max-lifetime", 30 * 60 * 1000));
|
||||||
hikariConfig.setValidationTimeout(datasourceConfig.getLong("validation-timeout", 5000));
|
hikariConfig.setValidationTimeout(datasourceConfig.getLong("validation-timeout", 5000));
|
||||||
hikariConfig.setPoolName("HamsterCore-Pool");
|
hikariConfig.setPoolName("HamsterCore-Pool");
|
||||||
|
|
||||||
datasource = new HikariDataSource(hikariConfig);
|
datasource = new HikariDataSource(hikariConfig);
|
||||||
|
|
||||||
|
|
||||||
|
File file = new File(plugin.getDataFolder(), "redission.yml");
|
||||||
|
try {
|
||||||
|
if (!file.exists()) {
|
||||||
|
Files.copy(
|
||||||
|
plugin.getResourceAsStream("redission.yml"),
|
||||||
|
file.toPath(), StandardCopyOption.REPLACE_EXISTING
|
||||||
|
);
|
||||||
|
}
|
||||||
|
redissonClient = Redisson.create(Config.fromYAML(file));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("redis 连接加载失败!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CoreBungeeAPI getInstance() {
|
public static CoreBungeeAPI getInstance() {
|
||||||
@@ -61,4 +83,9 @@ public final class CoreBungeeAPI extends CoreAPI {
|
|||||||
public @NotNull HikariDataSource getDataSource() {
|
public @NotNull HikariDataSource getDataSource() {
|
||||||
return datasource;
|
return datasource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull RedissonClient getRedissonClient() {
|
||||||
|
return redissonClient;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ dependencies {
|
|||||||
//noinspection GradlePackageUpdate
|
//noinspection GradlePackageUpdate
|
||||||
//noinspection VulnerableLibrariesLocal
|
//noinspection VulnerableLibrariesLocal
|
||||||
compileOnly("com.google.code.gson:gson:2.8.0")
|
compileOnly("com.google.code.gson:gson:2.8.0")
|
||||||
|
|
||||||
val adventureVersion = property("adventure_version")
|
val adventureVersion = property("adventure_version")
|
||||||
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-api
|
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-api
|
||||||
implementation("net.kyori:adventure-platform-api:${adventureVersion}") {
|
implementation("net.kyori:adventure-platform-api:${adventureVersion}") {
|
||||||
@@ -24,6 +25,13 @@ dependencies {
|
|||||||
implementation("net.kyori:adventure-text-serializer-legacy:${adventureSerializerVersion}") {
|
implementation("net.kyori:adventure-text-serializer-legacy:${adventureSerializerVersion}") {
|
||||||
exclude(group = "org.jetbrains")
|
exclude(group = "org.jetbrains")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val redissionVersion = property("redission_version")
|
||||||
|
implementation("org.redisson:redisson:${redissionVersion}") {
|
||||||
|
exclude(group = "io.netty")
|
||||||
|
exclude(group = "org.yaml")
|
||||||
|
exclude(group = "org.slf4j")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
@@ -2,6 +2,7 @@ package cn.hamster3.mc.plugin.core.common.api;
|
|||||||
|
|
||||||
import net.kyori.adventure.platform.AudienceProvider;
|
import net.kyori.adventure.platform.AudienceProvider;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -25,4 +26,7 @@ public abstract class CoreAPI {
|
|||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
return getDataSource().getConnection();
|
return getDataSource().getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public abstract RedissonClient getRedissonClient();
|
||||||
}
|
}
|
||||||
|
41
core-common/src/main/resources/datasource.yml
Normal file
41
core-common/src/main/resources/datasource.yml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# 数据库链接驱动地址
|
||||||
|
# 除非你知道自己在做什么,否则不建议更改该项
|
||||||
|
# 旧版服务端(低于1.13)请使用:com.mysql.jdbc.Driver
|
||||||
|
driver: "com.mysql.cj.jdbc.Driver"
|
||||||
|
# 数据库链接填写格式:
|
||||||
|
# jdbc:mysql://{数据库地址}:{数据库端口}/{使用的库名}?参数
|
||||||
|
# 除非你知道自己在做什么,否则不建议随意更改参数
|
||||||
|
url: "jdbc:mysql://sql.hamster3.cn:3306/Test1?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true"
|
||||||
|
# 用户名
|
||||||
|
username: "Test"
|
||||||
|
# 密码
|
||||||
|
password: "Test123.."
|
||||||
|
# 最小闲置链接数
|
||||||
|
# 推荐值:0~3
|
||||||
|
minimum-idle: 0
|
||||||
|
# 最大链接数
|
||||||
|
# 推荐值:
|
||||||
|
# 子服:最大在线玩家数/10,且不低于3
|
||||||
|
# BC:最大在线玩家数/20,且不低于5
|
||||||
|
maximum-pool-size: 3
|
||||||
|
# 保持连接池可用的间隔
|
||||||
|
# 除非你的服务器数据库连接经常断开,否则不建议启用该选项
|
||||||
|
# 单位:毫秒
|
||||||
|
# 默认值为0(禁用)
|
||||||
|
keep-alive-time: 0
|
||||||
|
# 连接闲置回收时间
|
||||||
|
# 单位:毫秒
|
||||||
|
# 推荐值:600000(10分钟)
|
||||||
|
idle-timeout: 600000
|
||||||
|
# 链接最长存活时间
|
||||||
|
# 单位:毫秒
|
||||||
|
max-lifetime: 1800000
|
||||||
|
# 验证连接存活的超时时间
|
||||||
|
# 单位:毫秒
|
||||||
|
validation-timeout: 5000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 如果你不需要做多端跨服,那么请使用 sqlite 作本地数据库
|
||||||
|
# driver: "org.sqlite.JDBC"
|
||||||
|
# url: "jdbc:sqlite:./plugins/HamsterCore/database.db"
|
36
core-common/src/main/resources/redission.yml
Normal file
36
core-common/src/main/resources/redission.yml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
singleServerConfig:
|
||||||
|
address: "redis://localhost:6379"
|
||||||
|
password: "Reids123.."
|
||||||
|
username: "default"
|
||||||
|
database: 1
|
||||||
|
clientName: ""
|
||||||
|
idleConnectionTimeout: 10000
|
||||||
|
connectTimeout: 10000
|
||||||
|
timeout: 3000
|
||||||
|
retryAttempts: 3
|
||||||
|
retryInterval: 1500
|
||||||
|
subscriptionsPerConnection: 5
|
||||||
|
sslEnableEndpointIdentification: true
|
||||||
|
sslProvider: "JDK"
|
||||||
|
pingConnectionInterval: 30000
|
||||||
|
keepAlive: false
|
||||||
|
tcpNoDelay: true
|
||||||
|
subscriptionConnectionMinimumIdleSize: 1
|
||||||
|
subscriptionConnectionPoolSize: 50
|
||||||
|
connectionMinimumIdleSize: 1
|
||||||
|
connectionPoolSize: 10
|
||||||
|
dnsMonitoringInterval: 5000
|
||||||
|
threads: 4
|
||||||
|
nettyThreads: 8
|
||||||
|
referenceEnabled: true
|
||||||
|
lockWatchdogTimeout: 30000
|
||||||
|
checkLockSyncedSlaves: true
|
||||||
|
slavesSyncTimeout: 1000
|
||||||
|
reliableTopicWatchdogTimeout: 600000
|
||||||
|
keepPubSubOrder: true
|
||||||
|
useScriptCache: false
|
||||||
|
minCleanUpDelay: 5
|
||||||
|
maxCleanUpDelay: 1800
|
||||||
|
cleanUpKeysAmount: 100
|
||||||
|
useThreadClassLoader: true
|
||||||
|
lazyInitialization: false
|
@@ -2,3 +2,4 @@ org.gradle.jvmargs=-Xmx2G
|
|||||||
adventure_version=4.3.0
|
adventure_version=4.3.0
|
||||||
adventure_serializer_version=4.14.0
|
adventure_serializer_version=4.14.0
|
||||||
HikariCP_version=4.0.3
|
HikariCP_version=4.0.3
|
||||||
|
redission_version=3.23.2
|
||||||
|
Reference in New Issue
Block a user