feat: 添加 singleton-server-id 配置

This commit is contained in:
2024-04-24 14:12:06 +08:00
parent 08a41c1209
commit 5c913fa2db
5 changed files with 19 additions and 1 deletions

View File

@@ -108,7 +108,7 @@ public abstract class BallAPI {
protected void enable() throws SQLException, InterruptedException {
try (Jedis jedis = CoreAPI.getInstance().getJedisPool().getResource()) {
String key = "HamsterBall:ServerInfo:" + localServerInfo.getId();
if (jedis.exists(key)) {
if (jedis.exists(key) && ballConfig.isSingletonServerID()) {
throw new IllegalStateException("已经有一个服务器占用了该 ID");
}
jedis.hset(key, "id", localServerInfo.getId());

View File

@@ -11,13 +11,16 @@ import java.util.List;
@AllArgsConstructor
public class BallConfig {
private boolean debug;
private boolean singletonServerID;
@NotNull
private String channelPrefix;
private boolean gameServerUpdatePlayerInfo;
@NotNull
private List<String> loadPlayerInfoFilter;
public BallConfig(@NotNull ConfigSection config) {
debug = config.getBoolean("debug", false);
singletonServerID = config.getBoolean("singleton-server-id", false);
channelPrefix = config.getString("channel-prefix", "");
channelPrefix = channelPrefix.isEmpty() ? channelPrefix : channelPrefix + ":";
gameServerUpdatePlayerInfo = config.getBoolean("game-server-update-player-info", false);