3 Commits

Author SHA1 Message Date
d0508f6610 refactor: 修复类名错误 2025-08-05 22:15:18 +08:00
e937924317 build: 更新版本号
All checks were successful
Publish Project / build (push) Successful in 2m43s
2025-07-10 20:47:03 +08:00
de10bd7feb feat: 允许单独配置 redis-url
All checks were successful
Publish Project / build (push) Successful in 4m23s
2025-07-10 20:40:36 +08:00
9 changed files with 41 additions and 22 deletions

View File

@@ -47,9 +47,9 @@ repositories {
dependencies {
// 对于 Bukkit 插件
compileOnly("cn.hamster3.mc.plugin:ball-bukkit:1.8.0")
compileOnly("cn.hamster3.mc.plugin:ball-bukkit:1.8.1")
// 对于 BungeeCord 插件
compileOnly("cn.hamster3.mc.plugin:ball-bungee:1.8.0")
compileOnly("cn.hamster3.mc.plugin:ball-bungee:1.8.1")
}
```
@@ -75,13 +75,13 @@ dependencies {
<dependency>
<groupId>cn.hamster3.mc.plugin</groupId>
<artifactId>ball-bukkit</artifactId>
<version>1.8.0</version>
<version>1.8.1</version>
</dependency>
<!--对于 BungeeCord 插件-->
<dependency>
<groupId>cn.hamster3.mc.plugin</groupId>
<artifactId>ball-bungee</artifactId>
<version>1.8.0</version>
<version>1.8.1</version>
</dependency>
</dependencies>
</project>

View File

@@ -42,6 +42,11 @@ server-info:
# 不填则自动获取 server.properties 文件中的设置
# port: 25577
# Redis 配置
# 如果注释该选项则默认使用 HamsterCore 中的连接配置
# 否则 HamsterBall 将会使用与 HamsterCore 不同的 Redis 链接
# redis-url: redis://localhost:6379/0?clientName=HamsterBall&timeout=5s
# 数据库连接池配置
# 如果注释该选项则默认使用 HamsterCore 中的连接池配置
# 否则 HamsterBall 将会使用与 HamsterCore 不同的数据库链接
@@ -53,9 +58,6 @@ server-info:
# # 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"
# # 密码

View File

@@ -33,6 +33,11 @@ server-info:
# 不填则自动设置为 25577
port: 25577
# Redis 配置
# 如果注释该选项则默认使用 HamsterCore 中的连接配置
# 否则 HamsterBall 将会使用与 HamsterCore 不同的 Redis 链接
# redis-url: redis://localhost:6379/0?clientName=HamsterBall&timeout=5s
# 数据库连接池配置
# 如果注释该选项则默认使用 HamsterCore 中的连接池配置
# 否则 HamsterBall 将会使用与 HamsterCore 不同的数据库链接

View File

@@ -20,6 +20,7 @@ import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
@@ -60,6 +61,8 @@ public abstract class BallAPI {
@NotNull
private final DataSource datasource;
@NotNull
private final RedisClient redisClient;
@NotNull
private final BallServerInfo localServerInfo;
@NotNull
@@ -81,6 +84,11 @@ public abstract class BallAPI {
throw new IllegalArgumentException("配置文件中未找到 server-info 节点");
}
localServerInfo = new BallServerInfo(serverInfoConfig, type);
if (config.hasKey("redis-url")) {
redisClient = RedisClient.create(config.getString("redis-url"));
} else {
redisClient = CoreAPI.getInstance().getRedisClient();
}
ConfigSection section = config.getSection("datasource");
if (section != null) {
getLogger().info("启用仓鼠球自定义数据库连接池");
@@ -94,7 +102,7 @@ public abstract class BallAPI {
eventBus.register(BallCommonListener.INSTANCE);
allServerInfo = new ConcurrentHashMap<>();
allPlayerInfo = new ConcurrentHashMap<>();
redisPubSub = CoreAPI.getInstance().getRedisClient().connectPubSub();
redisPubSub = getRedisClient().connectPubSub();
getLogger().info("频道前缀: " + ballConfig.getChannelPrefix());
getLogger().info("启用子服更新玩家状态: " + ballConfig.isGameServerUpdatePlayerInfo());
if (ballConfig.isGameServerUpdatePlayerInfo()) {
@@ -109,7 +117,7 @@ public abstract class BallAPI {
}
protected void enable() throws SQLException, InterruptedException {
try (StatefulRedisConnection<String, String> connect = CoreAPI.getInstance().getRedisClient().connect()) {
try (StatefulRedisConnection<String, String> connect = getRedisClient().connect()) {
RedisCommands<String, String> redis = connect.sync();
String key = "HamsterBall:ServerInfo:" + localServerInfo.getId();
if (redis.exists(key) > 0 && ballConfig.isSingletonServerID()) {
@@ -196,7 +204,7 @@ public abstract class BallAPI {
if (lockUpdater != null) {
lockUpdater.cancel(true);
lockUpdater = null;
try (StatefulRedisConnection<String, String> connect = CoreAPI.getInstance().getRedisClient().connect()) {
try (StatefulRedisConnection<String, String> connect = getRedisClient().connect()) {
RedisCommands<String, String> redis = connect.sync();
String key = "HamsterBall:ServerInfo:" + localServerInfo.getId();
redis.del(key);

View File

@@ -1,7 +1,6 @@
package cn.hamster3.mc.plugin.ball.common.thread;
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
@@ -14,7 +13,7 @@ public class LockUpdateThread implements Runnable {
@Override
public void run() {
String key = "HamsterBall:ServerInfo:" + BallAPI.getInstance().getLocalServerInfo().getId();
try (StatefulRedisConnection<String, String> connect = CoreAPI.getInstance().getRedisClient().connect()) {
try (StatefulRedisConnection<String, String> connect = BallAPI.getInstance().getRedisClient().connect()) {
RedisCommands<String, String> redis = connect.sync();
redis.expire(key, 180);
}

View File

@@ -4,7 +4,7 @@ import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
import cn.hamster3.mc.plugin.ball.common.event.BallActions;
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent;
import cn.hamster3.mc.plugin.ball.velocity.api.CoreVelocityAPI;
import cn.hamster3.mc.plugin.ball.velocity.api.BallVelocityAPI;
import cn.hamster3.mc.plugin.ball.velocity.command.VelocityBallCommand;
import cn.hamster3.mc.plugin.ball.velocity.listener.BallVelocityListener;
import cn.hamster3.mc.plugin.ball.velocity.listener.BallVelocityMainListener;
@@ -77,7 +77,7 @@ public class HamsterBallPlugin {
);
}
config = YamlConfig.load(configFile);
CoreVelocityAPI.init(config);
BallVelocityAPI.init(config);
slf4jLogger.info("已初始化 BallAPI");
} catch (Exception e) {
slf4jLogger.error("BallAPI 初始化失败", e);
@@ -92,7 +92,7 @@ public class HamsterBallPlugin {
long start = System.currentTimeMillis();
slf4jLogger.info("仓鼠球正在启动");
try {
CoreVelocityAPI.getInstance().enable();
BallVelocityAPI.getInstance().enable();
} catch (Exception e) {
slf4jLogger.error("仓鼠球启动失败", e);
slf4jLogger.info("由于仓鼠球启动失败,服务器将立即关闭");
@@ -144,7 +144,7 @@ public class HamsterBallPlugin {
long start = System.currentTimeMillis();
slf4jLogger.info("仓鼠球正在关闭");
try {
CoreVelocityAPI.getInstance().disable();
BallVelocityAPI.getInstance().disable();
} catch (Exception e) {
slf4jLogger.error("关闭仓鼠球时遇到了一个异常", e);
}

View File

@@ -13,20 +13,20 @@ import java.sql.SQLException;
import java.util.logging.Logger;
@SuppressWarnings("unused")
public final class CoreVelocityAPI extends BallAPI {
public CoreVelocityAPI(@NotNull ConfigSection config) {
public final class BallVelocityAPI extends BallAPI {
public BallVelocityAPI(@NotNull ConfigSection config) {
super(config, BallServerType.PROXY);
}
public static CoreVelocityAPI getInstance() {
return (CoreVelocityAPI) instance;
public static BallVelocityAPI getInstance() {
return (BallVelocityAPI) instance;
}
public static void init(@NotNull YamlConfig config) {
if (instance != null) {
return;
}
instance = new CoreVelocityAPI(config);
instance = new BallVelocityAPI(config);
}
@Override

View File

@@ -33,6 +33,11 @@ server-info:
# 不填则自动设置为 25577
port: 25577
# Redis 配置
# 如果注释该选项则默认使用 HamsterCore 中的连接配置
# 否则 HamsterBall 将会使用与 HamsterCore 不同的 Redis 链接
# redis-url: redis://localhost:6379/0?clientName=HamsterBall&timeout=5s
# 数据库连接池配置
# 如果注释该选项则默认使用 HamsterCore 中的连接池配置
# 否则 HamsterBall 将会使用与 HamsterCore 不同的数据库链接

View File

@@ -11,7 +11,7 @@ plugins {
}
group = "cn.hamster3.mc.plugin"
version = "1.8.0"
version = "1.8.1"
description = "基于 Redis 的 Minecraft 服务端通用消息中间件"
subprojects {