Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
d0508f6610 | |||
e937924317 | |||
de10bd7feb |
@@ -47,9 +47,9 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// 对于 Bukkit 插件
|
// 对于 Bukkit 插件
|
||||||
compileOnly("cn.hamster3.mc.plugin:ball-bukkit:1.8.0")
|
compileOnly("cn.hamster3.mc.plugin:ball-bukkit:1.8.1")
|
||||||
// 对于 BungeeCord 插件
|
// 对于 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>
|
<dependency>
|
||||||
<groupId>cn.hamster3.mc.plugin</groupId>
|
<groupId>cn.hamster3.mc.plugin</groupId>
|
||||||
<artifactId>ball-bukkit</artifactId>
|
<artifactId>ball-bukkit</artifactId>
|
||||||
<version>1.8.0</version>
|
<version>1.8.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--对于 BungeeCord 插件-->
|
<!--对于 BungeeCord 插件-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hamster3.mc.plugin</groupId>
|
<groupId>cn.hamster3.mc.plugin</groupId>
|
||||||
<artifactId>ball-bungee</artifactId>
|
<artifactId>ball-bungee</artifactId>
|
||||||
<version>1.8.0</version>
|
<version>1.8.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -42,6 +42,11 @@ server-info:
|
|||||||
# 不填则自动获取 server.properties 文件中的设置
|
# 不填则自动获取 server.properties 文件中的设置
|
||||||
# port: 25577
|
# port: 25577
|
||||||
|
|
||||||
|
# Redis 配置
|
||||||
|
# 如果注释该选项则默认使用 HamsterCore 中的连接配置
|
||||||
|
# 否则 HamsterBall 将会使用与 HamsterCore 不同的 Redis 链接
|
||||||
|
# redis-url: redis://localhost:6379/0?clientName=HamsterBall&timeout=5s
|
||||||
|
|
||||||
# 数据库连接池配置
|
# 数据库连接池配置
|
||||||
# 如果注释该选项则默认使用 HamsterCore 中的连接池配置
|
# 如果注释该选项则默认使用 HamsterCore 中的连接池配置
|
||||||
# 否则 HamsterBall 将会使用与 HamsterCore 不同的数据库链接
|
# 否则 HamsterBall 将会使用与 HamsterCore 不同的数据库链接
|
||||||
@@ -53,9 +58,6 @@ server-info:
|
|||||||
# # MySQL数据库链接填写格式:
|
# # MySQL数据库链接填写格式:
|
||||||
# # jdbc:mysql://{数据库地址}:{数据库端口}/{使用的库名}?参数
|
# # jdbc:mysql://{数据库地址}:{数据库端口}/{使用的库名}?参数
|
||||||
# url: "jdbc:mysql://localhost:3306/Test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true"
|
# 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"
|
# username: "root"
|
||||||
# # 密码
|
# # 密码
|
||||||
|
@@ -33,6 +33,11 @@ server-info:
|
|||||||
# 不填则自动设置为 25577
|
# 不填则自动设置为 25577
|
||||||
port: 25577
|
port: 25577
|
||||||
|
|
||||||
|
# Redis 配置
|
||||||
|
# 如果注释该选项则默认使用 HamsterCore 中的连接配置
|
||||||
|
# 否则 HamsterBall 将会使用与 HamsterCore 不同的 Redis 链接
|
||||||
|
# redis-url: redis://localhost:6379/0?clientName=HamsterBall&timeout=5s
|
||||||
|
|
||||||
# 数据库连接池配置
|
# 数据库连接池配置
|
||||||
# 如果注释该选项则默认使用 HamsterCore 中的连接池配置
|
# 如果注释该选项则默认使用 HamsterCore 中的连接池配置
|
||||||
# 否则 HamsterBall 将会使用与 HamsterCore 不同的数据库链接
|
# 否则 HamsterBall 将会使用与 HamsterCore 不同的数据库链接
|
||||||
|
@@ -20,6 +20,7 @@ import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
|||||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||||
import com.google.common.eventbus.AsyncEventBus;
|
import com.google.common.eventbus.AsyncEventBus;
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
|
import io.lettuce.core.RedisClient;
|
||||||
import io.lettuce.core.api.StatefulRedisConnection;
|
import io.lettuce.core.api.StatefulRedisConnection;
|
||||||
import io.lettuce.core.api.sync.RedisCommands;
|
import io.lettuce.core.api.sync.RedisCommands;
|
||||||
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
|
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
|
||||||
@@ -60,6 +61,8 @@ public abstract class BallAPI {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final DataSource datasource;
|
private final DataSource datasource;
|
||||||
@NotNull
|
@NotNull
|
||||||
|
private final RedisClient redisClient;
|
||||||
|
@NotNull
|
||||||
private final BallServerInfo localServerInfo;
|
private final BallServerInfo localServerInfo;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -81,6 +84,11 @@ public abstract class BallAPI {
|
|||||||
throw new IllegalArgumentException("配置文件中未找到 server-info 节点");
|
throw new IllegalArgumentException("配置文件中未找到 server-info 节点");
|
||||||
}
|
}
|
||||||
localServerInfo = new BallServerInfo(serverInfoConfig, type);
|
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");
|
ConfigSection section = config.getSection("datasource");
|
||||||
if (section != null) {
|
if (section != null) {
|
||||||
getLogger().info("启用仓鼠球自定义数据库连接池");
|
getLogger().info("启用仓鼠球自定义数据库连接池");
|
||||||
@@ -94,7 +102,7 @@ public abstract class BallAPI {
|
|||||||
eventBus.register(BallCommonListener.INSTANCE);
|
eventBus.register(BallCommonListener.INSTANCE);
|
||||||
allServerInfo = new ConcurrentHashMap<>();
|
allServerInfo = new ConcurrentHashMap<>();
|
||||||
allPlayerInfo = new ConcurrentHashMap<>();
|
allPlayerInfo = new ConcurrentHashMap<>();
|
||||||
redisPubSub = CoreAPI.getInstance().getRedisClient().connectPubSub();
|
redisPubSub = getRedisClient().connectPubSub();
|
||||||
getLogger().info("频道前缀: " + ballConfig.getChannelPrefix());
|
getLogger().info("频道前缀: " + ballConfig.getChannelPrefix());
|
||||||
getLogger().info("启用子服更新玩家状态: " + ballConfig.isGameServerUpdatePlayerInfo());
|
getLogger().info("启用子服更新玩家状态: " + ballConfig.isGameServerUpdatePlayerInfo());
|
||||||
if (ballConfig.isGameServerUpdatePlayerInfo()) {
|
if (ballConfig.isGameServerUpdatePlayerInfo()) {
|
||||||
@@ -109,7 +117,7 @@ public abstract class BallAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void enable() throws SQLException, InterruptedException {
|
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();
|
RedisCommands<String, String> redis = connect.sync();
|
||||||
String key = "HamsterBall:ServerInfo:" + localServerInfo.getId();
|
String key = "HamsterBall:ServerInfo:" + localServerInfo.getId();
|
||||||
if (redis.exists(key) > 0 && ballConfig.isSingletonServerID()) {
|
if (redis.exists(key) > 0 && ballConfig.isSingletonServerID()) {
|
||||||
@@ -196,7 +204,7 @@ public abstract class BallAPI {
|
|||||||
if (lockUpdater != null) {
|
if (lockUpdater != null) {
|
||||||
lockUpdater.cancel(true);
|
lockUpdater.cancel(true);
|
||||||
lockUpdater = null;
|
lockUpdater = null;
|
||||||
try (StatefulRedisConnection<String, String> connect = CoreAPI.getInstance().getRedisClient().connect()) {
|
try (StatefulRedisConnection<String, String> connect = getRedisClient().connect()) {
|
||||||
RedisCommands<String, String> redis = connect.sync();
|
RedisCommands<String, String> redis = connect.sync();
|
||||||
String key = "HamsterBall:ServerInfo:" + localServerInfo.getId();
|
String key = "HamsterBall:ServerInfo:" + localServerInfo.getId();
|
||||||
redis.del(key);
|
redis.del(key);
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package cn.hamster3.mc.plugin.ball.common.thread;
|
package cn.hamster3.mc.plugin.ball.common.thread;
|
||||||
|
|
||||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
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.StatefulRedisConnection;
|
||||||
import io.lettuce.core.api.sync.RedisCommands;
|
import io.lettuce.core.api.sync.RedisCommands;
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ public class LockUpdateThread implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String key = "HamsterBall:ServerInfo:" + BallAPI.getInstance().getLocalServerInfo().getId();
|
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();
|
RedisCommands<String, String> redis = connect.sync();
|
||||||
redis.expire(key, 180);
|
redis.expire(key, 180);
|
||||||
}
|
}
|
||||||
|
@@ -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.entity.BallPlayerInfo;
|
||||||
import cn.hamster3.mc.plugin.ball.common.event.BallActions;
|
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.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.command.VelocityBallCommand;
|
||||||
import cn.hamster3.mc.plugin.ball.velocity.listener.BallVelocityListener;
|
import cn.hamster3.mc.plugin.ball.velocity.listener.BallVelocityListener;
|
||||||
import cn.hamster3.mc.plugin.ball.velocity.listener.BallVelocityMainListener;
|
import cn.hamster3.mc.plugin.ball.velocity.listener.BallVelocityMainListener;
|
||||||
@@ -77,7 +77,7 @@ public class HamsterBallPlugin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
config = YamlConfig.load(configFile);
|
config = YamlConfig.load(configFile);
|
||||||
CoreVelocityAPI.init(config);
|
BallVelocityAPI.init(config);
|
||||||
slf4jLogger.info("已初始化 BallAPI");
|
slf4jLogger.info("已初始化 BallAPI");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
slf4jLogger.error("BallAPI 初始化失败", e);
|
slf4jLogger.error("BallAPI 初始化失败", e);
|
||||||
@@ -92,7 +92,7 @@ public class HamsterBallPlugin {
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
slf4jLogger.info("仓鼠球正在启动");
|
slf4jLogger.info("仓鼠球正在启动");
|
||||||
try {
|
try {
|
||||||
CoreVelocityAPI.getInstance().enable();
|
BallVelocityAPI.getInstance().enable();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
slf4jLogger.error("仓鼠球启动失败", e);
|
slf4jLogger.error("仓鼠球启动失败", e);
|
||||||
slf4jLogger.info("由于仓鼠球启动失败,服务器将立即关闭");
|
slf4jLogger.info("由于仓鼠球启动失败,服务器将立即关闭");
|
||||||
@@ -144,7 +144,7 @@ public class HamsterBallPlugin {
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
slf4jLogger.info("仓鼠球正在关闭");
|
slf4jLogger.info("仓鼠球正在关闭");
|
||||||
try {
|
try {
|
||||||
CoreVelocityAPI.getInstance().disable();
|
BallVelocityAPI.getInstance().disable();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
slf4jLogger.error("关闭仓鼠球时遇到了一个异常", e);
|
slf4jLogger.error("关闭仓鼠球时遇到了一个异常", e);
|
||||||
}
|
}
|
||||||
|
@@ -13,20 +13,20 @@ import java.sql.SQLException;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class CoreVelocityAPI extends BallAPI {
|
public final class BallVelocityAPI extends BallAPI {
|
||||||
public CoreVelocityAPI(@NotNull ConfigSection config) {
|
public BallVelocityAPI(@NotNull ConfigSection config) {
|
||||||
super(config, BallServerType.PROXY);
|
super(config, BallServerType.PROXY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CoreVelocityAPI getInstance() {
|
public static BallVelocityAPI getInstance() {
|
||||||
return (CoreVelocityAPI) instance;
|
return (BallVelocityAPI) instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(@NotNull YamlConfig config) {
|
public static void init(@NotNull YamlConfig config) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
instance = new CoreVelocityAPI(config);
|
instance = new BallVelocityAPI(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@@ -33,6 +33,11 @@ server-info:
|
|||||||
# 不填则自动设置为 25577
|
# 不填则自动设置为 25577
|
||||||
port: 25577
|
port: 25577
|
||||||
|
|
||||||
|
# Redis 配置
|
||||||
|
# 如果注释该选项则默认使用 HamsterCore 中的连接配置
|
||||||
|
# 否则 HamsterBall 将会使用与 HamsterCore 不同的 Redis 链接
|
||||||
|
# redis-url: redis://localhost:6379/0?clientName=HamsterBall&timeout=5s
|
||||||
|
|
||||||
# 数据库连接池配置
|
# 数据库连接池配置
|
||||||
# 如果注释该选项则默认使用 HamsterCore 中的连接池配置
|
# 如果注释该选项则默认使用 HamsterCore 中的连接池配置
|
||||||
# 否则 HamsterBall 将会使用与 HamsterCore 不同的数据库链接
|
# 否则 HamsterBall 将会使用与 HamsterCore 不同的数据库链接
|
||||||
|
@@ -11,7 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "cn.hamster3.mc.plugin"
|
group = "cn.hamster3.mc.plugin"
|
||||||
version = "1.8.0"
|
version = "1.8.1"
|
||||||
description = "基于 Redis 的 Minecraft 服务端通用消息中间件"
|
description = "基于 Redis 的 Minecraft 服务端通用消息中间件"
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
Reference in New Issue
Block a user