perf: 简化代码
This commit is contained in:
@@ -69,21 +69,12 @@ public abstract class BallAPI {
|
||||
@NotNull
|
||||
private final Jedis redisPub;
|
||||
|
||||
public BallAPI(@NotNull ConfigSection config) {
|
||||
Map<String, String> env = System.getenv();
|
||||
public BallAPI(@NotNull ConfigSection config, BallServerType type) {
|
||||
ConfigSection serverInfoConfig = config.getSection("server-info");
|
||||
if (serverInfoConfig == null) {
|
||||
throw new IllegalArgumentException("配置文件中未找到 server-info 节点");
|
||||
}
|
||||
serverInfo = new BallServerInfo(
|
||||
env.getOrDefault("BALL_LOCAL_SERVER_INFO_ID", serverInfoConfig.getString("id")),
|
||||
env.getOrDefault("BALL_LOCAL_SERVER_INFO_NAME", serverInfoConfig.getString("name")),
|
||||
BallServerType.GAME,
|
||||
env.getOrDefault("BALL_LOCAL_SERVER_IP", serverInfoConfig.getString("host")),
|
||||
Integer.parseInt(
|
||||
env.getOrDefault("BALL_LOCAL_SERVER_PORT", String.valueOf(serverInfoConfig.getInt("port")))
|
||||
)
|
||||
);
|
||||
serverInfo = new BallServerInfo(serverInfoConfig, type);
|
||||
ConfigSection section = config.getSection("datasource");
|
||||
if (section != null) {
|
||||
getLogger().info("启用仓鼠球自定义数据库连接池");
|
||||
@@ -686,9 +677,4 @@ public abstract class BallAPI {
|
||||
|
||||
@NotNull
|
||||
public abstract Logger getLogger();
|
||||
|
||||
@NotNull
|
||||
public DataSource getDatasource() {
|
||||
return datasource;
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,12 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.entity;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.config.ConfigSection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -40,6 +43,17 @@ public class BallServerInfo {
|
||||
*/
|
||||
private int port;
|
||||
|
||||
public BallServerInfo(@NotNull ConfigSection config, BallServerType type) {
|
||||
Map<String, String> env = System.getenv();
|
||||
id = env.getOrDefault("BALL_LOCAL_SERVER_INFO_ID", config.getString("id"));
|
||||
name = env.getOrDefault("BALL_LOCAL_SERVER_INFO_NAME", config.getString("name"));
|
||||
this.type = type;
|
||||
host = env.getOrDefault("BALL_LOCAL_SERVER_IP", config.getString("host"));
|
||||
port = Integer.parseInt(
|
||||
env.getOrDefault("BALL_LOCAL_SERVER_PORT", String.valueOf(config.getInt("port")))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
Reference in New Issue
Block a user